ChildService { public void registerForOA(FormSubmission submission) { Child child = allBeneficiaries.findChild(submission.getFieldValue(CHILD_ID)); child.setThayiCardNumber(submission.getFieldValue(THAYI_CARD_NUMBER)); allBeneficiaries.updateChild(child); Map<String, String> immunizationDateFieldMap = createImmunizationDateFieldMap(); String immunizationsGiven = submission.getFieldValue(AllConstants.ChildRegistrationOAFields.IMMUNIZATIONS_GIVEN); immunizationsGiven = isBlank(immunizationsGiven) ? "" : immunizationsGiven; allTimelines.add(forChildBirthInChildProfile( submission.getFieldValue(CHILD_ID), submission.getFieldValue(AllConstants.ChildRegistrationOAFields.DATE_OF_BIRTH), submission.getFieldValue(AllConstants.ChildRegistrationOAFields.WEIGHT), immunizationsGiven)); for (String immunization : immunizationsGiven.split(SPACE)) { serviceProvidedService.add(ServiceProvided.forChildImmunization(submission.entityId(), immunization, submission.getFieldValue(immunizationDateFieldMap.get(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 shouldAddTimelineEventWhenChildIsRegisteredForOA() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("ec id 1"); when(submission.getFieldValue("motherId")).thenReturn("mother id 1"); when(submission.getFieldValue("id")).thenReturn("child id 1"); when(submission.getFieldValue("dateOfBirth")).thenReturn("2013-01-02"); when(submission.getFieldValue("gender")).thenReturn("female"); when(submission.getFieldValue("weight")).thenReturn("3"); when(submission.getFieldValue("immunizationsGiven")).thenReturn("bcg opv_0"); when(submission.getFieldValue("bcgDate")).thenReturn("2012-01-06"); when(submission.getFieldValue("opv0Date")).thenReturn("2012-01-07"); when(submission.getFieldValue("thayiCardNumber")).thenReturn("1234567"); when(allBeneficiaries.findChild("child id 1")).thenReturn(child); service.registerForOA(submission); verify(child).setThayiCardNumber("1234567"); verify(allBeneficiaries).updateChild(child); verify(allTimelineEvents).add(forChildBirthInChildProfile("child id 1", "2013-01-02", "3", "bcg opv_0")); verify(serviceProvidedService).add(forChildImmunization("ec id 1", "bcg", "2012-01-06")); verify(serviceProvidedService).add(forChildImmunization("ec id 1", "opv_0", "2012-01-07")); }