This solution is unnecessary. Use the ErrorCollector and you'll have soft assertions.
A generic solution for soft assertions in Hamcrest. This class enables us to safely chain our BaseMatchers of type
? super <T>.
The collector returns the results after all matchers have been executed.
assertThat(foo, collect( hasFooBar(true)) .and(hasBar("foo")) .and(hasFoo(42))); // Output on failure: // Expected: // I wanted hasFooBar to return <true> // AND hasBar should have been "foo" // AND hasFoo should return <42> // but: // I wanted hasFooBar to return <true> BUT it returned <false> // hasBar should have been "foo" BUT instead it was "bar" // hasFoo should return <42> BUT it returned <14>
Of course you can tailor the output if you so desire. Then edit