Boston Star Boston Star - 1 year ago 117
Java Question

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:

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?

Answer Source

You could use Java Streams's allMatch

assertTrue( -> !b));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download