@Test void shouldTimeoutWhenDifferentContentProvided() { // given FakeClock clock = getFakeClock(); InputStream inputStream = spy( new MockInputStream( new Ticker( clock, 1, TimeUnit.SECONDS ), lines( "different content" ), lines( "different message" ) ) ); InputStreamAwaiter awaiter = new InputStreamAwaiter( clock, inputStream ); // when assertThrows( TimeoutException.class, () -> awaiter.awaitLine( "important message", 5, TimeUnit.SECONDS ) ); }
@Test void shouldWaitForALineWithoutBlocking() throws Exception { // given FakeClock clock = getFakeClock(); InputStream inputStream = spy( new MockInputStream( new Ticker( clock, 5, TimeUnit.MILLISECONDS ), lines( "important message" ) ) ); InputStreamAwaiter awaiter = new InputStreamAwaiter( clock, inputStream ); // when awaiter.awaitLine( "important message", 5, TimeUnit.SECONDS ); }