MotherService { public void deliveryOutcome(FormSubmission submission) { Mother mother = allBeneficiaries.findMotherWithOpenStatus(submission.entityId()); if (mother == null) { logWarn("Failed to handle delivery outcome for mother. Entity ID: " + submission.entityId()); return; } if (BOOLEAN_FALSE.equals(submission.getFieldValue(DID_WOMAN_SURVIVE)) || BOOLEAN_FALSE.equals(submission.getFieldValue(DID_MOTHER_SURVIVE))) { allBeneficiaries.closeMother(submission.entityId()); allEligibleCouples.close(mother.ecCaseId()); return; } allBeneficiaries.switchMotherToPNC(submission.entityId()); } 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 shouldHandleDeliveryOutcome() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("entity id 1"); when(submission.getFieldValue("didWomanSurvive")).thenReturn("yes"); when(allBeneficiaries.findMotherWithOpenStatus("entity id 1")).thenReturn(new Mother("entity id 1", "ec id 1", "1234567", "2014-01-01")); service.deliveryOutcome(submission); verify(allBeneficiaries).switchMotherToPNC("entity id 1"); }