Skip to content

Commit 89df2d1

Browse files
f
1 parent 3899a5f commit 89df2d1

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

service/src/test/java/uk/nhs/adaptors/gp2gp/ehr/mapper/ConditionLinkSetMapperTest.java

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@
3838
import static org.assertj.core.api.Assumptions.assumeThatThrownBy;
3939
import static org.junit.jupiter.api.Assertions.assertAll;
4040
import static org.mockito.ArgumentMatchers.any;
41-
import static org.mockito.Mockito.lenient;
42-
import static org.mockito.Mockito.when;
43-
import static org.mockito.Mockito.spy;
41+
import static org.mockito.Mockito.*;
42+
import static uk.nhs.adaptors.gp2gp.utils.CodeableConceptMapperMockUtil.TEST_CONDITION_CODE;
4443
import static uk.nhs.adaptors.gp2gp.utils.ConfidentialityCodeUtility.NOPAT;
4544
import static uk.nhs.adaptors.gp2gp.utils.ConfidentialityCodeUtility.NOPAT_HL7_CONFIDENTIALITY_CODE;
4645
import static uk.nhs.adaptors.gp2gp.utils.ConfidentialityCodeUtility.NOSCRUB;
@@ -260,27 +259,38 @@ void When_MappingParsedCondition_With_RelatedClinicalContentAllergy_Expect_LinkS
260259
assertThat(actualXml).isEqualTo(expectedXml);
261260
}
262261

262+
// It works but the indentation is giving me pain in the test comparison
263263
@Test
264264
void When_MappingParsedCondition_With_AllergyIntolerance_Expect_LinkSetXml() {
265-
final Condition condition = getConditionResourceFromJson(INPUT_JSON_WITH_ACTUAL_PROBLEM_ALLERGY_INTOLERANCE);
266-
final String expectedXml = getXmlStringFromFile(OUTPUT_XML_ALLERGY_INTOLERANCE_ACTUAL_PROBLEM);
265+
final Condition condition =
266+
getConditionResourceFromJson(INPUT_JSON_WITH_ACTUAL_PROBLEM_ALLERGY_INTOLERANCE);
267+
final String expectedXml =
268+
getXmlStringFromFile(OUTPUT_XML_ALLERGY_INTOLERANCE_ACTUAL_PROBLEM);
269+
IdType conditionId = buildIdType(ResourceType.Condition, CONDITION_ID);
267270

268-
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
269-
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
270271
when(messageContext.getIdMapper()).thenReturn(idMapper);
271272
when(messageContext.getAgentDirectory()).thenReturn(agentDirectory);
272273
when(messageContext.getInputBundleHolder()).thenReturn(inputBundle);
273-
274-
IdType conditionId = buildIdType(ResourceType.Condition, CONDITION_ID);
275-
when(idMapper.getOrNew(ResourceType.Condition, conditionId)).thenReturn(CONDITION_ID);
276-
when(idMapper.getOrNew(any(Reference.class))).thenAnswer(answerWithObjectId(ResourceType.Condition));
277-
when(agentDirectory.getAgentId(any(Reference.class))).thenAnswer(answerWithObjectId());
278-
when(randomIdGeneratorService.createNewId()).thenReturn(GENERATED_ID);
279-
lenient().doNothing().when(conditionLinkSetMapperSpy).testForValidReferences(any());
280-
281-
final String actualXml = conditionLinkSetMapperSpy.mapConditionToLinkSet(condition, false);
274+
when(idMapper.getOrNew(ResourceType.Condition, conditionId))
275+
.thenReturn(CONDITION_ID);
276+
when(idMapper.getOrNew(any(Reference.class)))
277+
.thenAnswer(answerWithObjectId(ResourceType.Condition));
278+
when(agentDirectory.getAgentId(any(Reference.class)))
279+
.thenAnswer(answerWithObjectId());
280+
when(randomIdGeneratorService.createNewId())
281+
.thenReturn(GENERATED_ID);
282+
lenient().doNothing().when(conditionLinkSetMapperSpy)
283+
.testForValidReferences(any());
284+
when(codeableConceptCdMapper.mapCodeableConceptToCdForTransformedActualProblemHeader(
285+
any(CodeableConcept.class)))
286+
.thenReturn(CodeableConceptMapperMockUtil.TEST_CONDITION_CODE);
287+
288+
final String actualXml =
289+
conditionLinkSetMapperSpy.mapConditionToLinkSet(condition, false);
282290

283291
assertThat(actualXml).isEqualTo(expectedXml);
292+
verify(codeableConceptCdMapper).mapCodeableConceptToCdForTransformedActualProblemHeader(any());
293+
verify(codeableConceptCdMapper, never()).mapCodeableConceptToCd(any());
284294
}
285295

286296
@Test
@@ -457,7 +467,9 @@ private static Stream<Arguments> testObservationArguments() {
457467
Arguments.of(INPUT_JSON_NO_ACTUAL_PROBLEM, OUTPUT_XML_WITH_GENERATED_PROBLEM_IS_NESTED, true),
458468
Arguments.of(INPUT_JSON_WITH_ACTUAL_PROBLEM_CONDITION, OUTPUT_XML_WITH_CONDITION_NAMED_OBSERVATION_STATEMENT_GENERATED, false),
459469
Arguments.of(INPUT_JSON_NO_ACTUAL_PROBLEM_NO_DATE, OUTPUT_XML_WITH_NULL_FLAVOR_OBSERVATION_STATEMENT_AVAILABILITY_TIME,
460-
true)
470+
true),
471+
Arguments.of(INPUT_JSON_WITH_ACTUAL_PROBLEM_IMMUNIZATION, OUTPUT_XML_IMMUNIZATION_ACTUAL_PROBLEM, false),
472+
Arguments.of(INPUT_JSON_WITH_ACTUAL_PROBLEM_MEDICATION_REQUEST, OUTPUT_XML_MEDICATION_REQUEST_ACTUAL_PROBLEM, false)
461473
);
462474
}
463475

service/src/test/java/uk/nhs/adaptors/gp2gp/utils/CodeableConceptMapperMockUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ public class CodeableConceptMapperMockUtil {
44
public static final String NULL_FLAVOR_CODE = "<code nullFlavor=\"UNK\"><originalText>Mocked code</originalText></code>";
55
public static final String ACTUAL_PROBLEM_CODE =
66
"<code code=\"55607006\" codeSystem=\"2.16.840.1.113883.2.1.3.2.4.15\" displayName=\"Problem\">";
7+
8+
public static final String TEST_CONDITION_CODE = "<code code=\"55607006\" codeSystem=\"2.16.840.1.113883.2.1.3.2.4.15\" displayName=\"Problem\">\n" +
9+
" <originalText>Test Condition</originalText>\n" +
10+
" </code>";
11+
712
}

0 commit comments

Comments
 (0)