Skip to content

Commit 1dfdbb6

Browse files
committed
adding test coverage
1 parent a23ec62 commit 1dfdbb6

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

service/src/main/java/uk/nhs/adaptors/gp2gp/ehr/mapper/diagnosticreport/DiagnosticReportMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private boolean hasObservationsWithoutSpecimen(List<Observation> observations) {
168168
/**
169169
* For correct display in EMIS, any observation without a specimen must be assigned a dummy specimen.
170170
*/
171-
private List<Observation> assignDummySpecimensToObservationsWithNoSpecimen(
171+
protected List<Observation> assignDummySpecimensToObservationsWithNoSpecimen(
172172
List<Observation> observations, List<Specimen> specimens) {
173173

174174
List<Observation> filingComments = getFilingComments(observations);

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package uk.nhs.adaptors.gp2gp.ehr.mapper.diagnosticreport;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
45
import static org.junit.jupiter.api.Assertions.assertAll;
56
import static org.mockito.ArgumentMatchers.any;
67
import static org.mockito.Mockito.when;
@@ -61,6 +62,7 @@ class DiagnosticReportMapperTest {
6162
private static final String INPUT_JSON_BUNDLE_WITH_FILING_COMMENTS = "fhir_bundle_with_filing_comments.json";
6263

6364
private static final String TEST_ID = "5E496953-065B-41F2-9577-BE8F2FBD0757";
65+
public static final String NOT_PRESENT_SPECIMEN_ID_PREFIX = "NOT-PRESENT-SPECIMEN-";
6466

6567
private static final String INPUT_JSON_REQUIRED_DATA = "diagnostic-report-with-required-data.json";
6668
private static final String INPUT_JSON_EMPTY_SPECIMENS = "diagnostic-report-with-empty-specimens.json";
@@ -129,6 +131,44 @@ public void tearDown() {
129131
messageContext.resetMessageContext();
130132
}
131133

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+
132172
@ParameterizedTest
133173
@MethodSource("resourceFileParams")
134174
void When_MappingDiagnosticReportJson_Expect_CompoundStatementXmlOutput(String inputJson, String outputXml) {

0 commit comments

Comments
 (0)