mardi 24 mars 2020

AssertJ check if JSONArray contains a map with an entry with given key and value

Hi I want to test in my test with assertThat if a JSONArray contains an item with a key with a specific value. For example i have the given JSONArray:

[
  {
    "eventType": "event_1",
    "name": "user_1",
    ....
  },
  {
    "eventType": "event_2",
    "name": "user_2",
    ....
  }
]

What I want to test for example is if this array contains an item with the key: eventType with the value: event_2 Is it possible to achieve this with assertThat without looping through the array and checking each item?

I know it is possible to check if a map contains a given key and value and I also know it is possible to check if an array contains an given item. But I didn't found any solution how to combine these both things. Someone has an idea how can combine these two things?

Thank you for your help

Aucun commentaire:

Enregistrer un commentaire