Search code examples
javahamcrest

Any way to use Hamcrest matchers in production code?


I'd like to use hamcrest as sugar framework to use in if statements, not in the unit tests with asserts, but in raw production code.

Something like

if ( isNotEmpty(name) ) return //....

or

if ( isEqual(name, "John")) return //...

Just like AssertThat but without throwing errors, just returning boolean. Is it possible?


Solution

  • There's the bool project that provides the following syntax:

    if(the(name, is(equalTo("Alex")))) {
    ...
    }