|
1 | 1 | package uk.nhs.adaptors.gp2gp.ehr.mapper.diagnosticreport; |
2 | 2 |
|
3 | 3 | import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; |
4 | 5 | import static org.junit.jupiter.api.Assertions.assertAll; |
5 | 6 | import static org.mockito.ArgumentMatchers.any; |
6 | 7 | import static org.mockito.Mockito.when; |
@@ -61,6 +62,7 @@ class DiagnosticReportMapperTest { |
61 | 62 | private static final String INPUT_JSON_BUNDLE_WITH_FILING_COMMENTS = "fhir_bundle_with_filing_comments.json"; |
62 | 63 |
|
63 | 64 | private static final String TEST_ID = "5E496953-065B-41F2-9577-BE8F2FBD0757"; |
| 65 | + public static final String NOT_PRESENT_SPECIMEN_ID_PREFIX = "NOT-PRESENT-SPECIMEN-"; |
64 | 66 |
|
65 | 67 | private static final String INPUT_JSON_REQUIRED_DATA = "diagnostic-report-with-required-data.json"; |
66 | 68 | private static final String INPUT_JSON_EMPTY_SPECIMENS = "diagnostic-report-with-empty-specimens.json"; |
@@ -129,6 +131,44 @@ public void tearDown() { |
129 | 131 | messageContext.resetMessageContext(); |
130 | 132 | } |
131 | 133 |
|
| 134 | + @Test |
| 135 | + void shouldAssignDummySpecimenToObservationsWithoutSpecimen() { |
| 136 | + |
| 137 | + Observation obsWithoutSpecimen = new Observation(); |
| 138 | + Observation obsWithSpecimen = new Observation(); |
| 139 | + obsWithSpecimen.setSpecimen(new Reference("real-specimen")); |
| 140 | + |
| 141 | + List<Observation> observations = List.of(obsWithoutSpecimen, obsWithSpecimen); |
| 142 | + |
| 143 | + Specimen dummySpecimen = new Specimen(); |
| 144 | + dummySpecimen.setId("dummy-" + NOT_PRESENT_SPECIMEN_ID_PREFIX); |
| 145 | + Specimen realSpecimen = new Specimen(); |
| 146 | + realSpecimen.setId("real-specimen"); |
| 147 | + List<Specimen> specimens = List.of(realSpecimen, dummySpecimen); |
| 148 | + |
| 149 | + List<Observation> result = mapper.assignDummySpecimensToObservationsWithNoSpecimen(observations, specimens); |
| 150 | + |
| 151 | + assertThat(result).hasSize(2); |
| 152 | + assertThat(result.get(0).getSpecimen().getReference()).contains(dummySpecimen.getId()); |
| 153 | + assertThat(result.get(1).getSpecimen().getReference()).contains("real-specimen"); |
| 154 | + } |
| 155 | + |
| 156 | + @Test |
| 157 | + void shouldThrowIfNoDummySpecimenFound() { |
| 158 | + |
| 159 | + Observation obsWithoutSpecimen = new Observation(); |
| 160 | + List<Observation> observations = List.of(obsWithoutSpecimen); |
| 161 | + |
| 162 | + Specimen realSpecimen = new Specimen(); |
| 163 | + realSpecimen.setId("real-specimen"); |
| 164 | + List<Specimen> specimens = List.of(realSpecimen); |
| 165 | + |
| 166 | + assertThatThrownBy(() -> |
| 167 | + mapper.assignDummySpecimensToObservationsWithNoSpecimen(observations, specimens)) |
| 168 | + .isInstanceOf(IllegalStateException.class) |
| 169 | + .hasMessageContaining(NOT_PRESENT_SPECIMEN_ID_PREFIX); |
| 170 | + } |
| 171 | + |
132 | 172 | @ParameterizedTest |
133 | 173 | @MethodSource("resourceFileParams") |
134 | 174 | void When_MappingDiagnosticReportJson_Expect_CompoundStatementXmlOutput(String inputJson, String outputXml) { |
|
0 commit comments