0

I have a map where i have stored expected values

private static final Map<String, List<String>> time = new HashMap<>();

Now i want to validate my expected values against Json response so i found below function in rest assured but here i need to pass each value separately in Matchers.hasitems

 .then()
    .statusCode(200)
    .body(("findAll { it }.collect { it.values.time }"),Matchers.hasItems(time.get("in").get(0),time.get("in").get(1))

Is there a way I can pass the whole map in Matchers.hasitems and it validates all the expected values in map . something like below?

  .then()
    .statusCode(200)
    .body(("findAll { it }.collect { it.values.time }"),Matchers.hasItems("how can i pass map here") 
syed naveed
  • 85
  • 2
  • 12
  • 1
    Would this help? https://stackoverflow.com/questions/2580369/using-mockito-how-do-i-match-against-the-key-value-pair-of-a-map – Atmas Mar 24 '21 at 23:58

1 Answers1

1

I converted the map to list and calling the function in matchers.hasItems have solved the issue.

private String[] expectedValues() {
        List<String> values = new ArrayList<>();
        for (Map.Entry<String, List<String>> time1 : time.entrySet()) {
            values.addAll(time1.getValue());
        }
        return values.toArray(new String[0]);
    }

calling here

.then()
    .statusCode(200)
    .body(("findAll { it }.collect { it.values.time }"),Matchers.hasItems(expectedValues());
syed naveed
  • 85
  • 2
  • 12