ChildService { public void updateImmunizations(FormSubmission submission) { String immunizationDate = submission.getFieldValue(AllConstants.ChildImmunizationsFields.IMMUNIZATION_DATE); List<String> immunizationsGivenList = splitFieldValueBySpace(submission, AllConstants.ChildImmunizationsFields.IMMUNIZATIONS_GIVEN); List<String> previousImmunizationsList = splitFieldValueBySpace(submission, AllConstants.ChildImmunizationsFields.PREVIOUS_IMMUNIZATIONS_GIVEN); immunizationsGivenList.removeAll(previousImmunizationsList); for (String immunization : immunizationsGivenList) { allTimelines.add(forChildImmunization(submission.entityId(), immunization, immunizationDate)); serviceProvidedService.add(ServiceProvided.forChildImmunization(submission.entityId(), immunization, immunizationDate)); allAlerts.changeAlertStatusToInProcess(submission.entityId(), immunization); } } ChildService(AllBeneficiaries allBeneficiaries, MotherRepository motherRepository, ChildRepository childRepository,
                        AllTimelineEvents allTimelineEvents, ServiceProvidedService serviceProvidedService, AllAlerts allAlerts); void register(FormSubmission submission); void registerForEC(FormSubmission submission); void pncRegistrationOA(FormSubmission submission); void updateImmunizations(FormSubmission submission); void pncVisitHappened(FormSubmission submission); void close(FormSubmission submission); void updatePhotoPath(String entityId, String imagePath); void updateIllnessStatus(FormSubmission submission); void updateVitaminAProvided(FormSubmission submission); void registerForOA(FormSubmission submission);  }
@Test public void shouldAddTimelineEventsWhenChildImmunizationsAreUpdated() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("child id 1"); when(submission.getFieldValue("previousImmunizations")).thenReturn("bcg"); when(submission.getFieldValue("immunizationsGiven")).thenReturn("bcg opv_0 pentavalent_0"); when(submission.getFieldValue("immunizationDate")).thenReturn("2013-01-01"); service.updateImmunizations(submission); verify(allTimelineEvents).add(TimelineEvent.forChildImmunization("child id 1", "opv_0", "2013-01-01")); verify(allTimelineEvents).add(TimelineEvent.forChildImmunization("child id 1", "pentavalent_0", "2013-01-01")); verifyNoMoreInteractions(allTimelineEvents); }
@Test public void shouldAddServiceProvidedWhenChildImmunizationsAreUpdated() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("child id 1"); when(submission.getFieldValue("previousImmunizations")).thenReturn("bcg"); when(submission.getFieldValue("immunizationsGiven")).thenReturn("bcg opv_0 pentavalent_0"); when(submission.getFieldValue("immunizationDate")).thenReturn("2013-01-01"); service.updateImmunizations(submission); verify(serviceProvidedService).add(new ServiceProvided("child id 1", "opv_0", "2013-01-01", null)); verify(serviceProvidedService).add(new ServiceProvided("child id 1", "pentavalent_0", "2013-01-01", null)); verifyNoMoreInteractions(serviceProvidedService); }
@Test public void shouldMarkRemindersAsInProcessWhenImmunizationsAreProvided() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("child id 1"); when(submission.getFieldValue("previousImmunizations")).thenReturn("bcg"); when(submission.getFieldValue("immunizationsGiven")).thenReturn("bcg opv_0 pentavalent_0"); when(submission.getFieldValue("immunizationDate")).thenReturn("2013-01-01"); service.updateImmunizations(submission); verify(allAlerts).changeAlertStatusToInProcess("child id 1", "opv_0"); verify(allAlerts).changeAlertStatusToInProcess("child id 1", "pentavalent_0"); verifyNoMoreInteractions(allAlerts); }