From 9b94718cab38268d093799405f809b4d04d822ee Mon Sep 17 00:00:00 2001 From: Nick Goupinets Date: Sat, 20 Mar 2021 21:22:21 -0400 Subject: [PATCH] Added ext util test --- .../ca/uhn/fhir/util/ExtensionUtilTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/util/ExtensionUtilTest.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/util/ExtensionUtilTest.java index 8e582852128..b5d7e5053a2 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/util/ExtensionUtilTest.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/util/ExtensionUtilTest.java @@ -2,7 +2,9 @@ package ca.uhn.fhir.util; import ca.uhn.fhir.context.FhirContext; import org.hl7.fhir.instance.model.api.IBaseDatatype; +import org.hl7.fhir.instance.model.api.IBaseExtension; import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.StringType; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; @@ -35,4 +37,40 @@ class ExtensionUtilTest { IBaseDatatype ext = ExtensionUtil.getExtension(p1, EXT_URL).getValue(); assertEquals("1", ext.toString()); } + + @Test + void testAddExtension() { + Patient p = new Patient(); + assertNotNull(ExtensionUtil.addExtension(p)); + assertNotNull(ExtensionUtil.addExtension(p, "myUrl")); + + assertEquals(2, p.getExtension().size()); + assertEquals("myUrl", p.getExtension().get(1).getUrl()); + } + + @Test + void testHasExtension() { + Patient p = new Patient(); + p.addExtension("URL", new StringType("VALUE")); + + assertTrue(ExtensionUtil.hasExtension(p, "URL")); + assertTrue(ExtensionUtil.hasExtension(p, "URL", "VALUE")); + } + + @Test + void testClearExtension() { + Patient p = new Patient(); + p.addExtension("URL", new StringType("VALUE")); + p.addExtension("URL2", new StringType("VALUE2")); + + ExtensionUtil.clearExtensions(p, e -> e.getUrl().equals("URL")); + + assertEquals(1, p.getExtension().size()); + assertFalse(ExtensionUtil.hasExtension(p, "URL")); + assertTrue(ExtensionUtil.hasExtension(p, "URL2")); + + ExtensionUtil.clearExtensions(p); + + assertEquals(0, p.getExtension().size()); + } }