void (boolean checkFinishEvent) { Iterator<BuildEvent> events = collect().iterator(); Iterator<Pair<String, Matcher<BuildEvent>>> expectedEvents = myExpectedEvents.iterator(); while (events.hasNext()) { if (!expectedEvents.hasNext()) { BuildEvent next = events.next(); if (next instanceof FinishBuildEvent && !checkFinishEvent) { continue; } if(next instanceof OutputBuildEvent && mySkipOutput) { continue; } fail("Event: " + next.getMessage() + " was not expected here"); } BuildEvent next = events.next(); if(next instanceof StartBuildEventImpl && !checkFinishEvent){ continue; } if(next instanceof OutputBuildEvent && mySkipOutput) { continue; } Pair<String, Matcher<BuildEvent>> matcher = expectedEvents.next(); assertThat(next, matcher.second); } if (expectedEvents.hasNext()) { fail("Didn't receive expected event: " + expectedEvents.next().first); } }