AuditServiceImpl implements AuditService { @Override public String findRevClassName( List<ModifiedEntityTypeEntity> modifiedEntityTypeEntitys) { StringBuffer entityClassname = new StringBuffer(); if (modifiedEntityTypeEntitys.size() == 1) { String entityname = new String(modifiedEntityTypeEntitys.get(0) .getEntityClassName()); entityClassname.append(entityname .substring(entityname.lastIndexOf('.') + 1).trim() .replaceAll("(\\p{Ll})(\\p{Lu})", "$1 $2")); } if (modifiedEntityTypeEntitys.size() == 2) { if (modifiedEntityTypeEntitys.get(0).getRevisionType() != 1) { String entityname = new String(modifiedEntityTypeEntitys.get(0) .getEntityClassName()); entityClassname.append(entityname .substring(entityname.lastIndexOf('.') + 1).trim() .replaceAll("(\\p{Ll})(\\p{Lu})", "$1 $2")); } else { String entityname = new String(modifiedEntityTypeEntitys.get(1) .getEntityClassName()); entityClassname.append(entityname .substring(entityname.lastIndexOf('.') + 1).trim() .replaceAll("(\\p{Ll})(\\p{Lu})", "$1 $2")); } } if (modifiedEntityTypeEntitys.size() == 3) { entityClassname.append("Add provider"); } return entityClassname.toString(); } 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 testFindRevClassName_when_modifiedEntity_size_is_one() { List<ModifiedEntityTypeEntity> modifiedEntityTypeEntitys = new ArrayList<ModifiedEntityTypeEntity>(); modifiedEntityTypeEntitys.add(mock(ModifiedEntityTypeEntity.class)); when(modifiedEntityTypeEntitys.get(0).getEntityClassName()).thenReturn( "gov.samhsa.consent2share.domain.patient.Patient"); String revClassName = pasut.findRevClassName(modifiedEntityTypeEntitys); assertEquals("Patient", revClassName); }
@Test public void testFindRevClassName_when_modifiedEntity_size_is_two() { List<ModifiedEntityTypeEntity> modifiedEntityTypeEntitys = new ArrayList<ModifiedEntityTypeEntity>(); modifiedEntityTypeEntitys.add(mock(ModifiedEntityTypeEntity.class)); modifiedEntityTypeEntitys.add(mock(ModifiedEntityTypeEntity.class)); when(modifiedEntityTypeEntitys.get(0).getRevisionType()).thenReturn( (byte) 1); when(modifiedEntityTypeEntitys.get(1).getEntityClassName()).thenReturn( "gov.samhsa.consent2share.domain.patient.Patient"); String revClassName = pasut.findRevClassName(modifiedEntityTypeEntitys); assertEquals("Patient", revClassName); }
@Test public void testFindRevClassName_when_modifiedEntity_size_is_two_Second() { List<ModifiedEntityTypeEntity> modifiedEntityTypeEntitys = new ArrayList<ModifiedEntityTypeEntity>(); modifiedEntityTypeEntitys.add(mock(ModifiedEntityTypeEntity.class)); modifiedEntityTypeEntitys.add(mock(ModifiedEntityTypeEntity.class)); when(modifiedEntityTypeEntitys.get(0).getRevisionType()).thenReturn( (byte) 0); when(modifiedEntityTypeEntitys.get(0).getEntityClassName()).thenReturn( "gov.samhsa.consent2share.domain.provider.IndividualProvider"); String revClassName = pasut.findRevClassName(modifiedEntityTypeEntitys); assertEquals("Individual Provider", revClassName); }
@Test public void testFindRevClassName_when_modifiedEntity_size_is_three() { List<ModifiedEntityTypeEntity> modifiedEntityTypeEntitys = new ArrayList<ModifiedEntityTypeEntity>(); modifiedEntityTypeEntitys.add(mock(ModifiedEntityTypeEntity.class)); modifiedEntityTypeEntitys.add(mock(ModifiedEntityTypeEntity.class)); modifiedEntityTypeEntitys.add(mock(ModifiedEntityTypeEntity.class)); String revClassName = pasut.findRevClassName(modifiedEntityTypeEntitys); assertEquals("Add provider", revClassName); }