TaskHelper { public static Date todayZero(Date period) { if (period == null) { period = new Date(); } Calendar cal = Calendar.getInstance(); cal.setTime(period); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }  static String join(double[] array, char separator); static String join(double[] array, char separator, int startIndex, int endIndex); static String join(int[] array, char separator); static String join(int[] array, char separator, int startIndex, int endIndex); static String join(Number[] array, char separator); static String join(Number[] array, char separator, int startIndex, int endIndex); static Date nextMonthStart(Date period); static Date thisHour(Date period); static Date todayZero(Date period); static Date tomorrowZero(Date period); static Date yesterdayZero(Date period);  }
@Test public void testTodayZero() { Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_YEAR, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 1); Date todayZero = TaskHelper.todayZero(cal.getTime()); Assert.assertEquals(cal.getTimeInMillis(), todayZero.getTime() + 1L); }
@PrepareForTest({TaskHelper.class}) @Test public void testTodayZero2() throws Exception { Date date = new Date(1562774400000L); PowerMockito.whenNew(Date.class).withAnyArguments().thenReturn(date); Assert.assertEquals(date, TaskHelper.todayZero(null)); }
@Test public void testTodayZero3() { Assert.assertEquals(new Date(1562601600000L), TaskHelper.todayZero(new Date(1562683022000L))); }