More Java 8 in tests
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -90,12 +89,9 @@ public void shouldThrowAnExceptionIfTheTimerRunsOut() {
TickingClock clock = new TickingClock(200);
WebDriverWait wait = new WebDriverWait(mockDriver, clock, clock, 1, 200);
- try {
- wait.until(new FalseExpectation());
- fail();
- } catch (TimeoutException e) {
- // this is expected
- }
+ Throwable ex = catchThrowable(() -> wait.until((d) -> false));
+ assertNotNull(ex);
+ assertThat(ex, instanceOf(TimeoutException.class));
}
@SuppressWarnings("unchecked")
@@ -137,10 +133,4 @@ public void shouldSilentlyCaptureNoSuchWindowExceptions() {
Wait<WebDriver> wait = new WebDriverWait(mockDriver, clock, clock, 5, 500);
wait.until(condition);
}
-
- private static class FalseExpectation implements ExpectedCondition<Boolean> {
- public Boolean apply(WebDriver driver) {
- return false;
- }
- }
}
