How can I make sure that my response, let's say it is in JSON, either contains or does not contain a specific field?
when()
.get("/person/12345")
.then()
.body("surname", isPresent()) // Doesn't work...
.body("age", isNotPresent()); // ...But that's the idea.
I'm looking for a way to assert whether my JSON will contain or not the fields age and surname.
Using:
import static org.junit.Assert.assertThat;
Your could then:
assertThat(response.then().body(containsString("thingThatShouldntBeHere")), is(false));
You can use equals(null) like this:
.body("surname", equals(null))
If the field does not exists it will be null