use of org.openmrs.api.DuplicateIdentifierException in project openmrs-core by openmrs.
the class PatientServiceImplTest method checkPatientIdentifiers_shouldThrowDuplicateIdentifierGivenDuplicateIdentifiers.
@Test
public void checkPatientIdentifiers_shouldThrowDuplicateIdentifierGivenDuplicateIdentifiers() throws Exception {
// given
final Integer equalIdentifierTypeId = 12345;
final String equalIdentifierTypeName = "TypeName";
final String equalIdentifier = "Identifier1";
final PatientIdentifierType identifierType = new PatientIdentifierType(equalIdentifierTypeId);
identifierType.setName(equalIdentifierTypeName);
final PatientIdentifierType sameIdentifierType = new PatientIdentifierType(equalIdentifierTypeId);
sameIdentifierType.setName(equalIdentifierTypeName);
when(patientDaoMock.getPatientIdentifierTypes(any(), any(), any(), any())).thenReturn(new ArrayList<>());
final Patient patientWithIdentifiers = new Patient();
final PatientIdentifier patientIdentifier = new PatientIdentifier("some identifier", identifierType, mock(Location.class));
patientIdentifier.setIdentifier(equalIdentifier);
patientWithIdentifiers.addIdentifier(patientIdentifier);
final PatientIdentifier patientIdentifierSameType = new PatientIdentifier("some identifier", sameIdentifierType, mock(Location.class));
patientIdentifierSameType.setIdentifier(equalIdentifier);
patientWithIdentifiers.addIdentifier(patientIdentifierSameType);
// when
try {
patientService.checkPatientIdentifiers(patientWithIdentifiers);
// then
fail();
} catch (DuplicateIdentifierException e) {
assertNotNull(e.getPatientIdentifier());
assertTrue(e.getMessage().contains("Identifier1 id type #: 12345"));
}
}
Aggregations