AlertService { public void create(Action action) { if (action.isActionActive() == null || action.isActionActive()) { repository.createAlert(new Alert(action.caseID(), action.get("scheduleName"), action.get("visitCode"), AlertStatus.from(action.get("alertStatus")), action.get("startDate"), action.get("expiryDate"))); } } AlertService(AlertRepository repository); void create(Action action); void close(Action action); void deleteAll(Action action); List<Alert> findByEntityIdAndAlertNames(String entityId, String... names); void changeAlertStatusToInProcess(String entityId, String alertName);  }
@Test public void shouldAddAnAlertIntoAlertRepositoryForMotherCreateAlertAction() throws Exception { Action actionForMother = actionForCreateAlert("Case X", normal.value(), BeneficiaryType.mother.value(), "Schedule 1", "ANC 1", "2012-01-01", "2012-01-22", "0"); service.create(actionForMother); verify(alertRepository).createAlert(new Alert("Case X", "Schedule 1", "ANC 1", normal, "2012-01-01", "2012-01-22")); verifyNoMoreInteractions(alertRepository); }
@Test public void shouldAddAnAlertIntoAlertRepositoryForECCreateAlertAction() throws Exception { Action actionForEC = actionForCreateAlert("Case X", normal.value(), BeneficiaryType.ec.value(), "Schedule 1", "Milestone 1", "2012-01-01", "2012-01-22", "0"); service.create(actionForEC); verify(alertRepository).createAlert(new Alert("Case X", "Schedule 1", "Milestone 1", normal, "2012-01-01", "2012-01-22")); verifyNoMoreInteractions(alertRepository); }
@Test public void shouldAddAnAlertIntoAlertRepositoryForECCreateAlertActionWhenThereIsNoMother() throws Exception { Action actionForEC = actionForCreateAlert("Case X", normal.value(), BeneficiaryType.ec.value(), "Schedule 1", "Milestone 1", "2012-01-01", "2012-01-22", "0"); service.create(actionForEC); verify(alertRepository).createAlert(new Alert("Case X", "Schedule 1", "Milestone 1", normal, "2012-01-01", "2012-01-22")); verifyNoMoreInteractions(alertRepository); }
@Test public void shouldNotCreateIfActionIsInactive() throws Exception { Action actionForMother = new Action("Case X", "alert", "createAlert", new HashMap<String, String>(), "0", false, new HashMap<String, String>()); service.create(actionForMother); verifyZeroInteractions(alertRepository); }
@Test public void shouldAddAnAlertIntoAlertRepositoryForChildCreateAlertAction() throws Exception { Action actionForMother = actionForCreateAlert("Case X", urgent.value(), BeneficiaryType.child.value(), "Schedule 1", "Milestone 1", "2012-01-01", "2012-01-22", "0"); service.create(actionForMother); verify(alertRepository).createAlert(new Alert("Case X", "Schedule 1", "Milestone 1", urgent, "2012-01-01", "2012-01-22")); verifyNoMoreInteractions(alertRepository); }