Skip to content

Commit dd5368c

Browse files
committedMar 28, 2013
TRUNK-3944: Created OpenmrsMatchers
1 parent 1171746 commit dd5368c

File tree

2 files changed

+63
-18
lines changed

2 files changed

+63
-18
lines changed
 

‎api/src/test/java/org/openmrs/api/ConceptServiceTest.java

+1-18
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.junit.Assert.assertNull;
2121
import static org.junit.Assert.assertThat;
2222
import static org.junit.Assert.assertTrue;
23+
import static org.openmrs.test.OpenmrsMatchers.hasId;
2324
import static org.openmrs.test.TestUtil.containsId;
2425

2526
import java.util.Arrays;
@@ -35,9 +36,6 @@
3536
import junit.framework.Assert;
3637

3738
import org.apache.commons.collections.CollectionUtils;
38-
import org.hamcrest.Description;
39-
import org.hamcrest.Matcher;
40-
import org.hamcrest.TypeSafeMatcher;
4139
import org.junit.Before;
4240
import org.junit.Ignore;
4341
import org.junit.Test;
@@ -63,7 +61,6 @@
6361
import org.openmrs.GlobalProperty;
6462
import org.openmrs.Location;
6563
import org.openmrs.Obs;
66-
import org.openmrs.OpenmrsObject;
6764
import org.openmrs.Patient;
6865
import org.openmrs.Person;
6966
import org.openmrs.User;
@@ -1372,20 +1369,6 @@ public void getConceptsByConceptSet_shouldReturnAllConceptsInSet() throws Except
13721369
assertThat(conceptSet, containsInAnyOrder(hasId(2), hasId(3), hasId(4), hasId(5), hasId(6)));
13731370
}
13741371

1375-
private Matcher<? super OpenmrsObject> hasId(final Integer id) {
1376-
return new TypeSafeMatcher<OpenmrsObject>() {
1377-
1378-
@Override
1379-
public void describeTo(Description description) {
1380-
}
1381-
1382-
@Override
1383-
protected boolean matchesSafely(OpenmrsObject item) {
1384-
return id.equals(item.getId());
1385-
}
1386-
};
1387-
}
1388-
13891372
/**
13901373
* @see {@link ConceptService#saveConceptStopWord(org.openmrs.ConceptStopWord)}
13911374
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* The contents of this file are subject to the OpenMRS Public License
3+
* Version 1.0 (the "License"); you may not use this file except in
4+
* compliance with the License. You may obtain a copy of the License at
5+
* http://license.openmrs.org
6+
*
7+
* Software distributed under the License is distributed on an "AS IS"
8+
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
9+
* License for the specific language governing rights and limitations
10+
* under the License.
11+
*
12+
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
13+
*/
14+
package org.openmrs.test;
15+
16+
import static org.hamcrest.Matchers.is;
17+
18+
import org.hamcrest.FeatureMatcher;
19+
import org.hamcrest.Matcher;
20+
import org.openmrs.OpenmrsObject;
21+
22+
/**
23+
* Useful OpenMRS specific matchers.
24+
*
25+
* @since 1.9.4
26+
*/
27+
public class OpenmrsMatchers {
28+
29+
/**
30+
* Matches by id.
31+
*
32+
* @param id
33+
* @return the matcher
34+
*/
35+
public static Matcher<OpenmrsObject> hasId(final Integer id) {
36+
return new FeatureMatcher<OpenmrsObject, Integer>(
37+
is(id), "id", "id") {
38+
39+
@Override
40+
protected Integer featureValueOf(final OpenmrsObject actual) {
41+
return actual.getId();
42+
}
43+
};
44+
}
45+
46+
/**
47+
* Matches by uuid.
48+
*
49+
* @param uuid
50+
* @return the uuid
51+
*/
52+
public static Matcher<OpenmrsObject> hasUuid(final String uuid) {
53+
return new FeatureMatcher<OpenmrsObject, String>(
54+
is(uuid), "uuid", "uuid") {
55+
56+
@Override
57+
protected String featureValueOf(final OpenmrsObject actual) {
58+
return actual.getUuid();
59+
}
60+
};
61+
}
62+
}

0 commit comments

Comments
 (0)
Please sign in to comment.