Using hamcrest to compare each item in two separate lists with its own match

I am trying to compare two lists with each other:

ListA (a1,a2,a3,...) ListB (b1,b2,b3,...) 

I want a1 to compare with b1, a2-b2, a3-b3, ....

But I have to use a different method and cannot use .equals!

I wrote my own interlocutor. But I have to use a for loop to iterate over the elements. is there a better solution?

 for(int i = 0;i<expected.size();i++){ assertThat(item.get(i),equalsModel(expected.get(0))); } 
+4
source share
1 answer

How about using iterators?

 for( Iterator<String> it1 = list1.iterator(), it2 = list2.iterator(); it1.hasNext() && it2.hasNext(); ){ assertThat(it1.next(),equalsModel(it2.next())); } 
+1
source

All Articles