AuditServiceImpl implements AuditService { @Override public HistoryDto findHistoryDetail(Number n) { HistoryDto hd = makeHistoryDto(); hd.setRevisionid(n.longValue()); RevisionInfoEntity patientRevisionEntity = patientRevisionEntityRepository .findOneById(n); List<ModifiedEntityTypeEntity> modifiedEntityTypeEntitys = modifiedEntityTypeEntityRepository .findAllByRevision(patientRevisionEntity); if (patientRevisionEntity.getUsername() != null) { String username1 = patientRevisionEntity.getUsername(); if (patientRepository.findByUsername(username1) != null) { Patient patientA1 = patientRepository.findByUsername(username1); String changedBy = patientA1.getLastName() + ", " + patientA1.getFirstName(); hd.setChangedBy(changedBy); } if (staffRepository.findByUsername(username1) != null) { hd.setChangedBy("provider staff"); } } Long timestamp = patientRevisionEntity.getTimestamp(); String revdate = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss") .format(timestamp); hd.setTimestamp(revdate); String revtp = findRevType(modifiedEntityTypeEntitys); String entityClassname = findRevClassName(modifiedEntityTypeEntitys); hd.setRecType(revtp); hd.setType(entityClassname); return hd; } AuditServiceImpl(
			EntityManagerFactory entityManagerFactory,
			PatientRepository patientRepository,
			RevisionInfoEntityRepository patientRevisionEntityRepository,
			ModifiedEntityTypeEntityRepository modifiedEntityTypeEntityRepository,
			PatientLegalRepresentativeAssociationRepository patientLegalRepresentativeAssociationRepository,
			StaffRepository staffRepository); @Override List<HistoryDto> findAllHistory(String username); @Override List<HistoryDto> getReversed(List<HistoryDto> original); @Override List<HistoryDto> findHistoryDetails(List<Number> revisions); @Override List<HistoryDto> makeHistoryDtos(); @Override HistoryDto makeHistoryDto(); @Override HistoryDto findHistoryDetail(Number n); List<HistoryDto> findConsentRevokationHistoryByPatient(
			AuditReader reader, long patientId); List<HistoryDto> findConsentSignPDFHistoryByPatient(
			AuditReader reader, long patientId); @Override String findRevType(
			List<ModifiedEntityTypeEntity> modifiedEntityTypeEntitys); @Override String findRevType(Byte btype); @Override String findRevClassName(
			List<ModifiedEntityTypeEntity> modifiedEntityTypeEntitys); @Override List<HistoryDto> findLegalHistoryByPatient(long patientId); @Override List<HistoryDto> findLegalHistoryDetails(List<Number> revisions); @Override HistoryDto findLegalHistoryDetail(Number n);  }
@Test public void testFindHistoryDetail() { AuditService pasutSpy = spy(pasut); Number n = mock(Number.class); HistoryDto hd = mock(HistoryDto.class); RevisionInfoEntity patientRevisionEntity = mock(RevisionInfoEntity.class); @SuppressWarnings("unchecked") List<ModifiedEntityTypeEntity> modifiedEntityTypeEntitys = mock(List.class); Patient patient = mock(Patient.class); when(pasutSpy.makeHistoryDto()).thenReturn(hd); when(patientRevisionEntityRepository.findOneById(n)).thenReturn( patientRevisionEntity); when( modifiedEntityTypeEntityRepository .findAllByRevision(any(RevisionInfoEntity.class))) .thenReturn(modifiedEntityTypeEntitys); when(patientRevisionEntity.getUsername()).thenReturn("username"); when(patientRepository.findByUsername(anyString())).thenReturn(patient); when(patient.getLastName()).thenReturn("LastName"); when(patient.getFirstName()).thenReturn("FirstName"); when(patientRevisionEntity.getTimestamp()).thenReturn((long) 1); pasutSpy.findHistoryDetail(n); verify(pasutSpy, times(1)).findRevType(modifiedEntityTypeEntitys); verify(pasutSpy, times(1)).findRevClassName(modifiedEntityTypeEntitys); verify(hd, times(1)).setRevisionid(anyLong()); verify(hd, times(1)).setChangedBy(anyString()); verify(hd, times(1)).setTimestamp(anyString()); verify(hd, times(1)).setRecType(anyString()); verify(hd, times(1)).setType(anyString()); }