EligibleCoupleService { public void fpChange(FormSubmission submission) { String fpMethodChangeDate = submission.getFieldValue(AllConstants.ECRegistrationFields.FAMILY_PLANNING_METHOD_CHANGE_DATE); if (isBlank(fpMethodChangeDate)) { fpMethodChangeDate = submission.getFieldValue(AllConstants.CommonFormFields.SUBMISSION_DATE); } allTimelineEvents.add(forChangeOfFPMethod(submission.entityId(), submission.getFieldValue(AllConstants.ECRegistrationFields.CURRENT_FP_METHOD), submission.getFieldValue(NEW_FP_METHOD_FIELD_NAME), fpMethodChangeDate)); allEligibleCouples.mergeDetails(submission.entityId(), mapOf(AllConstants.ECRegistrationFields.CURRENT_FP_METHOD, submission.getFieldValue(NEW_FP_METHOD_FIELD_NAME))); } EligibleCoupleService(AllEligibleCouples allEligibleCouples, AllTimelineEvents allTimelineEvents, AllBeneficiaries allBeneficiaries); void register(FormSubmission submission); void fpComplications(FormSubmission submission); void fpChange(FormSubmission submission); void renewFPProduct(FormSubmission submission); void closeEligibleCouple(FormSubmission submission);  }
@Test public void shouldCreateTimelineEventAndUpdateEntityWhenFPChangeIsReported() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("entity id 1"); when(submission.getFieldValue("currentMethod")).thenReturn("condom"); when(submission.getFieldValue("newMethod")).thenReturn("ocp"); when(submission.getFieldValue("familyPlanningMethodChangeDate")).thenReturn("2012-01-01"); service.fpChange(submission); verify(allTimelineEvents).add(TimelineEvent.forChangeOfFPMethod("entity id 1", "condom", "ocp", "2012-01-01")); verify(allEligibleCouples).mergeDetails("entity id 1", mapOf("currentMethod", "ocp")); }
@Test public void shouldUseFormSubmissionDateAsChangeDateWhenFPMethodIsChangedAndChangeDateIsBlank() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("entity id 1"); when(submission.getFieldValue("currentMethod")).thenReturn("condom"); when(submission.getFieldValue("newMethod")).thenReturn("none"); when(submission.getFieldValue("submissionDate")).thenReturn("2012-02-01"); service.fpChange(submission); verify(allTimelineEvents).add(TimelineEvent.forChangeOfFPMethod("entity id 1", "condom", "none", "2012-02-01")); verify(allEligibleCouples).mergeDetails("entity id 1", mapOf("currentMethod", "none")); }