ScheduleService { public void enroll(String entityId, String scheduleName, String referenceDate) { String startingMilestoneName = getStartingMilestoneName(scheduleName, parse(referenceDate)); EnrollmentRequest request = new EnrollmentRequest(entityId, scheduleName, new Time(new LocalTime(preferredTime, 0)), parse(referenceDate), null, null, null, startingMilestoneName, null); scheduleTrackingService.enroll(request); } @Autowired  ScheduleService(ScheduleTrackingService scheduleTrackingService, AllSchedules allSchedules, @Value("#{drishti['preferred.time']}") int preferredTime); void enroll(String entityId, String scheduleName, String referenceDate); void enroll(String entityId, String scheduleName, String milestone, String referenceDate);  }
@Test public void shouldEnrollToFirstMilestoneBasedOnScheduleDatesAndReferenceDate() { DateUtil.fakeIt(parse("2012-01-01")); when(allSchedules.getByName("my_schedule")).thenReturn(schedule); scheduleService.enroll("entity_1", "my_schedule", "2012-01-01"); verify(scheduleTrackingService).enroll(enrollmentFor("entity_1", "my_schedule", firstMilestone.getName(), "2012-01-01")); }
@Test public void shouldEnrollToSecondMilestoneBasedOnScheduleDatesAndReferenceDate() { DateUtil.fakeIt(parse("2012-02-07")); when(allSchedules.getByName("my_schedule")).thenReturn(schedule); scheduleService.enroll("entity_1", "my_schedule", "2012-01-01"); verify(scheduleTrackingService).enroll(enrollmentFor("entity_1", "my_schedule", secondMilestone.getName(), "2012-01-01")); }