NotificationServiceImpl implements NotificationService { @Override public String notificationStage(String username, String notify) { Patient patient = patientRepository.findByUsername(username); int providerscount = patient.getIndividualProviders().size() + patient.getOrganizationalProviders().size(); int consentscount = patient.getConsents().size(); boolean consentReviewStatus = checkConsentReviewStatus(patient .getConsents()); boolean consentSignedStatus = checkConsentSignedStatus(patient .getConsents()); switch (consentscount) { case 0: { switch (providerscount) { case 0: return "notification_add_provider"; case 1: { if (notify != null) { if (notify.equals("add")) return "notification_add_one_provider_successed"; } else return "notification_add_second_provider"; } case 2: { if (notify != null) { if (notify.equals("add")) return "notification_add_second_provider_successed"; } else return "notification_add_consent"; } default: return "notification_add_consent"; } } case 1: { if (providerscount < 2) return "notification_add_provider"; else { if (notify != null) { if (notify.equals("add")) return "notification_add_consent_successed"; } else if (consentReviewStatus == false) return "notification_review_sign_consent"; else { if (consentSignedStatus == false) return "notification_sign_consent"; } } } default: { if (providerscount < 2) return "notification_add_provider"; else { if (consentReviewStatus == false) return "notification_review_sign_consent"; else { if (consentSignedStatus == false) return "notification_sign_consent"; } return null; } } } } NotificationServiceImpl(PatientRepository patientRepository); @Override String notificationStage(String username, String notify); @Override boolean checkConsentReviewStatus(Set<Consent> consents); @Override boolean checkConsentSignedStatus(Set<Consent> consents); @Override String notificationValuesetMgmt(String username, String notify,
			String message);  }
@Test public void testnotificationStage_is_add_provider() { Patient patient = mock(Patient.class); when(patientRepository.findByUsername(anyString())).thenReturn(patient); String result = nst.notificationStage("username", null); assertEquals("notification_add_provider", result); }
@Test public void testnotificationStage_is_add_one_provider_successed() { Patient patient = mock(Patient.class); when(patientRepository.findByUsername(anyString())).thenReturn(patient); IndividualProvider individualProvider = mock(IndividualProvider.class); Set<IndividualProvider> individualProviders = new HashSet<IndividualProvider>(); individualProviders.add(individualProvider); when(patient.getIndividualProviders()).thenReturn(individualProviders); String result = nst.notificationStage("username", "add"); assertEquals("notification_add_one_provider_successed", result); }
@Test public void testnotificationStage_is_add_second_provider() { Patient patient = mock(Patient.class); when(patientRepository.findByUsername(anyString())).thenReturn(patient); IndividualProvider individualProvider = mock(IndividualProvider.class); Set<IndividualProvider> individualProviders = new HashSet<IndividualProvider>(); individualProviders.add(individualProvider); when(patient.getIndividualProviders()).thenReturn(individualProviders); String result = nst.notificationStage("username", null); assertEquals("notification_add_second_provider", result); }
@Test public void testnotificationStage_is_add_second_provider_successed() { Patient patient = mock(Patient.class); when(patientRepository.findByUsername(anyString())).thenReturn(patient); IndividualProvider individualProvider = mock(IndividualProvider.class); IndividualProvider individualProvider2 = mock(IndividualProvider.class); Set<IndividualProvider> individualProviders = new HashSet<IndividualProvider>(); individualProviders.add(individualProvider); individualProviders.add(individualProvider2); when(patient.getIndividualProviders()).thenReturn(individualProviders); String result = nst.notificationStage("username", "add"); assertEquals("notification_add_second_provider_successed", result); }
@Test public void testnotificationStage_is_add_consent() { Patient patient = mock(Patient.class); when(patientRepository.findByUsername(anyString())).thenReturn(patient); IndividualProvider individualProvider = mock(IndividualProvider.class); IndividualProvider individualProvider2 = mock(IndividualProvider.class); Set<IndividualProvider> individualProviders = new HashSet<IndividualProvider>(); individualProviders.add(individualProvider); individualProviders.add(individualProvider2); when(patient.getIndividualProviders()).thenReturn(individualProviders); String result = nst.notificationStage("username", null); assertEquals("notification_add_consent", result); }
@Test public void testnotificationStage_is_add_consent_successed() { Patient patient = mock(Patient.class); when(patientRepository.findByUsername(anyString())).thenReturn(patient); IndividualProvider individualProvider = mock(IndividualProvider.class); IndividualProvider individualProvider2 = mock(IndividualProvider.class); Set<IndividualProvider> individualProviders = new HashSet<IndividualProvider>(); Set<Consent> consents = new HashSet<Consent>(); Consent consent = mock(Consent.class); consents.add(consent); individualProviders.add(individualProvider); individualProviders.add(individualProvider2); when(patient.getIndividualProviders()).thenReturn(individualProviders); when(patient.getConsents()).thenReturn(consents); String result = nst.notificationStage("username", "add"); assertEquals("notification_add_consent_successed", result); }