@Test
public void testGetTimeInStateForFailedTask() {

    TaskStatus checked = TaskStatus.newBuilder().withState(TaskState.KillInitiated).withTimestamp(1000).build();
    Task task = REFERENCE_TASK.toBuilder()
            .withStatus(checked)
            .withStatusHistory(
                    TaskStatus.newBuilder().withState(TaskState.Accepted).withTimestamp(0).build(),
                    TaskStatus.newBuilder().withState(TaskState.Launched).withTimestamp(100).build()
            )
            .build();
    assertThat(JobFunctions.getTimeInState(task, TaskState.Accepted, clock)).contains(100L);
    assertThat(JobFunctions.getTimeInState(task, TaskState.Launched, clock)).contains(900L);
    assertThat(JobFunctions.getTimeInState(task, TaskState.StartInitiated, clock)).isEmpty();
    assertThat(JobFunctions.getTimeInState(task, TaskState.Started, clock)).isEmpty();
    assertThat(JobFunctions.getTimeInState(task, TaskState.KillInitiated, clock).get()).isGreaterThan(0);
    assertThat(JobFunctions.getTimeInState(task, TaskState.Finished, clock)).isEmpty();
}