In my unit test class, I am having two list. One is the expectedValue and other is returnedType.
I am doing
Collections.sort(expected);
Collections.sort(returned);
but how do I compare two list based on the type of value of one of its element? For example I have element sortOrder in both the list and it has values from 1,2 or 3 so how do i compare or say doing something like assertEqual(expected, returned) for both the list and make sure that both list has same elements and has same sortOrder meanings elements are also in proper sort format?
Note: I should not be using any external libraries for doing it.
Update
Example of my return and expected list:
excepted List = [Code: ANALYST, SortOrder: 2, Code: STREET, SortOrder: 1] and
returned List = [Code: STREET, SortOrder: 1, Code: ANALYST, SortOrder: 2]
So at very basic question here is how can I sort a list based on one of its element value, in our example according to sortOrder value so our expected should be
excepted List = [Code: STREET, SortOrder: 1, Code: ANALYST, SortOrder: 2]
Edit:
Best way is to do
because AbstractList implements equals using pairwise comparison.
If you are not sure, the Lists you are receiving inherit from AbstractList, you can always do
I leave the rest of the answer for documentary purposes (and to not hide my shameful ignorance)
Do you want to assert that the lists are in the correct order also?