PatientServiceImpl implements PatientService { @Override public List<AddConsentIndividualProviderDto> findAddConsentIndividualProviderDtoByUsername( String username) { Patient patient = patientRepository.findByUsername(username); List<AddConsentIndividualProviderDto> individualProvidersDto = new ArrayList<AddConsentIndividualProviderDto>(); Set<IndividualProvider> individualProviders = patient .getIndividualProviders(); Iterator<IndividualProvider> individualProvidersIterator = individualProviders .iterator(); while (individualProvidersIterator.hasNext()) { individualProvidersDto.add(modelMapper.map( individualProvidersIterator.next(), AddConsentIndividualProviderDto.class)); } return individualProvidersDto; } PatientServiceImpl(
			PatientRepository patientRepository,
			PatientLegalRepresentativeAssociationRepository patientLegalRepresentativeAssociationRepository,
			ModelMapper modelMapper,
			UserContext userContext,
			DtoToDomainEntityMapper<PatientProfileDto, Patient> patientProfileDtoToPatientMapper,
			UsersRepository usersRepository, PasswordEncoder passwordEncoder,
			EmailSender emailSender, PixService pixService); @Override long countAllPatients(); @Override PatientProfileDto findPatient(Long id); @Override List<PatientAdminDto> findAllPatientByFirstNameAndLastName(
			String[] tokens); @Override PatientProfileDto findByUsername(String username); @Override Long findIdByUsername(String username); @Override String findUsernameById(long id); @Override String findPatientEmailByUsername(String username); @Override PatientProfileDto findPatientProfileByUsername(String username); @Override PatientConnectionDto findPatientConnectionByUsername(String username); @Override PatientConnectionDto findPatientConnectionByPatient(Patient patient); @Override PatientConnectionDto findPatientConnectionById(long id); @Override List<PatientProfileDto> findPatientEntries(int pageNumber,
			int pageSize); @Override @Transactional PatientProfileDto savePatient(PatientProfileDto patientDto); @Override @Transactional void updatePatient(PatientProfileDto patientDto); @Override @Transactional void updateEid(String username); @Override @Transactional void updateEid(long id); @Override List<AddConsentIndividualProviderDto> findAddConsentIndividualProviderDtoByUsername(
			String username); @Override List<AddConsentOrganizationalProviderDto> findAddConsentOrganizationalProviderDtoByPatientId(
			long pateintId); @Override List<AddConsentIndividualProviderDto> findAddConsentIndividualProviderDtoByPatientId(
			long pateintId); @Override List<AddConsentOrganizationalProviderDto> findAddConsentOrganizationalProviderDtoByUsername(
			String username); @Override boolean isLegalRepForCurrentUser(Long legalRepId); @Override List<RecentPatientDto> findRecentPatientDtosById(List<String> ids); static final Integer LAST_N_DIGITS_OF_SSN; }
@Test public void testFindAddConsentIndividualProviderDtoByUsername() { final String username = "TheUsername"; Patient patient = mock(Patient.class); when(patientRepository.findByUsername(username)).thenReturn(patient); IndividualProvider provider1 = mock(IndividualProvider.class); IndividualProvider provider2 = mock(IndividualProvider.class); Set<IndividualProvider> providerSet = new HashSet(); providerSet.add(provider1); providerSet.add(provider2); when(patient.getIndividualProviders()).thenReturn(providerSet); AddConsentIndividualProviderDto providerDto1 = mock(AddConsentIndividualProviderDto.class); AddConsentIndividualProviderDto providerDto2 = mock(AddConsentIndividualProviderDto.class); when(modelMapper.map(provider1, AddConsentIndividualProviderDto.class)) .thenReturn(providerDto1); when(modelMapper.map(provider2, AddConsentIndividualProviderDto.class)) .thenReturn(providerDto2); List<AddConsentIndividualProviderDto> result = sut .findAddConsentIndividualProviderDtoByUsername(username); assertEquals(2, result.size()); for (AddConsentIndividualProviderDto providerDto : result) { assertTrue(providerDto == providerDto1 || providerDto == providerDto2); } assertTrue(result.get(0) != result.get(1)); }