Times { public static long elapsed(long started, long finished) { return Times.elapsed(started, finished, true); }  static long elapsed(long started, long finished); static long elapsed(long started, long finished, boolean isRunning); static String format(long ts); static String formatISO8601(long ts); static long parseISO8601ToLocalTimeInMillis(String isoString);  }
@Test public void testNegativeStartTimes() { long elapsed = Times.elapsed(-5, 10, true); Assert.assertEquals("Elapsed time is not 0", 0, elapsed); elapsed = Times.elapsed(-5, 10, false); Assert.assertEquals("Elapsed time is not -1", -1, elapsed); }
@Test public void testNegativeFinishTimes() { long elapsed = Times.elapsed(5, -10, false); Assert.assertEquals("Elapsed time is not -1", -1, elapsed); }
@Test public void testNegativeStartandFinishTimes() { long elapsed = Times.elapsed(-5, -10, false); Assert.assertEquals("Elapsed time is not -1", -1, elapsed); }
@Test public void testPositiveStartandFinishTimes() { long elapsed = Times.elapsed(5, 10, true); Assert.assertEquals("Elapsed time is not 5", 5, elapsed); elapsed = Times.elapsed(5, 10, false); Assert.assertEquals("Elapsed time is not 5", 5, elapsed); }
@Test public void testFinishTimesAheadOfStartTimes() { long elapsed = Times.elapsed(10, 5, true); Assert.assertEquals("Elapsed time is not -1", -1, elapsed); elapsed = Times.elapsed(10, 5, false); Assert.assertEquals("Elapsed time is not -1", -1, elapsed); elapsed = Times.elapsed(Long.MAX_VALUE, 0, true); Assert.assertEquals("Elapsed time is not -1", -1, elapsed); }