@Test public void shouldWaitForApplicationToStart() { // Given int timeout = 1234; task.setTimeout(timeout); // When task.exec(); // Then verify(poller).awaitAtMost(eq(timeout), eq(TimeUnit.SECONDS), any(Callable.class)); }
@Test(expected = ApplicationTerminatedException.class) public void shouldThrowExceptionWhenApplicationHasTerminated() throws Exception { // Given given(execHandle.getState()).willReturn(ABORTED); task.exec(); ArgumentCaptor<Callable> callableArgumentCaptor = ArgumentCaptor.forClass(Callable.class); verify(poller).awaitAtMost(anyInt(), any(TimeUnit.class), callableArgumentCaptor.capture()); Callable callable = callableArgumentCaptor.getValue(); // When callable.call(); // Then exception is thrown }
@Test public void shouldReturnFalseWhenApplicationIsNotReady() throws Exception { // Given task.exec(); ArgumentCaptor<Callable> callableArgumentCaptor = ArgumentCaptor.forClass(Callable.class); verify(poller).awaitAtMost(anyInt(), any(TimeUnit.class), callableArgumentCaptor.capture()); Callable<Boolean> callable = (Callable<Boolean>) callableArgumentCaptor.getValue(); // When Boolean result = callable.call(); // Then assertThat(result).isFalse(); }