Skip to content

Commit

Permalink
Adds an assertion method.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 239035315
  • Loading branch information
Googler authored and copybara-github committed Mar 18, 2019
1 parent 547aa48 commit 79603fa
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,25 @@ public static Event assertContainsEvent(Iterable<Event> eventCollector,
return null; // unreachable
}

/**
* If {@code eventCollector} does not contain an event which matches {@code expectedEventRegex},
* fails with an informative assertion.
*/
public static void assertContainsEventRegex(
Iterable<Event> eventCollector, String expectedEventRegex) {
for (Event event : eventCollector) {
if (event.toString().matches(expectedEventRegex)) {
return;
}
}
String eventsString = eventsToString(eventCollector);
String failureMessage = "Event matching '" + expectedEventRegex + "' not found";
if (!eventsString.isEmpty()) {
failureMessage += "; found these though: " + eventsString;
}
fail(failureMessage);
}

/**
* If the specified EventCollector contains an event which has
* 'expectedEvent' as a substring, an informative assertion fails.
Expand Down

0 comments on commit 79603fa

Please sign in to comment.