MotherService { public void ifaTabletsGiven(FormSubmission submission) { String numberOfIFATabletsGiven = submission.getFieldValue(NUMBER_OF_IFA_TABLETS_GIVEN); if (tryParse(numberOfIFATabletsGiven, 0) > 0) { allTimelines.add(forIFATabletsGiven(submission.entityId(), numberOfIFATabletsGiven, submission.getFieldValue(IFA_TABLETS_DATE))); serviceProvidedService.add(ServiceProvided.forIFATabletsGiven(submission.entityId(), numberOfIFATabletsGiven, submission.getFieldValue(IFA_TABLETS_DATE))); } } MotherService(AllBeneficiaries allBeneficiaries, AllEligibleCouples allEligibleCouples,
                         AllTimelineEvents allTimelineEvents, ServiceProvidedService serviceProvidedService); void registerANC(FormSubmission submission); void registerOutOfAreaANC(FormSubmission submission); void ancVisit(FormSubmission submission); void close(FormSubmission submission); void close(String entityId, String reason); void ttProvided(FormSubmission submission); void ifaTabletsGiven(FormSubmission submission); void hbTest(FormSubmission submission); void deliveryOutcome(FormSubmission submission); void pncVisitHappened(FormSubmission submission); void deliveryPlan(FormSubmission submission); static final String MOTHER_ID; static String submissionDate; }
@Test public void shouldAddTimelineEventWhenIFATabletsAreGiven() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("entity id 1"); when(submission.getFieldValue("numberOfIFATabletsGiven")).thenReturn("100"); when(submission.getFieldValue("ifaTabletsDate")).thenReturn("2013-02-01"); service.ifaTabletsGiven(submission); verify(allTimelineEvents).add(forIFATabletsGiven("entity id 1", "100", "2013-02-01")); }
@Test public void shouldAddServiceProvidedWhenIFATabletsAreGiven() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("entity id 1"); when(submission.getFieldValue("numberOfIFATabletsGiven")).thenReturn("100"); when(submission.getFieldValue("ifaTabletsDate")).thenReturn("2013-02-01"); service.ifaTabletsGiven(submission); verify(serviceProvidedService).add(new ServiceProvided("entity id 1", "IFA", "2013-02-01", mapOf("dose", "100"))); }
@Test public void shouldDoNothingWhenIFATabletsAreNotGiven() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("entity id 1"); when(submission.getFieldValue("numberOfIFATabletsGiven")).thenReturn("0"); when(submission.getFieldValue("ifaTabletsDate")).thenReturn("2013-02-01"); service.ifaTabletsGiven(submission); verifyZeroInteractions(allTimelineEvents); verifyZeroInteractions(serviceProvidedService); }