RealtimeBarUtil { public static LocalDateTime getBarDate() { LocalDateTime dateTime; if(testDateTime == null) { dateTime = LocalDateTime.now(); } else { dateTime = testDateTime; } int currentSecond = dateTime.getSecond(); dateTime = dateTime.withNano(0).withSecond(0); if (currentSecond >= 30) { dateTime = dateTime.plusMinutes(1); } return dateTime; }  static JobDetail buildJob(String jobName, IBarBuilder barBuilder); static Trigger getTrigger(String jobName, int interval, LengthUnit units); static Date getFirstScheduledDate(Date date, int interval); static String getJobName(RealtimeBarRequest realtimeBarRequest); static LocalDateTime getBarDate(); static final String BAR_BUILDER_DATA; }
@Test public void testGetBarDate_ZeroSecond() { LocalDateTime expected = LocalDateTime.of(2012, 6, 1, 5, 30, 0, 0); RealtimeBarUtil.testDateTime = expected; assertEquals(expected, RealtimeBarUtil.getBarDate()); }
@Test public void testGetBarDate_minus3Seconds() { LocalDateTime testDateTime = LocalDateTime.of(2012, 6, 1, 5, 59, 57, 0); LocalDateTime expected = testDateTime.withSecond(0).withMinute(0).withHour(6); RealtimeBarUtil.testDateTime = testDateTime; assertEquals(expected, RealtimeBarUtil.getBarDate()); }
@Test public void testGetBarDate_plus3Seconds() { LocalDateTime testDateTime = LocalDateTime.of(2012, 6, 1, 5, 1, 3, 0); LocalDateTime expected = testDateTime.withSecond(0).withMinute(1).withHour(5); RealtimeBarUtil.testDateTime = testDateTime; assertEquals(expected, RealtimeBarUtil.getBarDate()); }