@Test
public void testGetTimeInStateForCompletedTask() {

    TaskStatus checked = TaskStatus.newBuilder().withState(TaskState.Finished).withTimestamp(5000).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(),
                    TaskStatus.newBuilder().withState(TaskState.StartInitiated).withTimestamp(200).build(),
                    TaskStatus.newBuilder().withState(TaskState.Started).withTimestamp(1000).build(),
                    TaskStatus.newBuilder().withState(TaskState.KillInitiated).withTimestamp(2000).build()
            )
            .build();
    assertThat(JobFunctions.getTimeInState(task, TaskState.Accepted, clock)).contains(100L);
    assertThat(JobFunctions.getTimeInState(task, TaskState.Launched, clock)).contains(100L);
    assertThat(JobFunctions.getTimeInState(task, TaskState.StartInitiated, clock)).contains(800L);
    assertThat(JobFunctions.getTimeInState(task, TaskState.Started, clock)).contains(1000L);
    assertThat(JobFunctions.getTimeInState(task, TaskState.KillInitiated, clock)).contains(3000L);
    assertThat(JobFunctions.getTimeInState(task, TaskState.Finished, clock).get()).isGreaterThan(0);
}