MidnightTime { public static long calc() { Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTimeInMillis(); }  static long calc(); static long calc(long time); static String log();  }
@Test public void calc() { long now = DateUtil.now(); Assert.assertTrue(now >= MidnightTime.calc()); Calendar c = Calendar.getInstance(); c.setTimeInMillis(MidnightTime.calc()); Assert.assertEquals(c.get(Calendar.HOUR_OF_DAY), 0); Assert.assertEquals(c.get(Calendar.MINUTE), 0); Assert.assertEquals(c.get(Calendar.SECOND), 0); Assert.assertEquals(c.get(Calendar.MILLISECOND), 0); }
@Test public void calc_time() { long now = DateUtil.now(); long midnight = MidnightTime.calc(now); Assert.assertTrue(now >= midnight); Calendar c = Calendar.getInstance(); c.setTimeInMillis(MidnightTime.calc(now)); Assert.assertEquals(c.get(Calendar.HOUR_OF_DAY), 0); Assert.assertEquals(c.get(Calendar.MINUTE), 0); Assert.assertEquals(c.get(Calendar.SECOND), 0); Assert.assertEquals(c.get(Calendar.MILLISECOND), 0); Assert.assertEquals(midnight, MidnightTime.calc(now)); }