PatientLegalRepresentativeAssociationServiceImpl implements
		PatientLegalRepresentativeAssociationService { @Override public List<PatientLegalRepresentativeAssociationDto> findAllPatientLegalRepresentativeAssociationDtos() { AuthenticatedUser currentUser = userContext.getCurrentUser(); String username = currentUser.getUsername(); Patient patient = patientRepository.findByUsername(username); Long patientId = patient.getId(); List<PatientLegalRepresentativeAssociationDto> associationDtos = new ArrayList<PatientLegalRepresentativeAssociationDto>(); List<PatientLegalRepresentativeAssociation> allAssociations = patientLegalRepresentativeAssociationRepository .findAll(); for (PatientLegalRepresentativeAssociation association : allAssociations) { if (association.getPatientLegalRepresentativeAssociationPk() .getPatient().getId() == patientId) { associationDtos .add(getPatientLegalRepresentativeAssociationDto(association)); } } return associationDtos; } PatientLegalRepresentativeAssociationServiceImpl(
			PatientLegalRepresentativeAssociationRepository patientLegalRepresentativeAssociationRepository,
			PatientRepository patientRepository,
			LegalRepresentativeTypeCodeRepository legalRepresentativeTypeCodeRepository,
			ModelMapper modelMapper, UserContext userContext); @Override long countAllPatientLegalRepresentativeAssociations(); @Override void deletePatientLegalRepresentativeAssociation(
			PatientLegalRepresentativeAssociation patientLegalRepresentativeAssociation); @Override void deletePatientLegalRepresentativeById(Long legalRepId); @Override PatientLegalRepresentativeAssociation findPatientLegalRepresentativeAssociation(
			Long id); @Override List<PatientLegalRepresentativeAssociation> findAllPatientLegalRepresentativeAssociations(); @Override List<PatientLegalRepresentativeAssociationDto> findAllPatientLegalRepresentativeAssociationDtos(); @Override List<PatientProfileDto> findAllPatientLegalRepresentativeDto(); @Override List<PatientLegalRepresentativeAssociation> findPatientLegalRepresentativeAssociationEntries(
			int firstResult, int maxResults); @Override void savePatientLegalRepresentativeAssociation(
			PatientLegalRepresentativeAssociation patientLegalRepresentativeAssociation); @Override void savePatientLegalRepresentativeAssociationDto(
			PatientLegalRepresentativeAssociationDto patientLegalRepresentativeAssociationDto); @Override PatientLegalRepresentativeAssociation updatePatientLegalRepresentativeAssociation(
			PatientLegalRepresentativeAssociation patientLegalRepresentativeAssociation); @Override void updatePatientLegalRepresentativeAssociationDto(
			PatientLegalRepresentativeAssociationDto patientLegalRepresentativeAssociationDto); @Override List<LegalRepresentativeDto> getAllLegalRepresentativeDto(); @Override PatientLegalRepresentativeAssociationDto getAssociationDtoFromLegalRepresentativeDto(
			LegalRepresentativeDto legalRepresentativeDto); @Override PatientProfileDto getPatientDtoFromLegalRepresentativeDto(
			LegalRepresentativeDto legalRepresentativeDto);  }
@Test public void testFindAllPatientLegalRepresentativeAssociationDtos() { Patient patient = mock(Patient.class); when(patientRepository.findByUsername(anyString())).thenReturn(patient); when(patient.getId()).thenReturn((long) 1); List<PatientLegalRepresentativeAssociation> allAssociations = new ArrayList<PatientLegalRepresentativeAssociation>(); List<PatientLegalRepresentativeAssociationDto> associationDtos = new ArrayList<PatientLegalRepresentativeAssociationDto>(); List<PatientLegalRepresentativeAssociationDto> associationDtosSpy = spy(associationDtos); PatientLegalRepresentativeAssociation association = mock(PatientLegalRepresentativeAssociation.class); allAssociations.add(association); PatientLegalRepresentativeAssociationPk associationPk = mock(PatientLegalRepresentativeAssociationPk.class); Patient patient2 = mock(Patient.class); PatientLegalRepresentativeAssociationDto associationDto = mock(PatientLegalRepresentativeAssociationDto.class); Patient legalRep = mock(Patient.class); when(patientLegalRepresentativeAssociationRepository.findAll()) .thenReturn(allAssociations); when(association.getPatientLegalRepresentativeAssociationPk()) .thenReturn(associationPk); when(associationPk.getPatient()).thenReturn(patient2); when(associationPk.getLegalRepresentative()).thenReturn(legalRep); when(patient2.getId()).thenReturn((long) 1); when( modelMapper.map(association, PatientLegalRepresentativeAssociationDto.class)) .thenReturn(associationDto); associationDtos = patientLegalRepresentativeAssociationService .findAllPatientLegalRepresentativeAssociationDtos(); assertEquals(associationDto, associationDtos.get(0)); }