Java – use hamcrest to compare each item in two separate lists with its own matcher
•
Java
I try to compare the two lists:
ListA (a1,a2,a3,...) ListB (b1,b2,b3,...)
I hope A1 and B1, A2 to B2, A3 to B3
But I have to use another method. I can't equals!
I wrote my own hamcrest matcher But I have to iterate over the elements using a for loop Is there a better solution?
for(int i = 0;i<expected.size();i++){ assertThat(item.get(i),equalsModel(expected.get(0))); }
Solution
How do I use iterators?
for( Iterator<String> it1 = list1.iterator(),it2 = list2.iterator(); it1.hasNext() && it2.hasNext(); ){ assertThat(it1.next(),equalsModel(it2.next())); }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码