PNCSchedulesService { public void unEnrollFromSchedules(String entityId) { List<EnrollmentRecord> openEnrollments = trackingService.search(new EnrollmentsQuery().havingExternalId(entityId).havingState(ACTIVE)); for (EnrollmentRecord enrollment : openEnrollments) { logger.info(format("Un-enrolling PNC with Entity id:{0} from schedule: {1}.", entityId, enrollment.getScheduleName())); trackingService.unenroll(entityId, asList(enrollment.getScheduleName())); } } @Autowired  PNCSchedulesService(ScheduleTrackingService trackingService, ScheduleService scheduleService, ActionService actionService); void deliveryOutcome(String entityId, String date); void unEnrollFromSchedules(String entityId); void fulfillPNCAutoCloseMilestone(String entityId, String anmIdentifier);  }
@Test public void shouldUnenrollAMotherFromAllOpenSchedulesAndRaiseDeleteAllAlertActionDuringClose() { EnrollmentRecord record1 = new EnrollmentRecord("Case X", "Schedule 1", null, null, null, null, null, null, null, null); EnrollmentRecord record2 = new EnrollmentRecord("Case X", "Schedule 2", null, null, null, null, null, null, null, null); List<EnrollmentRecord> records = Arrays.asList(record1, record2); when(scheduleTrackingService.search(queryFor("Case X"))).thenReturn(records); schedulesService.unEnrollFromSchedules("Case X"); verify(scheduleTrackingService).unenroll("Case X", Arrays.asList("Schedule 1")); verify(scheduleTrackingService).unenroll("Case X", Arrays.asList("Schedule 2")); }