Skip to content

Commit

Permalink
TRUNK-3203 Add JUnit test for getting by patients for method Hibernat…
Browse files Browse the repository at this point in the history
…ePatientDAO.getPatientIdentifiers

TRUNK-3203 Add JUnit test for getting by patients for method HibernatePatientDAO.getPatientIdentifiers review fixes

TRUNK-3203 Add JUnit test for getting by patients for method HibernatePatientDAO.getPatientIdentifiers review fixes

TRUNK-3203 Add JUnit test for getting by patients for method HibernatePatientDAO.getPatientIdentifiers review fixes

TRUNK-3203 Add JUnit test for getting by patients for method HibernatePatientDAO.getPatientIdentifiers review fixes

Add JUnit test for getting by patients for method HibernatePatientDAO.getPatientIdentifiers
  • Loading branch information
akolodziejski authored and rkorytkowski committed Mar 28, 2013
1 parent df3b3b4 commit 79d94c3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
2 changes: 2 additions & 0 deletions api/src/main/java/org/openmrs/api/db/PatientDAO.java
Expand Up @@ -74,6 +74,8 @@ public List<Patient> getPatients(String name, String identifier, List<PatientIde
* @should return all matching non voided patient identifiers if is preferred is set to null
* @should return all matching non voided patient identifiers if is preferred is set to true
* @should return all matching non voided patient identifiers if is preferred is set to false
* @should fetch all patient identifiers belong to given patient
* @should fetch all patient identifiers belong to given patients
*/
public List<PatientIdentifier> getPatientIdentifiers(String identifier,
List<PatientIdentifierType> patientIdentifierTypes, List<Location> locations, List<Patient> patients,
Expand Down
72 changes: 68 additions & 4 deletions api/src/test/java/org/openmrs/api/db/PatientDAOTest.java
@@ -1,5 +1,16 @@
package org.openmrs.api.db;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.is;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.hamcrest.FeatureMatcher;
import org.hamcrest.Matcher;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -10,13 +21,10 @@
import org.openmrs.PersonName;
import org.openmrs.api.PatientService;
import org.openmrs.api.context.Context;
import org.openmrs.api.db.hibernate.HibernatePatientDAO;
import org.openmrs.test.BaseContextSensitiveTest;
import org.openmrs.test.Verifies;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class PatientDAOTest extends BaseContextSensitiveTest {

private PatientDAO dao = null;
Expand Down Expand Up @@ -313,4 +321,60 @@ public void getPatientIdentifiers_shouldReturnAllMatchingNonVoidedPatientIdentif

Assert.assertEquals(2, patientIdentifiers.size());
}

/**
* @see HibernatePatientDAO#getPatientIdentifiers(String,List,List,List,Boolean)
* @verifies fetch all patient identifiers belong to given patient
*/
@Test
public void getPatientIdentifiers_shouldFetchAllPatientIdentifiersBelongToGivenPatient() throws Exception {

//There are two identifiers in the test database for patient with id 2
Patient patientWithId2 = Context.getPatientService().getPatient(2);

List<PatientIdentifier> patientIdentifiers = dao.getPatientIdentifiers(null, new ArrayList<PatientIdentifierType>(),
new ArrayList<Location>(), Collections.singletonList(patientWithId2), null);

assertThat(patientIdentifiers, containsInAnyOrder(hasIdentifier("101"), hasIdentifier("101-6")));
}

/**
* @see HibernatePatientDAO#getPatientIdentifiers(String,List,List,List,Boolean)
* @verifies fetch all patient identifiers belong to given patients
*/
@Test
public void getPatientIdentifiers_shouldFetchAllPatientIdentifiersBelongToGivenPatients() throws Exception {

//There is one identifier[id=12345K] in the test database for patient with id 6
Patient patientWithId6 = Context.getPatientService().getPatient(6);

//There is one identifier[id=6TS-4] in the test database for patient with id 7
Patient patientWithId7 = Context.getPatientService().getPatient(7);

List<Patient> patientsList = Arrays.asList(patientWithId6, patientWithId7);

List<PatientIdentifier> patientIdentifiers = dao.getPatientIdentifiers(null, new ArrayList<PatientIdentifierType>(),
new ArrayList<Location>(), patientsList, null);

assertThat(patientIdentifiers, containsInAnyOrder(hasIdentifier("12345K"), hasIdentifier("6TS-4")));
}

/**
* Matcher for PatientIdentifier class.
*
* @param identifier
* @return getIdentifier value matcher.
*/
private Matcher<PatientIdentifier> hasIdentifier(final String identifier) {

return new FeatureMatcher<PatientIdentifier, String>(
is(identifier), "identifier", "identifier") {

@Override
protected String featureValueOf(PatientIdentifier actual) {
return actual.getIdentifier();
}

};
}
}

0 comments on commit 79d94c3

Please sign in to comment.