Search code examples
javatestingautomated-testsassertionsrest-assured

ArrayList<Boolean> Assertion Java without hamcrest


This test gives me all statuses as a Boolean value of either True or False from API:

List<Boolean> allStatus = event.getResponse().getBody().jsonPath().getList("enabled");

There is no specific idea of how many status there will be, and there is no fixed size; it could be size 20 or 1.

To check this assertion, I was running a for loop and checking each value:

assertNotNull(allStatus);
for (Boolean status : allStatus) {
    assertEquals("FAILED Disable event status ", false, status);
}

I want to know what is there a better way to handle such a scenario?


Solution

  • You could use Java Streams's allMatch

    assertNotNull(allStatus);
    assertTrue(allStatus.stream().allMatch(b -> !b));