PatientServiceImpl implements PatientService { @Override public List<PatientProfileDto> findPatientEntries(int pageNumber, int pageSize) { List<Patient> patientList = patientRepository.findAll( new PageRequest(pageNumber, pageSize)).getContent(); List<PatientProfileDto> patientDtoList = new ArrayList<PatientProfileDto>(); for (Patient patient : patientList) { PatientProfileDto patientProfileDto = modelMapper.map(patient, PatientProfileDto.class); patientDtoList.add(patientProfileDto); } return patientDtoList; } 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 testFindPatientEntries() { final int pageNumber = 1; final int pageSize = 9; final Patient patient1 = mock(Patient.class); final Patient patient2 = mock(Patient.class); List<Patient> patientList = new ArrayList<Patient>(); patientList.add(patient1); patientList.add(patient2); int numberOfPatients = patientList.size(); Page<Patient> patientPage = mock(Page.class); when(patientPage.getContent()).thenReturn(patientList); ArgumentMatcher<PageRequest> pageRequestArgumentMatcher = new ArgumentMatcher<PageRequest>() { @Override public boolean matches(Object argument) { PageRequest pageRequest = (PageRequest) argument; if (pageRequest == null) { return false; } if (pageRequest.getPageSize() != pageSize) { return false; } if (pageRequest.getPageNumber() != pageNumber) { return false; } return true; } }; when(patientRepository.findAll(argThat(pageRequestArgumentMatcher))) .thenReturn(patientPage); final PatientProfileDto expectedPatientProfileDto1 = mock(PatientProfileDto.class); when(modelMapper.map(patient1, PatientProfileDto.class)).thenReturn( expectedPatientProfileDto1); final PatientProfileDto expectedPatientProfileDto2 = mock(PatientProfileDto.class); when(modelMapper.map(patient2, PatientProfileDto.class)).thenReturn( expectedPatientProfileDto2); List<PatientProfileDto> result = sut.findPatientEntries(pageNumber, pageSize); assertEquals(numberOfPatients, result.size()); for (PatientProfileDto patientProfileDto : result) { assertTrue(patientProfileDto == expectedPatientProfileDto1 || patientProfileDto == expectedPatientProfileDto2); } assertTrue(result.get(0) != result.get(1)); }