Search code examples
javahamcrestrest-assured

Assert alternative (or)


I have an endpoint which returns either true or false. Is it somehow possible to tell Hamcrest with RestAssured to check whether there exist one of mentioned two ? I've already tried containsString, hasItems etc, but none of them works i.e it checks for both of them.

get("http://localhost:8080/trueOrFalse")
        .then()
        .body(hasItems("true", "false")); // TRUE or FALSE not both 

Solution

  • There is an either() method on the CombinableMatcher class.

    Example

    assertThat(result, either(is(true)).or(is(false)));