fix-matchers-not-contains-in-asserts (#3913)

* test

* replace not(contains())

* make a util class to replace not(hasItems()) and not(containsInAnyOrder())

* replace not(hasItems()) and not(containsInAnyOrder())

* add javadocs to new util class

* test for util class

* Addressing comments from code review.

* Adding static import.

Co-authored-by: Justin_Dar <justin.dar@smilecdr.com>
Co-authored-by: peartree <etienne.poirier@smilecdr.com>
This commit is contained in:
jdar8 2022-09-21 08:54:27 -07:00 committed by GitHub
parent 3349ad8ca9
commit dbe52b429c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 148 additions and 62 deletions

View File

@ -24,6 +24,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -325,7 +326,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test {
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1)); assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), contains(pId1));
map = new SearchParameterMap(); map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEBBB")); map.add(Constants.PARAM_CONTENT, new StringParam("NAMEBBB"));
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), not(contains(pId1))); assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), not(hasItem(pId1)));
myPatientDao.update(patient, null, true, mySrd); myPatientDao.update(patient, null, true, mySrd);

View File

@ -72,6 +72,7 @@ import ca.uhn.fhir.rest.param.TokenOrListParam;
import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.UriParam; import ca.uhn.fhir.rest.param.UriParam;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.test.utilities.CustomMatchersUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
@ -93,6 +94,7 @@ import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsInRelativeOrder; import static org.hamcrest.Matchers.containsInRelativeOrder;
import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@ -852,14 +854,14 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
params.setLastUpdated(new DateRangeParam(beforeR2, null)); params.setLastUpdated(new DateRangeParam(beforeR2, null));
List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, containsInAnyOrder(id2)); assertThat(patients, containsInAnyOrder(id2));
assertThat(patients, not(hasItems(id1a, id1b))); CustomMatchersUtil.assertDoesNotContainAnyOf(patients, List.of(id1a, id1b));
} }
{ {
SearchParameterMap params = new SearchParameterMap(); SearchParameterMap params = new SearchParameterMap();
params.setLoadSynchronous(true); params.setLoadSynchronous(true);
params.setLastUpdated(new DateRangeParam(beforeAny, beforeR2)); params.setLastUpdated(new DateRangeParam(beforeAny, beforeR2));
List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients.toString(), patients, not(hasItems(id2))); assertThat(patients.toString(), patients, not(hasItem(id2)));
assertThat(patients.toString(), patients, (containsInAnyOrder(id1a, id1b))); assertThat(patients.toString(), patients, (containsInAnyOrder(id1a, id1b)));
} }
{ {
@ -868,7 +870,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
params.setLastUpdated(new DateRangeParam(null, beforeR2)); params.setLastUpdated(new DateRangeParam(null, beforeR2));
List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, (containsInAnyOrder(id1a, id1b))); assertThat(patients, (containsInAnyOrder(id1a, id1b)));
assertThat(patients, not(hasItems(id2))); assertThat(patients, not(hasItem(id2)));
} }
} }
@ -1088,7 +1090,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
params.setLoadSynchronous(true); params.setLoadSynchronous(true);
params.add(Patient.SP_FAMILY, new StringDt(name)); params.add(Patient.SP_FAMILY, new StringDt(name));
patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, not(contains(id))); assertThat(patients, not(hasItem(id)));
} }
@ -1438,7 +1440,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test {
IBundleProvider found = myPatientDao.search(params); IBundleProvider found = myPatientDao.search(params);
assertEquals(1, toList(found).size()); assertEquals(1, toList(found).size());
assertThat(toUnqualifiedVersionlessIds(found), contains(longId)); assertThat(toUnqualifiedVersionlessIds(found), contains(longId));
assertThat(toUnqualifiedVersionlessIds(found), not(contains(shortId))); assertThat(toUnqualifiedVersionlessIds(found), not(hasItem(shortId)));
} }

View File

@ -110,6 +110,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import static ca.uhn.fhir.test.utilities.CustomMatchersUtil.*;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInAnyOrder;
@ -119,6 +120,7 @@ import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.emptyString; import static org.hamcrest.Matchers.emptyString;
import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith; import static org.hamcrest.Matchers.startsWith;
@ -2040,7 +2042,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
.execute(); .execute();
List<IdDt> patients = toIdListUnqualifiedVersionless(found); List<IdDt> patients = toIdListUnqualifiedVersionless(found);
assertThat(patients, hasItems(id2)); assertThat(patients, hasItems(id2));
assertThat(patients, not(hasItems(id1a, id1b))); assertDoesNotContainAnyOf(patients, List.of(id1a, id1b));
} }
{ {
Bundle found = ourClient.search() Bundle found = ourClient.search()
@ -2051,7 +2053,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
.execute(); .execute();
List<IdDt> patients = toIdListUnqualifiedVersionless(found); List<IdDt> patients = toIdListUnqualifiedVersionless(found);
assertThat(patients.toString(), patients, not(hasItems(id2))); assertThat(patients.toString(), patients, not(hasItem(id2)));
assertThat(patients.toString(), patients, (hasItems(id1a, id1b))); assertThat(patients.toString(), patients, (hasItems(id1a, id1b)));
} }
{ {
@ -2064,7 +2066,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
List<IdDt> patients = toIdListUnqualifiedVersionless(found); List<IdDt> patients = toIdListUnqualifiedVersionless(found);
assertThat(patients, (hasItems(id1a, id1b))); assertThat(patients, (hasItems(id1a, id1b)));
assertThat(patients, not(hasItems(id2))); assertThat(patients, not(hasItem(id2)));
} }
} }

View File

@ -23,12 +23,16 @@ import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List; import java.util.List;
import static ca.uhn.fhir.test.utilities.CustomMatchersUtil.*;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -418,7 +422,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test {
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(idArray)); assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(idArray));
map = new SearchParameterMap(); map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEBBB")); map.add(Constants.PARAM_CONTENT, new StringParam("NAMEBBB"));
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), not(contains(idArray))); assertDoesNotContainAnyOf(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), Arrays.asList(idArray));
myPatientDao.update(patient, null, true, mockSrd()); myPatientDao.update(patient, null, true, mockSrd());

View File

@ -45,6 +45,7 @@ import ca.uhn.fhir.rest.param.TokenParamModifier;
import ca.uhn.fhir.rest.param.UriParam; import ca.uhn.fhir.rest.param.UriParam;
import ca.uhn.fhir.rest.param.UriParamQualifierEnum; import ca.uhn.fhir.rest.param.UriParamQualifierEnum;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.test.utilities.CustomMatchersUtil;
import ca.uhn.fhir.util.UrlUtil; import ca.uhn.fhir.util.UrlUtil;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -114,6 +115,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import static ca.uhn.fhir.test.utilities.CustomMatchersUtil.*;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInAnyOrder;
@ -1291,13 +1293,13 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
myCaptureQueriesListener.logSelectQueriesForCurrentThread(0); myCaptureQueriesListener.logSelectQueriesForCurrentThread(0);
assertThat(patients, hasItems(id2)); assertThat(patients, hasItems(id2));
assertThat(patients, not(hasItems(id1a, id1b))); assertDoesNotContainAnyOf(patients, List.of(id1a, id1b));
} }
{ {
SearchParameterMap params = new SearchParameterMap(); SearchParameterMap params = new SearchParameterMap();
params.setLastUpdated(new DateRangeParam(beforeAny, beforeR2)); params.setLastUpdated(new DateRangeParam(beforeAny, beforeR2));
List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients.toString(), patients, not(hasItems(id2))); assertThat(patients.toString(), patients, not(hasItem(id2)));
assertThat(patients.toString(), patients, (hasItems(id1a, id1b))); assertThat(patients.toString(), patients, (hasItems(id1a, id1b)));
} }
{ {
@ -1305,7 +1307,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
params.setLastUpdated(new DateRangeParam(null, beforeR2)); params.setLastUpdated(new DateRangeParam(null, beforeR2));
List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, (hasItems(id1a, id1b))); assertThat(patients, (hasItems(id1a, id1b)));
assertThat(patients, not(hasItems(id2))); assertThat(patients, not(hasItem(id2)));
} }
@ -1313,7 +1315,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
SearchParameterMap params = new SearchParameterMap(); SearchParameterMap params = new SearchParameterMap();
params.setLastUpdated(new DateRangeParam(new DateParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, beforeR2))); params.setLastUpdated(new DateRangeParam(new DateParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, beforeR2)));
List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, not(hasItems(id1a, id1b))); CustomMatchersUtil.assertDoesNotContainAnyOf(patients, List.of(id1a, id1b));
assertThat(patients, (hasItems(id2))); assertThat(patients, (hasItems(id2)));
} }
{ {
@ -1321,7 +1323,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
params.setLastUpdated(new DateRangeParam(new DateParam(ParamPrefixEnum.LESSTHAN_OR_EQUALS, beforeR2))); params.setLastUpdated(new DateRangeParam(new DateParam(ParamPrefixEnum.LESSTHAN_OR_EQUALS, beforeR2)));
List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, (hasItems(id1a, id1b))); assertThat(patients, (hasItems(id1a, id1b)));
assertThat(patients, not(hasItems(id2))); assertThat(patients, not(hasItem(id2)));
} }
} }
@ -1558,7 +1560,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
params.setLoadSynchronous(true); params.setLoadSynchronous(true);
params.add(Patient.SP_FAMILY, new StringParam(name)); params.add(Patient.SP_FAMILY, new StringParam(name));
patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, not(contains(id))); assertThat(patients, not(hasItem(id)));
} }
@ -1961,7 +1963,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
params.add(Patient.SP_FAMILY, new StringParam("HELLO")); params.add(Patient.SP_FAMILY, new StringParam("HELLO"));
patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, containsInAnyOrder(pid1)); assertThat(patients, containsInAnyOrder(pid1));
assertThat(patients, not(containsInAnyOrder(pid2))); assertThat(patients, not(hasItem(pid2)));
} }
@Test @Test
@ -2053,7 +2055,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
IBundleProvider found = myPatientDao.search(params); IBundleProvider found = myPatientDao.search(params);
assertEquals(1, toList(found).size()); assertEquals(1, toList(found).size());
assertThat(toUnqualifiedVersionlessIds(found), contains(longId)); assertThat(toUnqualifiedVersionlessIds(found), contains(longId));
assertThat(toUnqualifiedVersionlessIds(found), not(contains(shortId))); assertThat(toUnqualifiedVersionlessIds(found), not(hasItem(shortId)));
} }
@ -3108,7 +3110,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
params.add("_tag", new TokenParam("urn:taglist", methodName + "1a").setModifier(TokenParamModifier.NOT)); params.add("_tag", new TokenParam("urn:taglist", methodName + "1a").setModifier(TokenParamModifier.NOT));
List<IIdType> patients = toUnqualifiedVersionlessIds(myOrganizationDao.search(params)); List<IIdType> patients = toUnqualifiedVersionlessIds(myOrganizationDao.search(params));
assertThat(patients, containsInAnyOrder(tag2id)); assertThat(patients, containsInAnyOrder(tag2id));
assertThat(patients, not(containsInAnyOrder(tag1id))); assertThat(patients, not(hasItem(tag1id)));
} }
{ {
// Non existant tag // Non existant tag

View File

@ -151,6 +151,7 @@ import java.util.TreeSet;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static ca.uhn.fhir.test.utilities.CustomMatchersUtil.assertDoesNotContainAnyOf;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
@ -3173,7 +3174,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
//@formatter:on //@formatter:on
List<IIdType> patients = toUnqualifiedVersionlessIds(found); List<IIdType> patients = toUnqualifiedVersionlessIds(found);
assertThat(patients, hasItems(id2)); assertThat(patients, hasItems(id2));
assertThat(patients, not(hasItems(id1a, id1b))); assertDoesNotContainAnyOf(patients, List.of(id1a, id1b));
} }
{ {
//@formatter:off //@formatter:off
@ -3185,7 +3186,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
.execute(); .execute();
//@formatter:on //@formatter:on
List<IIdType> patients = toUnqualifiedVersionlessIds(found); List<IIdType> patients = toUnqualifiedVersionlessIds(found);
assertThat(patients.toString(), patients, not(hasItems(id2))); assertThat(patients.toString(), patients, not(hasItem(id2)));
assertThat(patients.toString(), patients, (hasItems(id1a, id1b))); assertThat(patients.toString(), patients, (hasItems(id1a, id1b)));
} }
{ {
@ -3199,7 +3200,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
//@formatter:on //@formatter:on
List<IIdType> patients = toUnqualifiedVersionlessIds(found); List<IIdType> patients = toUnqualifiedVersionlessIds(found);
assertThat(patients, (hasItems(id1a, id1b))); assertThat(patients, (hasItems(id1a, id1b)));
assertThat(patients, not(hasItems(id2))); assertThat(patients, not(hasItem(id2)));
} }
} }
@ -3696,7 +3697,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
List<String> ids = toUnqualifiedVersionlessIdValues(bundle); List<String> ids = toUnqualifiedVersionlessIdValues(bundle);
assertThat(ids, contains(oid1)); assertThat(ids, contains(oid1));
assertThat(ids, not(contains(oid2))); assertThat(ids, not(hasItem(oid2)));
} finally { } finally {
IOUtils.closeQuietly(resp); IOUtils.closeQuietly(resp);
} }
@ -3883,7 +3884,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
List<String> ids = toUnqualifiedVersionlessIdValues(bundle); List<String> ids = toUnqualifiedVersionlessIdValues(bundle);
assertThat(ids, contains(id1.getValue())); assertThat(ids, contains(id1.getValue()));
assertThat(ids, not(contains(id2.getValue()))); assertThat(ids, not(hasItem(id2.getValue())));
} finally { } finally {
IOUtils.closeQuietly(resp); IOUtils.closeQuietly(resp);
} }

View File

@ -25,12 +25,15 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List; import java.util.List;
import static ca.uhn.fhir.test.utilities.CustomMatchersUtil.*;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith; import static org.hamcrest.Matchers.startsWith;
import static org.hl7.fhir.r4.model.Observation.SP_VALUE_QUANTITY; import static org.hl7.fhir.r4.model.Observation.SP_VALUE_QUANTITY;
@ -432,7 +435,7 @@ public class FhirResourceDaoR4SearchFtTest extends BaseJpaR4Test {
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(pidTypeArray)); assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(pidTypeArray));
map = new SearchParameterMap(); map = new SearchParameterMap();
map.add(Constants.PARAM_CONTENT, new StringParam("NAMEBBB")); map.add(Constants.PARAM_CONTENT, new StringParam("NAMEBBB"));
assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), not(contains(pidTypeArray))); assertDoesNotContainAnyOf(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), Arrays.asList(pidTypeArray));
myPatientDao.update(patient, null, true, mockSrd()); myPatientDao.update(patient, null, true, mockSrd());

View File

@ -173,6 +173,7 @@ import static ca.uhn.fhir.rest.param.ParamPrefixEnum.GREATERTHAN_OR_EQUALS;
import static ca.uhn.fhir.rest.param.ParamPrefixEnum.LESSTHAN; import static ca.uhn.fhir.rest.param.ParamPrefixEnum.LESSTHAN;
import static ca.uhn.fhir.rest.param.ParamPrefixEnum.LESSTHAN_OR_EQUALS; import static ca.uhn.fhir.rest.param.ParamPrefixEnum.LESSTHAN_OR_EQUALS;
import static ca.uhn.fhir.rest.param.ParamPrefixEnum.NOT_EQUAL; import static ca.uhn.fhir.rest.param.ParamPrefixEnum.NOT_EQUAL;
import static ca.uhn.fhir.test.utilities.CustomMatchersUtil.*;
import static org.apache.commons.lang3.StringUtils.countMatches; import static org.apache.commons.lang3.StringUtils.countMatches;
import static org.apache.commons.lang3.StringUtils.leftPad; import static org.apache.commons.lang3.StringUtils.leftPad;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
@ -2652,24 +2653,23 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
result = performSearchLastUpdatedAndReturnIds(new DateRangeParam(beforeR2, null)); result = performSearchLastUpdatedAndReturnIds(new DateRangeParam(beforeR2, null));
assertThat(result, hasItems(id2)); assertThat(result, hasItems(id2));
assertThat(result, not(hasItems(id1a, id1b))); assertDoesNotContainAnyOf(result, List.of(id1a, id1b));
result = performSearchLastUpdatedAndReturnIds(new DateRangeParam(beforeAny, beforeR2)); result = performSearchLastUpdatedAndReturnIds(new DateRangeParam(beforeAny, beforeR2));
assertThat(result.toString(), result, not(hasItems(id2))); assertThat(result.toString(), result, not(hasItem(id2)));
assertThat(result.toString(), result, (hasItems(id1a, id1b))); assertThat(result.toString(), result, (hasItems(id1a, id1b)));
result = performSearchLastUpdatedAndReturnIds(new DateRangeParam(null, beforeR2)); result = performSearchLastUpdatedAndReturnIds(new DateRangeParam(null, beforeR2));
assertThat(result, (hasItems(id1a, id1b))); assertThat(result, (hasItems(id1a, id1b)));
assertThat(result, not(hasItems(id2))); assertThat(result, not(hasItem(id2)));
result = performSearchLastUpdatedAndReturnIds(new DateRangeParam(new DateParam(GREATERTHAN_OR_EQUALS, beforeR2))); result = performSearchLastUpdatedAndReturnIds(new DateRangeParam(new DateParam(GREATERTHAN_OR_EQUALS, beforeR2)));
assertThat(result, not(hasItems(id1a, id1b))); assertDoesNotContainAnyOf(result, List.of(id1a, id1b));
assertThat(result, (hasItems(id2))); assertThat(result, (hasItems(id2)));
result = performSearchLastUpdatedAndReturnIds(new DateRangeParam(new DateParam(LESSTHAN_OR_EQUALS, beforeR2))); result = performSearchLastUpdatedAndReturnIds(new DateRangeParam(new DateParam(LESSTHAN_OR_EQUALS, beforeR2)));
assertThat(result, (hasItems(id1a, id1b))); assertThat(result, (hasItems(id1a, id1b)));
assertThat(result, not(hasItems(id2))); assertThat(result, not(hasItem(id2)));
} }
@Test @Test
@ -2741,7 +2741,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
dateRange = new DateRangeParam(new DateParam(EQUAL, p0LastUpdated), new DateParam(EQUAL, p0LastUpdated)); dateRange = new DateRangeParam(new DateParam(EQUAL, p0LastUpdated), new DateParam(EQUAL, p0LastUpdated));
result = performSearchLastUpdatedAndReturnIds(dateRange); result = performSearchLastUpdatedAndReturnIds(dateRange);
assertThat(result, containsInAnyOrder(id0)); assertThat(result, containsInAnyOrder(id0));
assertThat(result, not(containsInAnyOrder(id1a, id1b))); assertDoesNotContainAnyOf(result, List.of(id1a, id1b));
DateTimeType p0LastUpdatedDay = new DateTimeType(p0LastUpdated.getValue(), TemporalPrecisionEnum.DAY); DateTimeType p0LastUpdatedDay = new DateTimeType(p0LastUpdated.getValue(), TemporalPrecisionEnum.DAY);
dateRange = new DateRangeParam(new DateParam(EQUAL, p0LastUpdatedDay), new DateParam(EQUAL, p0LastUpdatedDay)); dateRange = new DateRangeParam(new DateParam(EQUAL, p0LastUpdatedDay), new DateParam(EQUAL, p0LastUpdatedDay));
@ -2751,7 +2751,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
dateRange = new DateRangeParam(new DateParam(NOT_EQUAL, p0LastUpdated), new DateParam(NOT_EQUAL, p0LastUpdated)); dateRange = new DateRangeParam(new DateParam(NOT_EQUAL, p0LastUpdated), new DateParam(NOT_EQUAL, p0LastUpdated));
result = performSearchLastUpdatedAndReturnIds(dateRange); result = performSearchLastUpdatedAndReturnIds(dateRange);
assertThat(result, containsInAnyOrder(id1a, id1b)); assertThat(result, containsInAnyOrder(id1a, id1b));
assertThat(result, not(containsInAnyOrder(id0))); assertThat(result, not(hasItem(id0)));
dateRange = new DateRangeParam(new DateParam(NOT_EQUAL, p0LastUpdatedDay), new DateParam(NOT_EQUAL, p0LastUpdatedDay)); dateRange = new DateRangeParam(new DateParam(NOT_EQUAL, p0LastUpdatedDay), new DateParam(NOT_EQUAL, p0LastUpdatedDay));
result = performSearchLastUpdatedAndReturnIds(dateRange); result = performSearchLastUpdatedAndReturnIds(dateRange);
@ -3077,7 +3077,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
params.setLoadSynchronous(true); params.setLoadSynchronous(true);
params.add(Patient.SP_FAMILY, new StringParam(name)); params.add(Patient.SP_FAMILY, new StringParam(name));
patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, not(contains(id))); assertThat(patients, not(hasItem(id)));
} }
@ -3594,7 +3594,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
params.add(Patient.SP_FAMILY, new StringParam("HELLO")); params.add(Patient.SP_FAMILY, new StringParam("HELLO"));
patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, containsInAnyOrder(pid1)); assertThat(patients, containsInAnyOrder(pid1));
assertThat(patients, not(containsInAnyOrder(pid2))); assertThat(patients, not(hasItem(pid2)));
} }
@Test @Test
@ -3626,7 +3626,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
IBundleProvider found = myPatientDao.search(params); IBundleProvider found = myPatientDao.search(params);
assertEquals(1, toList(found).size()); assertEquals(1, toList(found).size());
assertThat(toUnqualifiedVersionlessIds(found), contains(longId)); assertThat(toUnqualifiedVersionlessIds(found), contains(longId));
assertThat(toUnqualifiedVersionlessIds(found), not(contains(shortId))); assertThat(toUnqualifiedVersionlessIds(found), not(hasItem(shortId)));
} }
@ -5033,7 +5033,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
List<IIdType> patients = toUnqualifiedVersionlessIds(myOrganizationDao.search(params)); List<IIdType> patients = toUnqualifiedVersionlessIds(myOrganizationDao.search(params));
myCaptureQueriesListener.logSelectQueriesForCurrentThread(0); myCaptureQueriesListener.logSelectQueriesForCurrentThread(0);
assertThat(patients, containsInAnyOrder(tag2id)); assertThat(patients, containsInAnyOrder(tag2id));
assertThat(patients, not(containsInAnyOrder(tag1id))); assertThat(patients, not(hasItem(tag1id)));
} }
{ {
// Non existant tag // Non existant tag

View File

@ -120,6 +120,7 @@ import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static ca.uhn.fhir.test.utilities.CustomMatchersUtil.*;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInAnyOrder;
@ -1485,13 +1486,13 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test {
params.setLastUpdated(new DateRangeParam(beforeR2, null)); params.setLastUpdated(new DateRangeParam(beforeR2, null));
List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, hasItems(id2)); assertThat(patients, hasItems(id2));
assertThat(patients, not(hasItems(id1a, id1b))); assertDoesNotContainAnyOf(patients, List.of(id1a, id1b));
} }
{ {
SearchParameterMap params = new SearchParameterMap(); SearchParameterMap params = new SearchParameterMap();
params.setLastUpdated(new DateRangeParam(beforeAny, beforeR2)); params.setLastUpdated(new DateRangeParam(beforeAny, beforeR2));
List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients.toString(), patients, not(hasItems(id2))); assertThat(patients.toString(), patients, not(hasItem(id2)));
assertThat(patients.toString(), patients, (hasItems(id1a, id1b))); assertThat(patients.toString(), patients, (hasItems(id1a, id1b)));
} }
{ {
@ -1499,7 +1500,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test {
params.setLastUpdated(new DateRangeParam(null, beforeR2)); params.setLastUpdated(new DateRangeParam(null, beforeR2));
List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, (hasItems(id1a, id1b))); assertThat(patients, (hasItems(id1a, id1b)));
assertThat(patients, not(hasItems(id2))); assertThat(patients, not(hasItem(id2)));
} }
@ -1507,7 +1508,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test {
SearchParameterMap params = new SearchParameterMap(); SearchParameterMap params = new SearchParameterMap();
params.setLastUpdated(new DateRangeParam(new DateParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, beforeR2))); params.setLastUpdated(new DateRangeParam(new DateParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, beforeR2)));
List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, not(hasItems(id1a, id1b))); assertDoesNotContainAnyOf(patients, List.of(id1a, id1b));
assertThat(patients, (hasItems(id2))); assertThat(patients, (hasItems(id2)));
} }
{ {
@ -1515,7 +1516,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test {
params.setLastUpdated(new DateRangeParam(new DateParam(ParamPrefixEnum.LESSTHAN_OR_EQUALS, beforeR2))); params.setLastUpdated(new DateRangeParam(new DateParam(ParamPrefixEnum.LESSTHAN_OR_EQUALS, beforeR2)));
List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); List<IIdType> patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, (hasItems(id1a, id1b))); assertThat(patients, (hasItems(id1a, id1b)));
assertThat(patients, not(hasItems(id2))); assertThat(patients, not(hasItem(id2)));
} }
} }
@ -1758,7 +1759,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test {
params.setLoadSynchronous(true); params.setLoadSynchronous(true);
params.add(Patient.SP_FAMILY, new StringParam(name)); params.add(Patient.SP_FAMILY, new StringParam(name));
patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, not(contains(id))); assertThat(patients, not(hasItem(id)));
} }
@ -2153,7 +2154,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test {
params.add(Patient.SP_FAMILY, new StringParam("HELLO")); params.add(Patient.SP_FAMILY, new StringParam("HELLO"));
patients = toUnqualifiedVersionlessIds(myPatientDao.search(params)); patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
assertThat(patients, containsInAnyOrder(pid1)); assertThat(patients, containsInAnyOrder(pid1));
assertThat(patients, not(containsInAnyOrder(pid2))); assertThat(patients, not(hasItem(pid2)));
} }
@Test @Test
@ -2185,7 +2186,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test {
IBundleProvider found = myPatientDao.search(params); IBundleProvider found = myPatientDao.search(params);
assertEquals(1, toList(found).size()); assertEquals(1, toList(found).size());
assertThat(toUnqualifiedVersionlessIds(found), contains(longId)); assertThat(toUnqualifiedVersionlessIds(found), contains(longId));
assertThat(toUnqualifiedVersionlessIds(found), not(contains(shortId))); assertThat(toUnqualifiedVersionlessIds(found), not(hasItem(shortId)));
} }
@ -3149,7 +3150,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test {
params.add("_tag", new TokenParam("urn:taglist", methodName + "1a").setModifier(TokenParamModifier.NOT)); params.add("_tag", new TokenParam("urn:taglist", methodName + "1a").setModifier(TokenParamModifier.NOT));
List<IIdType> patients = toUnqualifiedVersionlessIds(myOrganizationDao.search(params)); List<IIdType> patients = toUnqualifiedVersionlessIds(myOrganizationDao.search(params));
assertThat(patients, containsInAnyOrder(tag2id)); assertThat(patients, containsInAnyOrder(tag2id));
assertThat(patients, not(containsInAnyOrder(tag1id))); assertThat(patients, not(hasItem(tag1id)));
} }
{ {
// Non existant tag // Non existant tag

View File

@ -162,7 +162,6 @@ import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate; import org.springframework.transaction.support.TransactionTemplate;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.sql.DataSource;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -186,6 +185,7 @@ import java.util.stream.Stream;
import static ca.uhn.fhir.jpa.config.r4.FhirContextR4Config.DEFAULT_PRESERVE_VERSION_REFS; import static ca.uhn.fhir.jpa.config.r4.FhirContextR4Config.DEFAULT_PRESERVE_VERSION_REFS;
import static ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick; import static ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick;
import static ca.uhn.fhir.rest.param.BaseParamWithPrefix.MSG_PREFIX_INVALID_FORMAT; import static ca.uhn.fhir.rest.param.BaseParamWithPrefix.MSG_PREFIX_INVALID_FORMAT;
import static ca.uhn.fhir.test.utilities.CustomMatchersUtil.assertDoesNotContainAnyOf;
import static ca.uhn.fhir.util.TestUtil.sleepAtLeast; import static ca.uhn.fhir.util.TestUtil.sleepAtLeast;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
@ -2282,8 +2282,8 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
assertThat(ids, containsInAnyOrder(o1Id, p1Id, c1Id)); assertThat(ids, containsInAnyOrder(o1Id, p1Id, c1Id));
assertThat(ids, not((o2Id))); assertThat(ids, not((o2Id)));
assertThat(ids, not(contains(c2Id))); assertThat(ids, not(hasItem(c2Id)));
assertThat(ids, not(contains(p2Id))); assertThat(ids, not(hasItem(p2Id)));
} }
{ {
@ -2315,7 +2315,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
List<IIdType> ids = toUnqualifiedVersionlessIds(b); List<IIdType> ids = toUnqualifiedVersionlessIds(b);
assertThat(ids, containsInAnyOrder(o1Id, p1Id, c1Id, o2Id, c2Id, p2Id)); assertThat(ids, containsInAnyOrder(o1Id, p1Id, c1Id, o2Id, c2Id, p2Id));
assertThat(ids, not(contains(c5Id))); assertThat(ids, not(hasItem(c5Id)));
} }
{ {
@ -2333,7 +2333,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
List<IIdType> ids = toUnqualifiedVersionlessIds(b); List<IIdType> ids = toUnqualifiedVersionlessIds(b);
assertThat(ids, containsInAnyOrder(o1Id, p1Id, c1Id, o2Id, c2Id, p2Id, p3Id, o3Id, c3Id, p4Id, c4Id, o4Id)); assertThat(ids, containsInAnyOrder(o1Id, p1Id, c1Id, o2Id, c2Id, p2Id, p3Id, o3Id, c3Id, p4Id, c4Id, o4Id));
assertThat(ids, not(contains(c5Id))); assertThat(ids, not(hasItem(c5Id)));
} }
{ {
@ -2361,9 +2361,26 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
allresults.addAll(secondBundle); allresults.addAll(secondBundle);
assertThat(allresults, containsInAnyOrder(o1Id, p1Id, c1Id, o2Id, c2Id, p2Id, p3Id, o3Id, c3Id, p4Id, c4Id, o4Id)); assertThat(allresults, containsInAnyOrder(o1Id, p1Id, c1Id, o2Id, c2Id, p2Id, p3Id, o3Id, c3Id, p4Id, c4Id, o4Id));
assertThat(allresults, not(contains(c5Id))); assertThat(allresults, not(hasItem(c5Id)));
} }
} }
@Test
public void testContains(){
List<String> test = List.of("a", "b", "c");
String testString = "testAString";
//examined iterable must be of the same length as the specified collection of matchers
assertThat(test, not(contains("b"))); //replace with not(hasItem())
//examined Iterable yield at least one item that is matched
//it can contain "a", but it doesn't contain "d" so this passes
//really does "do not have one of these"
assertThat(test, not(hasItems("a", "d"))); //replace with individual calls to not(hasItem())
//MatchersUtil.assertDoesNotContainAnyOf(test, List.of("a", "d"));
//examined iterable must be of the same length as the specified collection of matchers
assertThat(test, not(containsInAnyOrder("a", "b"))); //replace with indiv calls to not(hasItem())
}
@Test @Test
public void testEverythingPatientInstanceWithTypeParameter() { public void testEverythingPatientInstanceWithTypeParameter() {
@ -2503,7 +2520,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
assertEquals(BundleType.SEARCHSET, b.getType()); assertEquals(BundleType.SEARCHSET, b.getType());
List<IIdType> ids = toUnqualifiedVersionlessIds(b); List<IIdType> ids = toUnqualifiedVersionlessIds(b);
assertThat(ids, containsInAnyOrder(o1Id, pabcId, c1Id, pdefId, o2Id, c2Id)); assertThat(ids, containsInAnyOrder(o1Id, pabcId, c1Id, pdefId, o2Id, c2Id));
assertThat(ids, not(contains(c3Id))); assertThat(ids, not(hasItem(c3Id)));
} }
@ -4579,7 +4596,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
//@formatter:on //@formatter:on
List<IIdType> patients = toUnqualifiedVersionlessIds(found); List<IIdType> patients = toUnqualifiedVersionlessIds(found);
assertThat(patients, hasItems(id2)); assertThat(patients, hasItems(id2));
assertThat(patients, not(hasItems(id1a, id1b))); assertDoesNotContainAnyOf(patients, List.of(id1a, id1b));
} }
{ {
//@formatter:off //@formatter:off
@ -4591,7 +4608,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
.execute(); .execute();
//@formatter:on //@formatter:on
List<IIdType> patients = toUnqualifiedVersionlessIds(found); List<IIdType> patients = toUnqualifiedVersionlessIds(found);
assertThat(patients.toString(), patients, not(hasItems(id2))); assertThat(patients.toString(), patients, not(hasItem(id2)));
assertThat(patients.toString(), patients, (hasItems(id1a, id1b))); assertThat(patients.toString(), patients, (hasItems(id1a, id1b)));
} }
{ {
@ -4605,7 +4622,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
//@formatter:on //@formatter:on
List<IIdType> patients = toUnqualifiedVersionlessIds(found); List<IIdType> patients = toUnqualifiedVersionlessIds(found);
assertThat(patients, (hasItems(id1a, id1b))); assertThat(patients, (hasItems(id1a, id1b)));
assertThat(patients, not(hasItems(id2))); assertThat(patients, not(hasItem(id2)));
} }
} }
@ -4649,7 +4666,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
List<String> ids = toUnqualifiedVersionlessIdValues(bundle); List<String> ids = toUnqualifiedVersionlessIdValues(bundle);
assertThat(ids, contains(oid1)); assertThat(ids, contains(oid1));
assertThat(ids, not(contains(oid2))); assertThat(ids, not(hasItem(oid2)));
} }
} }
@ -5754,7 +5771,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
List<String> ids = toUnqualifiedVersionlessIdValues(bundle); List<String> ids = toUnqualifiedVersionlessIdValues(bundle);
assertThat(ids, contains(id1.getValue())); assertThat(ids, contains(id1.getValue()));
assertThat(ids, not(contains(id2.getValue()))); assertThat(ids, not(hasItem(id2.getValue())));
} }
} }

View File

@ -10,6 +10,7 @@ import java.util.function.Supplier;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.core.IsNot.not; import static org.hamcrest.core.IsNot.not;
@ -33,7 +34,7 @@ public class DropTableTest extends BaseTest {
getMigrator().migrate(); getMigrator().migrate();
assertThat(JdbcUtils.getTableNames(getConnectionProperties()), not(hasItems("SOMETABLE"))); assertThat(JdbcUtils.getTableNames(getConnectionProperties()), not(hasItem("SOMETABLE")));
} }
@ParameterizedTest(name = "{index}: {0}") @ParameterizedTest(name = "{index}: {0}")
@ -53,7 +54,7 @@ public class DropTableTest extends BaseTest {
getMigrator().migrate(); getMigrator().migrate();
assertThat(JdbcUtils.getTableNames(getConnectionProperties()), not(hasItems("SOMETABLE"))); assertThat(JdbcUtils.getTableNames(getConnectionProperties()), not(hasItem("SOMETABLE")));
} }
@ParameterizedTest(name = "{index}: {0}") @ParameterizedTest(name = "{index}: {0}")
@ -67,7 +68,7 @@ public class DropTableTest extends BaseTest {
getMigrator().migrate(); getMigrator().migrate();
assertThat(JdbcUtils.getTableNames(getConnectionProperties()), not(hasItems("SOMETABLE"))); assertThat(JdbcUtils.getTableNames(getConnectionProperties()), not(hasItem("SOMETABLE")));
} }
@ParameterizedTest(name = "{index}: {0}") @ParameterizedTest(name = "{index}: {0}")
@ -87,7 +88,7 @@ public class DropTableTest extends BaseTest {
getMigrator().migrate(); getMigrator().migrate();
assertThat(getMigrator().getMigrationInfo().get().pending().length, equalTo(0)); assertThat(getMigrator().getMigrationInfo().get().pending().length, equalTo(0));
assertThat(JdbcUtils.getTableNames(getConnectionProperties()), not(hasItems("SOMETABLE"))); assertThat(JdbcUtils.getTableNames(getConnectionProperties()), not(hasItem("SOMETABLE")));
} }

View File

@ -0,0 +1,21 @@
package ca.uhn.fhir.test.utilities;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.not;
public class CustomMatchersUtil {
/**
* Asserts that none of the items in theShouldNotContain are in theActual
* @param theActual the actual results
* @param theShouldNotContain the items that should not be in theActual
*/
public static <T> void assertDoesNotContainAnyOf(List<T> theActual, List<T> theShouldNotContain) {
for (T item : theShouldNotContain) {
assertThat(theActual, not(hasItem(item)));
}
}
}

View File

@ -0,0 +1,31 @@
package ca.uhn.fhir.test.utilities;
import org.junit.jupiter.api.Test;
import java.util.List;
import static ca.uhn.fhir.test.utilities.CustomMatchersUtil.assertDoesNotContainAnyOf;
import static org.junit.jupiter.api.Assertions.assertThrows;
class CustomMatchersUtilTest {
private List<String> data = List.of("A", "B", "C");
@Test
public void testAssertDoesNotContainAllOf_withItemsNotInData() {
assertDoesNotContainAnyOf(data, List.of("D", "E"));
}
@Test
public void testAssertDoesNotContainAllOf_withItemsInData() {
assertThrows(AssertionError.class, () -> {
assertDoesNotContainAnyOf(data, List.of("A", "B"));
});
}
@Test
public void testAssertDoesNotContainAllOf_withSomeItemsInData() {
assertThrows(AssertionError.class, () -> {
assertDoesNotContainAnyOf(data, List.of("A", "E"));
});
}
}