I write a converter for a list and I want to test it with assertj.
List<Bar> convert(List<Foo> input)
Imagine I know how to assert that a single Foo correctly converted to a Bar.
My test is something like this
@Test
void test() {
List<Foo> input = generateInput();
List<Bar> actual = converter.convert(input);
// TODO asserThat input list correctly coverted to output list
}
How can I assert that each element of actual corresponds to the element in same index of input and assert that correctly converted?
I'm looking for some method like containsExactlyElementsOf that get a custom satisfier to assert that Foo correctly converted to Bar.
One way is using a for loop like this but I'm looking for a better option:
assertThat(actual).hasSameSize(input);
for(int i = 0; i < actual.size(); i++) {
Foo foo = input.get(i);
Bar bar = actual.get(i);
assertThatConvertedCorrectly(foo, bar);
}
One of my colleagues found a solution to this problem. There is an assertion zipSatisfy.
Here is the description of the function.
It does exactly what I was looking for.