PatientLegalRepresentativeAssociationServiceImpl implements
		PatientLegalRepresentativeAssociationService { private void deletePatientLegalRepresentativeAssociationById(Long legalRepId) { List<PatientLegalRepresentativeAssociation> patientLegalRepresentativeAssociations = patientLegalRepresentativeAssociationRepository .findByPatientLegalRepresentativeAssociationPkLegalRepresentativeId(legalRepId); for (PatientLegalRepresentativeAssociation association : patientLegalRepresentativeAssociations) { if (patientRepository.findByUsername( userContext.getCurrentUser().getUsername()).getId() == association .getPatientLegalRepresentativeAssociationPk().getPatient() .getId()) { patientLegalRepresentativeAssociationRepository .delete(association); } } } 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 testDeletePatientLegalRepresentativeAssociationById() { List<PatientLegalRepresentativeAssociation> associations = new ArrayList<PatientLegalRepresentativeAssociation>(); PatientLegalRepresentativeAssociation association = mock(PatientLegalRepresentativeAssociation.class); PatientLegalRepresentativeAssociationPk associationPk = mock(PatientLegalRepresentativeAssociationPk.class); when(association.getPatientLegalRepresentativeAssociationPk()) .thenReturn(associationPk); associations.add(association); Patient patient = mock(Patient.class); when(associationPk.getPatient()).thenReturn(patient); when(patient.getId()).thenReturn((long) 1); Patient patient2 = mock(Patient.class); when( patientLegalRepresentativeAssociationRepository .findByPatientLegalRepresentativeAssociationPkLegalRepresentativeId(anyLong())) .thenReturn(associations); when(patientRepository.findByUsername(anyString())) .thenReturn(patient2); when(patient2.getId()).thenReturn((long) 1); patientLegalRepresentativeAssociationService .deletePatientLegalRepresentativeById(anyLong()); verify(patientLegalRepresentativeAssociationRepository).delete( association); }