Skip to content

Commit

Permalink
TRUNK-3944: Created OpenmrsMatchers
Browse files Browse the repository at this point in the history
  • Loading branch information
rkorytkowski committed Mar 28, 2013
1 parent 1171746 commit dd5368c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 18 deletions.
19 changes: 1 addition & 18 deletions api/src/test/java/org/openmrs/api/ConceptServiceTest.java
Expand Up @@ -20,6 +20,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.openmrs.test.OpenmrsMatchers.hasId;
import static org.openmrs.test.TestUtil.containsId;

import java.util.Arrays;
Expand All @@ -35,9 +36,6 @@
import junit.framework.Assert;

import org.apache.commons.collections.CollectionUtils;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
Expand All @@ -63,7 +61,6 @@
import org.openmrs.GlobalProperty;
import org.openmrs.Location;
import org.openmrs.Obs;
import org.openmrs.OpenmrsObject;
import org.openmrs.Patient;
import org.openmrs.Person;
import org.openmrs.User;
Expand Down Expand Up @@ -1372,20 +1369,6 @@ public void getConceptsByConceptSet_shouldReturnAllConceptsInSet() throws Except
assertThat(conceptSet, containsInAnyOrder(hasId(2), hasId(3), hasId(4), hasId(5), hasId(6)));
}

private Matcher<? super OpenmrsObject> hasId(final Integer id) {
return new TypeSafeMatcher<OpenmrsObject>() {

@Override
public void describeTo(Description description) {
}

@Override
protected boolean matchesSafely(OpenmrsObject item) {
return id.equals(item.getId());
}
};
}

/**
* @see {@link ConceptService#saveConceptStopWord(org.openmrs.ConceptStopWord)}
*/
Expand Down
62 changes: 62 additions & 0 deletions api/src/test/java/org/openmrs/test/OpenmrsMatchers.java
@@ -0,0 +1,62 @@
/**
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
package org.openmrs.test;

import static org.hamcrest.Matchers.is;

import org.hamcrest.FeatureMatcher;
import org.hamcrest.Matcher;
import org.openmrs.OpenmrsObject;

/**
* Useful OpenMRS specific matchers.
*
* @since 1.9.4
*/
public class OpenmrsMatchers {

/**
* Matches by id.
*
* @param id
* @return the matcher
*/
public static Matcher<OpenmrsObject> hasId(final Integer id) {
return new FeatureMatcher<OpenmrsObject, Integer>(
is(id), "id", "id") {

@Override
protected Integer featureValueOf(final OpenmrsObject actual) {
return actual.getId();
}
};
}

/**
* Matches by uuid.
*
* @param uuid
* @return the uuid
*/
public static Matcher<OpenmrsObject> hasUuid(final String uuid) {
return new FeatureMatcher<OpenmrsObject, String>(
is(uuid), "uuid", "uuid") {

@Override
protected String featureValueOf(final OpenmrsObject actual) {
return actual.getUuid();
}
};
}
}

0 comments on commit dd5368c

Please sign in to comment.