### Question:
TimeUtils { public static Duration getDuration(@Nullable final Instant started, @Nullable final Instant finished) { if (started == null || started.toEpochMilli() == 0L) { return Duration.ZERO; } else if (finished == null || finished.toEpochMilli() == 0L) { return Duration.ofMillis(Instant.now().toEpochMilli() - started.toEpochMilli()); } else { return Duration.ofMillis(finished.toEpochMilli() - started.toEpochMilli()); } } private  TimeUtils(); static Duration getDuration(@Nullable final Instant started, @Nullable final Instant finished);  }### Answer:
@Test void canGetDuration() { final long durationMillis = 50823L; final Duration duration = Duration.ofMillis(durationMillis); final Instant started = Instant.now(); final Instant finished = started.plusMillis(durationMillis); Assertions.assertThat(TimeUtils.getDuration(null, finished)).isEqualByComparingTo(Duration.ZERO); Assertions.assertThat(TimeUtils.getDuration(Instant.EPOCH, finished)).isEqualByComparingTo(Duration.ZERO); Assertions.assertThat(TimeUtils.getDuration(started, null)).isNotNull(); Assertions.assertThat(TimeUtils.getDuration(started, Instant.EPOCH)).isNotNull(); Assertions.assertThat(TimeUtils.getDuration(started, finished)).isEqualByComparingTo(duration); }