TIL #3: Comparing lists and ensuring the order

Nothing much, but today my teammate was checking my PR where I had a unit test that was checking if the expected list does not contain the element. We discussed if the unit test can be improved, for example by checking if expected list, when compared to actual list, is the same.

I thought about utilizing containsAll() but after some discussion it turned out that I should also cover the order of the items. After some time I found out that I could simply utilize equals() which does exactly that.

Great topic on SO regarding this issue, and especially the answer:

Topic: https://stackoverflow.com/questions/1075656/simple-way-to-find-if-two-different-lists-contain-exactly-the-same-elements

Answer #1: https://stackoverflow.com/a/1075699

Answer #2: https://stackoverflow.com/a/1075817

That’s all, thanks!

Mariusz Brona

Dodaj komentarz

Twój adres email nie zostanie opublikowany. Pola, których wypełnienie jest wymagane, są oznaczone symbolem *