DropScheduleService { DateTime getLastDropDueDate(DateTime before) { DateTime lastDropDueDate = null; HashSet<Integer> dropDueDaysSet = Sets.newHashSet(dropScheduleConfig.getDueDays()); for (int daysToSubstract = 0; daysToSubstract <= 7; daysToSubstract++) { DateTime candidate = before.minusDays(daysToSubstract).withTime(dropScheduleConfig.getDueLocalTime()); if (dropDueDaysSet.contains(candidate.getDayOfWeek()) && !candidate.isAfter(before)) { lastDropDueDate = candidate; break; } } return lastDropDueDate; }  DateTime getLastDropCreatedDate();  }
@Test public void testGetLastDropDueDateDuringWeekend() { DateTime before = new DateTime("2018-06-09T21:00:00.000-07:00", dateTimeZone); assertEquals("2018-06-08T14:00:00.000-07:00", dropSchedule.getLastDropDueDate(before).toString()); }
@Test public void testGetLastDropDueDateExactSameTime() { DateTime before = new DateTime("2018-06-08T14:00:00.000-07:00", dateTimeZone); assertEquals("2018-06-08T14:00:00.000-07:00", dropSchedule.getLastDropDueDate(before).toString()); }
@Test public void testGetLastDropDueDateSameDayBeforeDropTime() { DateTime before = new DateTime("2018-06-08T11:00:00.000-07:00", dateTimeZone); assertEquals("2018-06-07T14:00:00.000-07:00", dropSchedule.getLastDropDueDate(before).toString()); }
@Test public void testGetLastDropDueDateSameDayAfterDropTime() { DateTime before = new DateTime("2018-06-08T16:00:00.000-07:00", dateTimeZone); assertEquals("2018-06-08T14:00:00.000-07:00", dropSchedule.getLastDropDueDate(before).toString()); }
@Test public void testGetLastDropDueDateEmptyWorkingDays() { doReturn(Arrays.asList()).when(dropScheduleConfig).getDueDays(); DateTime before = new DateTime("2018-06-08T16:00:00.000-07:00", dateTimeZone); assertNull(dropSchedule.getLastDropDueDate(before)); }
@Test public void testGetLastDropDueDatePreviousWeek() { doReturn(Arrays.asList(5)).when(dropScheduleConfig).getDueDays(); DateTime before = new DateTime("2018-06-06T16:00:00.000-07:00", dateTimeZone); assertEquals("2018-06-01T14:00:00.000-07:00", dropSchedule.getLastDropDueDate(before).toString()); }
@Test public void testGetLastDropDueDateOneWeekAgo() { doReturn(Arrays.asList(5)).when(dropScheduleConfig).getDueDays(); DateTime before = new DateTime("2018-06-08T11:00:00.000-07:00", dateTimeZone); assertEquals("2018-06-01T14:00:00.000-07:00", dropSchedule.getLastDropDueDate(before).toString()); }