JobExecutionResult { public Long getDuration() { if (endTime == null) { return null; } return endTime.getTime() - startTime.getTime(); } JobExecutionResult(Long id, String status, Date startTime, Date endTime, String description); Long getId(); String getStatus(); Date getStartTime(); Date getEndTime(); String getDescription(); Long getDuration();  }
@Test public void givenStartAndEndTime_whenGetDuration_thenCalculateDurationAsDifference() { JobExecutionResult jobExecutionResult = new JobExecutionResult(1234567L, "COMPLETED", new Date(0), new Date(1000), "1"); assertThat(jobExecutionResult.getDuration()).isEqualTo(1000); }
@Test public void givenRunningJobExecutionWithoutEndTime_whenGetDuration_thenReturnNull() { JobExecutionResult jobExecutionResult = new JobExecutionResult(1234567L, "STARTED", new Date(0), null, "1"); assertThat(jobExecutionResult.getDuration()).isNull(); }
@Test public void givenNotStartedJobExecution_whenGetDuration_thenReturnNull() { JobExecutionResult jobExecutionResult = new JobExecutionResult(1234567L, "STARTED", null, null, "1"); assertThat(jobExecutionResult.getDuration()).isNull(); }