I am using assertj library for performing assertions in my JUnit5 tests.
I want to perform multiple assertions, I was exploring few different ways and got to know about Conditions
.
final var condition1 = new Condition<String>(text -> text != null, "Input not null");
final var condition2 = new Condition<String>(text -> text.equalsIgnoreCase("abc"), "Input not matching");
assertThat(someString).satisfies(allOf(condition1, condition2));
When I execute above code, I get below output:
Expecting actual: "PQR"
to satisfy:
all of:[Input not null, Input not matching]
The output doesn’t really specify which of the 2 conditions failed.
I can use separate statements to assert each condition, but I would like to know how to get exact failure message when using allOf()
.