@Test public void patientWithValidReporterReturnsCorrectContactInfo() throws ComponentLookupException { UserManager users = this.mocker.getInstance(UserManager.class); User user = mock(User.class); when(users.getUser(USER_STR)).thenReturn(user); when(user.getName()).thenReturn(USER_NAME); when(user.getUsername()).thenReturn(USER.getName()); when(user.getAttribute("email")).thenReturn(USER_EMAIL); when(user.getAttribute("company")).thenReturn(USER_INSTITUTION); when(this.patient.getReporter()).thenReturn(USER); List<ContactInfo> result = this.mocker.getComponentUnderTest().getContacts(this.patient); Assert.assertNotNull(result); Assert.assertEquals(1, result.size()); ContactInfo contact = result.get(0); Assert.assertEquals(USER_STR, contact.getUserId()); Assert.assertEquals(USER_NAME, contact.getName()); Assert.assertEquals(Collections.singletonList(USER_EMAIL), contact.getEmails()); Assert.assertEquals(USER_INSTITUTION, contact.getInstitution()); }
@Override public List<ContactInfo> getContacts(Patient patient) { DocumentReference reporter = patient.getReporter(); if (reporter == null) { return Collections.emptyList(); } List<ContactInfo> list = new ArrayList<>(); ContactInfo.Builder contactInfo = new ContactInfo.Builder(); contactInfo.withUserId(this.serializer.serialize(reporter)); User user = this.userManager.getUser(reporter.toString()); if (user != null) { String email = (String) user.getAttribute("email"); String institution = (String) user.getAttribute("company"); contactInfo.withName(user.getName()); contactInfo.withEmail(email); contactInfo.withInstitution(institution); } list.add(contactInfo.build()); return list; }
ReporterContactProvider implements PatientContactProvider { @Override public List<ContactInfo> getContacts(Patient patient) { DocumentReference reporter = patient.getReporter(); if (reporter == null) { return Collections.emptyList(); } List<ContactInfo> list = new ArrayList<>(); ContactInfo.Builder contactInfo = new ContactInfo.Builder(); contactInfo.withUserId(this.serializer.serialize(reporter)); User user = this.userManager.getUser(reporter.toString()); if (user != null) { String email = (String) user.getAttribute("email"); String institution = (String) user.getAttribute("company"); contactInfo.withName(user.getName()); contactInfo.withEmail(email); contactInfo.withInstitution(institution); } list.add(contactInfo.build()); return list; } }
ReporterContactProvider implements PatientContactProvider { @Override public List<ContactInfo> getContacts(Patient patient) { DocumentReference reporter = patient.getReporter(); if (reporter == null) { return Collections.emptyList(); } List<ContactInfo> list = new ArrayList<>(); ContactInfo.Builder contactInfo = new ContactInfo.Builder(); contactInfo.withUserId(this.serializer.serialize(reporter)); User user = this.userManager.getUser(reporter.toString()); if (user != null) { String email = (String) user.getAttribute("email"); String institution = (String) user.getAttribute("company"); contactInfo.withName(user.getName()); contactInfo.withEmail(email); contactInfo.withInstitution(institution); } list.add(contactInfo.build()); return list; }  }
ReporterContactProvider implements PatientContactProvider { @Override public List<ContactInfo> getContacts(Patient patient) { DocumentReference reporter = patient.getReporter(); if (reporter == null) { return Collections.emptyList(); } List<ContactInfo> list = new ArrayList<>(); ContactInfo.Builder contactInfo = new ContactInfo.Builder(); contactInfo.withUserId(this.serializer.serialize(reporter)); User user = this.userManager.getUser(reporter.toString()); if (user != null) { String email = (String) user.getAttribute("email"); String institution = (String) user.getAttribute("company"); contactInfo.withName(user.getName()); contactInfo.withEmail(email); contactInfo.withInstitution(institution); } list.add(contactInfo.build()); return list; }  @Override int getPriority(); @Override List<ContactInfo> getContacts(Patient patient); }
ReporterContactProvider implements PatientContactProvider { @Override public List<ContactInfo> getContacts(Patient patient) { DocumentReference reporter = patient.getReporter(); if (reporter == null) { return Collections.emptyList(); } List<ContactInfo> list = new ArrayList<>(); ContactInfo.Builder contactInfo = new ContactInfo.Builder(); contactInfo.withUserId(this.serializer.serialize(reporter)); User user = this.userManager.getUser(reporter.toString()); if (user != null) { String email = (String) user.getAttribute("email"); String institution = (String) user.getAttribute("company"); contactInfo.withName(user.getName()); contactInfo.withEmail(email); contactInfo.withInstitution(institution); } list.add(contactInfo.build()); return list; }  @Override int getPriority(); @Override List<ContactInfo> getContacts(Patient patient);  }