ANCService { public void deliveryOutcome(FormSubmission submission) { if (!allMothers.exists(submission.entityId())) { logger.warn("Tried to handle delivery outcome without registered mother. Submission: " + submission); return; } ancSchedulesService.unEnrollFromAllSchedules(submission.entityId()); List<String> reportFields = reportFieldsDefinition.get(submission.formName()); reportingService.deliveryOutcome(new SafeMap(submission.getFields(reportFields))); } @Autowired  ANCService(AllMothers allMothers,
                      AllEligibleCouples eligibleCouples,
                      ANCSchedulesService ancSchedulesService,
                      ActionService actionService,
                      MotherReportingService reportingService,
                      ReportFieldsDefinition reportFieldsDefinition); void registerANC(FormSubmission submission); void registerOutOfAreaANC(FormSubmission submission); void ancVisit(FormSubmission submission); void ttProvided(FormSubmission submission); void ifaTabletsGiven(FormSubmission submission); void hbTest(FormSubmission submission); void deliveryPlanned(FormSubmission submission); void deliveryOutcome(FormSubmission submission); void close(FormSubmission submission); void ancInvestigations(FormSubmission submission);  }
@Test public void shouldHandleDeliveryOutcome() { FormSubmission submission = create() .withFormName("delivery_outcome") .withANMId("anm id 1") .withEntityId("entity id 1") .addFormField("someKey", "someValue") .build(); when(allMothers.exists("entity id 1")).thenReturn(true); when(reportFieldsDefinition.get("delivery_outcome")).thenReturn(asList("someKey")); service.deliveryOutcome(submission); verify(ancSchedulesService).unEnrollFromAllSchedules("entity id 1"); verify(motherReportingService).deliveryOutcome(new SafeMap(mapOf("someKey", "someValue"))); }
@Test public void shouldDoNothingIfMotherIsNotRegisteredWhileDeliveryOutcome() { when(allMothers.exists("entity id 1")).thenReturn(false); service.deliveryOutcome(create().build()); verifyZeroInteractions(ancSchedulesService); verifyZeroInteractions(reportFieldsDefinition); verifyZeroInteractions(motherReportingService); }