From 9171c39d590b90498ecce1dcdd9d575c053b12c9 Mon Sep 17 00:00:00 2001 From: Paul Robson Date: Wed, 22 Dec 2021 11:53:24 -0500 Subject: [PATCH] refactor: extract private helper methods --- .../terminologies/ConceptMapEngineTest.java | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/terminologies/ConceptMapEngineTest.java b/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/terminologies/ConceptMapEngineTest.java index c428d3b0b..bea524f3a 100644 --- a/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/terminologies/ConceptMapEngineTest.java +++ b/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/terminologies/ConceptMapEngineTest.java @@ -4,6 +4,7 @@ import org.hl7.fhir.r4.context.SimpleWorkerContext; import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.ConceptMap; import org.hl7.fhir.r4.model.Enumerations; +import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Test; import java.io.IOException; @@ -14,33 +15,43 @@ import static org.junit.jupiter.api.Assertions.assertEquals; class ConceptMapEngineTest { private static final String CONCEPT_MAP_URL = "https://test-fhir.com/ConceptMap/fake"; + public static final String SOURCE_CODE_STRING = "body-weight"; + public static final String TARGET_CODE_STRING = "vital-signs"; @Test void translate() throws IOException { + ConceptMap conceptMap = getConceptMap(); + ConceptMapEngine conceptMapEngine = getConceptMapEngine(conceptMap); + Coding coding = new Coding(null, SOURCE_CODE_STRING, "Body Weight"); + + Coding actual = conceptMapEngine.translate(coding, CONCEPT_MAP_URL); + + assertEquals(TARGET_CODE_STRING, actual.getCode()); + } + + @NotNull + private ConceptMapEngine getConceptMapEngine(ConceptMap conceptMap) throws IOException { + SimpleWorkerContext simpleWorkerContext = new SimpleWorkerContext(); + simpleWorkerContext.cacheResource(conceptMap); + + return new ConceptMapEngine(simpleWorkerContext); + } + + @NotNull + private ConceptMap getConceptMap() { ConceptMap.TargetElementComponent targetElementComponent = new ConceptMap.TargetElementComponent(); - targetElementComponent.setCode("vital-signs"); + targetElementComponent.setCode(TARGET_CODE_STRING); targetElementComponent.setEquivalence(Enumerations.ConceptMapEquivalence.EQUIVALENT); ConceptMap.SourceElementComponent sourceElementComponent = new ConceptMap.SourceElementComponent(); - sourceElementComponent.setCode("body-weight"); + sourceElementComponent.setCode(SOURCE_CODE_STRING); sourceElementComponent.setTarget(Collections.singletonList(targetElementComponent)); ConceptMap.ConceptMapGroupComponent conceptMapGroupComponent = new ConceptMap.ConceptMapGroupComponent(); conceptMapGroupComponent.addElement(sourceElementComponent); - ConceptMap conceptMap = new ConceptMap(); - conceptMap.addGroup(conceptMapGroupComponent); - conceptMap.setUrl(CONCEPT_MAP_URL); - - SimpleWorkerContext simpleWorkerContext = new SimpleWorkerContext(); - simpleWorkerContext.cacheResource(conceptMap); - - ConceptMapEngine conceptMapEngine = new ConceptMapEngine(simpleWorkerContext); - - Coding coding = new Coding(null, "body-weight", "Body Weight"); - - Coding actual = conceptMapEngine.translate(coding, CONCEPT_MAP_URL); - - assertEquals("vital-signs", actual.getCode()); + return new ConceptMap() + .addGroup(conceptMapGroupComponent) + .setUrl(CONCEPT_MAP_URL); } }