### Question:
JobHelper { public static long calculateRuntimeDuration(long maxRuntimeSecs, Instant startedAt) { long terminateJobInSecs = maxRuntimeSecs; if (maxRuntimeSecs > 0) { Instant now = Instant.now(); if (now.isAfter(startedAt)) { long elapsedSeconds = now.getEpochSecond() - startedAt.getEpochSecond(); terminateJobInSecs = maxRuntimeSecs - elapsedSeconds; if (terminateJobInSecs <= 0) { terminateJobInSecs = 1; } } } return terminateJobInSecs; } private  JobHelper(); static List<Integer> getUserStageNumbers(SchedulingInfo schedulingInfo, boolean hasJobMaster); static boolean isTerminalWorkerEvent(WorkerEvent workerEvent); static Optional<String> getWorkerHostFromWorkerEvent(WorkerEvent event); static long calculateRuntimeDuration(long maxRuntimeSecs, Instant startedAt);  }### Answer:
@Test public void testCalculateRuntimeLimitForAlreadyStartedJob() { Instant now = Instant.now(); Instant startedAt = now.minusSeconds(5); assertEquals(5, JobHelper.calculateRuntimeDuration(10, startedAt)); }
@Test public void testCalculateRuntimeLimitForJustStartedJob() { Instant now = Instant.now(); Instant startedAt = now; assertEquals(10, JobHelper.calculateRuntimeDuration(10, startedAt)); }
@Test public void testCalculateRuntimeLimitForAlreadyExpiredJob() { Instant now = Instant.now(); Instant startedAt = now.minusSeconds(15); assertEquals(1, JobHelper.calculateRuntimeDuration(10, startedAt)); }