Skip to content
A generic solution for soft assertions in Hamrest
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
LICENSE
README.md
pom.xml

README.md

BaseMatcherCollector

UPDATE

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 describeTo and/or describeMismatch.

You can’t perform that action at this time.