I have constructed a list that contains String
s of a JSON object's body field names like this:
List<String> fieldNames = new ArrayList<String>();
Then I have used REST-assured to GET a response which is in JSON format like this:
{
"id": 11,
"name": "CoolGuy",
"age": "80",
}
My list contains id
, name
, and age
. How can I verify that JSON fields match those strings in my list, without depending on their order.
I only know how to verify that it contains one String
. Here's the whole JUnit test method I've used:
@Test
public void verifyJSONMatch() {
given()
.auth()
.basic("user", "pass")
.when()
.get(getRequestURL)
.then()
.body(containsString("id"));
}