MotherService { public void close(FormSubmission submission) { close(submission.entityId(), submission.getFieldValue(CLOSE_REASON_FIELD_NAME)); } 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 shouldNotDoAnythingWhenANCIsClosedAndMotherDoesNotExist() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("entity id 1"); when(allBeneficiaries.findMotherWithOpenStatus("entity id 1")).thenReturn(null); service.close(submission); verify(allBeneficiaries, times(0)).closeMother("entity id 1"); verifyZeroInteractions(allEligibleCouples); }
@Test public void shouldCloseECWhenMotherIsClosedAndReasonIsDeath() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("entity id 1"); when(submission.getFieldValue("closeReason")).thenReturn("death_of_mother"); when(allBeneficiaries.findMotherWithOpenStatus("entity id 1")).thenReturn(new Mother("entity id 1", "ec entity id 1", "thayi 1", "2013-01-01")); service.close(submission); verify(allEligibleCouples).close("ec entity id 1"); }
@Test public void shouldCloseECWhenWomanIsClosedAndReasonIsDeath() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("entity id 1"); when(submission.getFieldValue("closeReason")).thenReturn("death_of_woman"); when(allBeneficiaries.findMotherWithOpenStatus("entity id 1")).thenReturn(new Mother("entity id 1", "ec entity id 1", "thayi 1", "2013-01-01")); service.close(submission); verify(allEligibleCouples).close("ec entity id 1"); }
@Test public void shouldCloseECWhenMotherIsClosedAndReasonIsPermanentRelocation() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("entity id 1"); when(submission.getFieldValue("closeReason")).thenReturn("relocation_permanent"); when(allBeneficiaries.findMotherWithOpenStatus("entity id 1")).thenReturn(new Mother("entity id 1", "ec entity id 1", "thayi 1", "2013-01-01")); service.close(submission); verify(allEligibleCouples).close("ec entity id 1"); }
@Test public void shouldCloseECWhenMotherIsClosedUsingPNCCloseAndReasonIsPermanentRelocation() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("entity id 1"); when(submission.getFieldValue("closeReason")).thenReturn("permanent_relocation"); when(allBeneficiaries.findMotherWithOpenStatus("entity id 1")).thenReturn(new Mother("entity id 1", "ec entity id 1", "thayi 1", "2013-01-01")); service.close(submission); verify(allEligibleCouples).close("ec entity id 1"); }
@Test public void shouldNotCloseECWhenMotherIsClosedForOtherReasons() throws Exception { FormSubmission submission = mock(FormSubmission.class); when(submission.entityId()).thenReturn("entity id 1"); when(submission.getFieldValue("closeReason")).thenReturn("other_reason"); when(allBeneficiaries.findMotherWithOpenStatus("entity id 1")).thenReturn(new Mother("entity id 1", "ec entity id 1", "thayi 1", "2013-01-01")); service.close(submission); verifyZeroInteractions(allEligibleCouples); }