@Before
  public void setUp() {
    task = createTask(TestableAbstractPollingExecAsyncTask.class);

    task.setExecHandleBuilder(execHandleBuilder);
    given(execHandleBuilder.build()).willReturn(execHandle);
    given(execHandle.getState()).willReturn(STARTED);

    task.setPoller(poller);
  }
  @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
  public void shouldSetAndReturnTimeout() {
    // Given
    int timeout = 123456;

    // When
    task.setTimeout(timeout);
    int result = task.getTimeout();

    // Then
    assertThat(result).isEqualTo(timeout);
  }
  @Test
  public void shouldReturnTrueWhenApplicationIsReady() throws Exception {
    // Given
    task.ready = true;
    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).isTrue();
  }
  @Test
  public void shouldReturnDefaultTimeout() {
    // When
    int result = task.getTimeout();

    // Then
    assertThat(result).isEqualTo(300);
  }
  @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
  }