Home > Software design >  How to check if list returned by Json path contains only 1 unique value
How to check if list returned by Json path contains only 1 unique value

Time:12-27

Json response:

{
  "result": [
    {
      "object": {
        "id": "myId"
      }
    },
    {
      "object": {
        "id": "myId"
      }
    }
  ]
}

Is there any way to assert that "id" does not have any other value except "myId" using rest assured assertion with hamcrest matcher?

Other sample assertion: response.then().assertThat().body("result", hasSize(greaterThan(0)));

Currently I am doing this by creating a set from the response and asserting that it has size 1 using testNG assertion but I want to achieve the same with restAssured assertion and hamcrest matcher

CodePudding user response:

If you want to use method body, then solution is:

.body("result.object.id", everyItem(is("myId")));
  • Related