EmailSentCounter extends AbstractEmailSenderCallback { @VisibleForTesting protected long getStartTime() { long deltaTime = TimeUnit.MINUTES.toMillis(1); long startTimeMilli = DateTimeUtils.getNearestHour().getTime() - System.currentTimeMillis() + deltaTime; return TimeUnit.MILLISECONDS.toMinutes(startTimeMilli); }  @PostConstruct void scheduledCheckSentEmails(); @Override void success(); @Override void fail(Throwable throwable);  }
@Test public void testGetStartTime() throws Exception { long minute = instance.getStartTime(); Date date = DateTimeUtils.getMinutesLaterThan(new Date(), (int)minute); Date expected = DateTimeUtils.getNearestHour(); System.out.println(minute); System.out.println(date); System.out.println(expected); Assert.assertTrue(Math.abs(expected.getTime() - date.getTime()) <= TimeUnit.MINUTES.toMillis(1)); }