What you probably want to use is void org.junit.Assert.assertArrayEquals(Object[] expecteds, Object[] actuals) . You just need to convert the List to an array using the toArray() method, for example:
ArrayList<Token> list1 = buildListOne(); // retrieve or build list ArrayList<Token> list2 = buildListTwo(); // retrieve or build other list with same items assertArrayEquals(list1.toArray(), list2.toArray());
Remember to import this statement.
import static org.junit.Assert.assertArrayEquals;
But these methods only work if the items in both lists are in the same order. If the order is not guaranteed, you need to sort the lists using the Collections.sort() method, but your object needs to implement the java.util.Comparable interface using a single int compareTo(T o) method.
PS: Another possible solution is to use assertEquals and transfer your list to Set, for example:
assertEquals(new HashSet<Token>(list1), new HashSet<Token>(list2));
source share