ECService { public void reportFPComplications(FormSubmission submission) { EligibleCouple couple = allEligibleCouples.findByCaseId(submission.entityId()); if (couple == null) { logger.warn("Tried to report FP Complications of a non-existing EC, with submission: " + submission); return; } FPProductInformation fpProductInformation = new FPProductInformation( submission.entityId(), submission.anmId(), null, null, null, null, null, null, submission.getField(SUBMISSION_DATE_FIELD_NAME), null, submission.getField(COMPLICATION_DATE_FIELD_NAME), submission.getField(NEEDS_FOLLOWUP_FIELD_NAME), submission.getField(NEEDS_REFERRAL_FOLLOWUP_FIELD_NAME)); schedulingService.reportFPComplications(fpProductInformation); } @Autowired  ECService(AllEligibleCouples allEligibleCouples, ECSchedulingService schedulingService, ECReportingService reportingService,
                     ReportFieldsDefinition reportFieldsDefinition); void registerEligibleCouple(FormSubmission submission); void reportFPComplications(FormSubmission submission); void reportFPChange(FormSubmission submission); void renewFPProduct(FormSubmission submission); void followupOnFPMethod(FormSubmission submission); void handleReferralFollowup(FormSubmission submission); void closeEligibleCouple(FormSubmission submission);  }
@Test public void shouldNotDoAnythingWhenFPComplicationIsReportedAndECIsNotFound() throws Exception { when(allEligibleCouples.findByCaseId("entity id 1")).thenReturn(null); FormSubmission submission = FormSubmissionBuilder.create().withFormName("fp_complications").build(); ecService.reportFPComplications(submission); verify(allEligibleCouples).findByCaseId("entity id 1"); verifyZeroInteractions(reportingService); verifyZeroInteractions(schedulingService); }
@Test public void shouldUpdateECSchedulesWhenFPComplicationsIsReported() throws Exception { EligibleCouple ec = new EligibleCouple("entity id 1", "EC Number 1"); when(allEligibleCouples.findByCaseId("entity id 1")).thenReturn(ec); FormSubmission submission = FormSubmissionBuilder.create() .withFormName("fp_complications") .withANMId("anm id 1") .addFormField("currentMethod", "fp method") .addFormField("complicationDate", "2010-12-25") .addFormField("submissionDate", "2010-12-24") .addFormField("needsFollowup", "yes") .addFormField("needsReferralFollowup", "no") .build(); ecService.reportFPComplications(submission); verify(schedulingService).reportFPComplications(new FPProductInformation("entity id 1", "anm id 1", null, null, null, null, null, null, "2010-12-24", null, "2010-12-25", "yes", "no")); }