ANCService { public void ttProvided(FormSubmission submission) { Mother mother = allMothers.findByCaseId(submission.entityId()); if (mother == null) { logger.warn("Tried to handle TT provided without registered mother. Submission: " + submission); return; } Map<String, String> ttDose = create(TT_DATE_FIELD, submission.getField(TT_DATE_FIELD)) .put(TT_DOSE_FIELD, submission.getField(TT_DOSE_FIELD)) .map(); mother.updateTTDoseInformation(ttDose); allMothers.update(mother); ancSchedulesService.ttVisitHasHappened(submission.entityId(), submission.anmId(), submission.getField(TT_DOSE_FIELD), submission.getField(TT_DATE_FIELD)); List<String> reportFields = reportFieldsDefinition.get(submission.formName()); reportingService.ttProvided(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 shouldHandleTTProvided() { FormSubmission submission = create() .withFormName("tt_2") .withANMId("anm id 1") .withEntityId("entity id 1") .addFormField("ttDate", "2013-01-01") .addFormField("ttDose", "tt2") .addFormField("someKey", "someValue") .build(); List<Map<String, String>> ttDoses = new ArrayList<>(); ttDoses.add(create("ttDate", "2012-12-24") .put("ttDose", "tt1") .map()); Mother mother = new Mother("entity id 1", "ec entity id 1", "thayi 1") .withDetails(mapOf("some-key", "some-value")) .withTTDoses(ttDoses); when(allMothers.findByCaseId("entity id 1")).thenReturn(mother); when(reportFieldsDefinition.get("tt_2")).thenReturn(asList("someKey")); service.ttProvided(submission); Mother updatedMother = new Mother("entity id 1", "ec entity id 1", "thayi 1") .withDetails(create("some-key", "some-value").map()) .withTTDoses(asList( create("ttDate", "2012-12-24") .put("ttDose", "tt1") .map(), create("ttDate", "2013-01-01") .put("ttDose", "tt2") .map() )); verify(allMothers).update(updatedMother); verify(ancSchedulesService).ttVisitHasHappened("entity id 1", "anm id 1", "tt2", "2013-01-01"); verify(motherReportingService).ttProvided(new SafeMap(mapOf("someKey", "someValue"))); }