I want to use assertEquals() on the two lists list1 and list2.
The problem is, that I don't want to compare the lists like assertEquals(list1, list2). The elements are objects that can return their ids with a function getId(), and I want to check if the lists are equal in terms of the ids (ordered!).
How can I do that? Is functional programming a good idea?
If you create the expected list with the ids of the objects in order, example
List<MyObject> expected = new ArrayList<>();
expected.add(myObject1); //with id = 1
expected.add(myObject2); //with id = 2
expected.add(myObject3); //with id = 3
assertEquals(expected, actual);
, then if the actual list has objects in different order of ids, it would fail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With