|
13 | 13 | */
|
14 | 14 | package org.openmrs.api;
|
15 | 15 |
|
| 16 | +import static org.hamcrest.Matchers.equalTo; |
| 17 | +import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; |
| 18 | +import static org.hamcrest.core.Is.is; |
| 19 | +import static org.junit.Assert.assertEquals; |
| 20 | +import static org.junit.Assert.assertFalse; |
| 21 | +import static org.junit.Assert.assertNotNull; |
| 22 | +import static org.junit.Assert.assertNull; |
| 23 | +import static org.junit.Assert.assertThat; |
| 24 | +import static org.junit.Assert.assertTrue; |
| 25 | +import static org.junit.Assert.fail; |
| 26 | +import static org.openmrs.test.TestUtil.assertCollectionContentsEquals; |
| 27 | +import static org.openmrs.util.AddressMatcher.containsAddress; |
| 28 | +import static org.openmrs.util.NameMatcher.containsFullName; |
| 29 | + |
| 30 | +import java.util.ArrayList; |
| 31 | +import java.util.Arrays; |
| 32 | +import java.util.Calendar; |
| 33 | +import java.util.Collection; |
| 34 | +import java.util.Collections; |
| 35 | +import java.util.Date; |
| 36 | +import java.util.GregorianCalendar; |
| 37 | +import java.util.HashSet; |
| 38 | +import java.util.LinkedHashSet; |
| 39 | +import java.util.List; |
| 40 | +import java.util.Set; |
| 41 | +import java.util.Vector; |
| 42 | + |
| 43 | +import javax.validation.ValidationException; |
| 44 | + |
16 | 45 | import org.apache.commons.collections.CollectionUtils;
|
17 | 46 | import org.apache.commons.logging.Log;
|
18 | 47 | import org.apache.commons.logging.LogFactory;
|
|
55 | 84 | import org.openmrs.util.OpenmrsConstants;
|
56 | 85 | import org.openmrs.util.OpenmrsUtil;
|
57 | 86 |
|
58 |
| -import java.util.ArrayList; |
59 |
| -import java.util.Arrays; |
60 |
| -import java.util.Calendar; |
61 |
| -import java.util.Collection; |
62 |
| -import java.util.Collections; |
63 |
| -import java.util.Date; |
64 |
| -import java.util.GregorianCalendar; |
65 |
| -import java.util.HashSet; |
66 |
| -import java.util.LinkedHashSet; |
67 |
| -import java.util.List; |
68 |
| -import java.util.Set; |
69 |
| -import java.util.Vector; |
70 |
| - |
71 |
| -import static org.hamcrest.Matchers.equalTo; |
72 |
| -import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; |
73 |
| -import static org.hamcrest.core.Is.is; |
74 |
| -import static org.junit.Assert.assertEquals; |
75 |
| -import static org.junit.Assert.assertFalse; |
76 |
| -import static org.junit.Assert.assertNotNull; |
77 |
| -import static org.junit.Assert.assertNull; |
78 |
| -import static org.junit.Assert.assertThat; |
79 |
| -import static org.junit.Assert.assertTrue; |
80 |
| -import static org.junit.Assert.fail; |
81 |
| -import static org.openmrs.test.TestUtil.assertCollectionContentsEquals; |
82 |
| -import static org.openmrs.util.AddressMatcher.containsAddress; |
83 |
| -import static org.openmrs.util.NameMatcher.containsFullName; |
84 |
| - |
85 | 87 | /**
|
86 | 88 | * This class tests methods in the PatientService class TODO Add methods to test all methods in
|
87 | 89 | * PatientService class
|
@@ -3220,4 +3222,27 @@ public void getCountOfPatients_shouldReturnTheRightCountOfPatientsWithAMatchingI
|
3220 | 3222 | Assert.assertEquals(1, patientService.getCountOfPatients(identifier).intValue());
|
3221 | 3223 | }
|
3222 | 3224 |
|
| 3225 | + /** |
| 3226 | + * @see {@link PatientService#savePatientIdentifier(PatientIdentifier)} |
| 3227 | + */ |
| 3228 | + @Test |
| 3229 | + @Verifies(value = "should pass if patient identifer type's location behaviour is NOT_USED and location is null", method = "savePatientIdentifier(PatientIdentifierType)") |
| 3230 | + public void savePatientIdentifier_shouldAllowLocationToBeNullWhenLocationBehaviourIsNotUsed() { |
| 3231 | + PatientIdentifier patientIdentifier = patientService.getPatientIdentifier(7); |
| 3232 | + patientIdentifier.setLocation(null); |
| 3233 | + patientIdentifier.getIdentifierType().setLocationBehavior(PatientIdentifierType.LocationBehavior.NOT_USED); |
| 3234 | + patientService.savePatientIdentifier(patientIdentifier); |
| 3235 | + } |
| 3236 | + |
| 3237 | + /** |
| 3238 | + * @see {@link PatientService#savePatientIdentifier(PatientIdentifier)} |
| 3239 | + */ |
| 3240 | + @Test(expected = APIException.class) |
| 3241 | + @Verifies(value = "should fail if patient identifer type's location behaviour is REQUIRED and location is null", method = "savePatientIdentifier(PatientIdentifierType)") |
| 3242 | + public void savePatientIdentifier_shouldAllowLocationToBeNullWhenLocationBehaviourIsRequired() { |
| 3243 | + PatientIdentifier patientIdentifier = patientService.getPatientIdentifier(7); |
| 3244 | + patientIdentifier.setLocation(null); |
| 3245 | + patientIdentifier.getIdentifierType().setLocationBehavior(PatientIdentifierType.LocationBehavior.REQUIRED); |
| 3246 | + patientService.savePatientIdentifier(patientIdentifier); |
| 3247 | + } |
3223 | 3248 | }
|
0 commit comments