Time { public static long toMilliseconds(long ts) throws IllegalArgumentException { int length = (int) (Math.log10(ts) + 1); switch (length) { case 10: return ts * 1000; case 13: return ts; case 16: return ts / 1000; case 19: return ts / 1000000; default: throw new IllegalArgumentException("Timestamp is out of valid range"); } }  static long toMilliseconds(long ts);  }
@Test public void testFromSeconds() { assertEquals(1484802359000L, Time.toMilliseconds(1484802359L)); }
@Test public void testFromMilliseconds() { assertEquals(1484802359000L, Time.toMilliseconds(1484802359000L)); }
@Test public void testFromMicroseconds() { assertEquals(1484802359000L, Time.toMilliseconds(1484802359000000L)); }
@Test public void testFromNanoseconds() { assertEquals(1484802359000L, Time.toMilliseconds(1484802359000000000L)); }
@Test(expected = IllegalArgumentException.class) public void testInvalid() { assertEquals(1484802359000L, Time.toMilliseconds(1484802L)); }