Skip to content

Commit c2fdd63

Browse files
Continuing work to remove lenient
1 parent 39af912 commit c2fdd63

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed

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

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import org.junit.jupiter.params.provider.MethodSource;
1313
import org.mockito.Mock;
1414
import org.mockito.junit.jupiter.MockitoExtension;
15-
import org.mockito.junit.jupiter.MockitoSettings;
16-
import org.mockito.quality.Strictness;
1715
import uk.nhs.adaptors.gp2gp.common.service.ConfidentialityService;
1816
import uk.nhs.adaptors.gp2gp.common.service.FhirParseService;
1917
import uk.nhs.adaptors.gp2gp.common.service.RandomIdGeneratorService;
@@ -28,12 +26,12 @@
2826
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2927
import static org.mockito.ArgumentMatchers.any;
3028
import static org.mockito.ArgumentMatchers.anyString;
29+
import static org.mockito.Mockito.reset;
3130
import static org.mockito.Mockito.when;
3231
import static uk.nhs.adaptors.gp2gp.utils.ConfidentialityCodeUtility.NOPAT_HL7_CONFIDENTIALITY_CODE;
3332
import static uk.nhs.adaptors.gp2gp.utils.XmlAssertion.assertThatXml;
3433

3534
@ExtendWith(MockitoExtension.class)
36-
@MockitoSettings(strictness = Strictness.LENIENT)
3735
class ImmunizationObservationStatementMapperTest {
3836
private static final String TEST_ID = "test-id";
3937
private static final String IMMUNIZATION_FILE_LOCATIONS = "/ehr/mapper/immunization/";
@@ -168,7 +166,6 @@ class ImmunizationObservationStatementMapperTest {
168166

169167
@BeforeEach
170168
void setUp() {
171-
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
172169
when(randomIdGeneratorService.createNewOrUseExistingUUID(anyString())).thenReturn(TEST_ID);
173170
when(codeableConceptCdMapper.mapCodeableConceptToCd(any(CodeableConcept.class)))
174171
.thenReturn(CodeableConceptMapperMockUtil.NULL_FLAVOR_CODE);
@@ -197,17 +194,65 @@ void When_MappingImmunizationJson_Expect_ObservationStatementXmlOutput(String in
197194
var expectedOutput = ResourceTestFileUtils.getFileContent(outputXml);
198195
var jsonInput = ResourceTestFileUtils.getFileContent(inputJson);
199196

197+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
198+
200199
Immunization parsedImmunization = fhirParseService.parseResource(jsonInput, Immunization.class);
201200
String outputMessage = observationStatementMapper.mapImmunizationToObservationStatement(parsedImmunization, isNested);
202201
assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutput);
203202
}
204203

204+
@Test
205+
void When_MappingImmunizationWithoutCodeableConceptText_Expect_ObservationStatementXmlOutput() {
206+
var expectedOutput = ResourceTestFileUtils.getFileContent(OUTPUT_XML_WITH_PERTINENT_INFORMATION);
207+
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITHOUT_CODEABLE_CONCEPT_TEXT);
208+
209+
Immunization parsedImmunization = fhirParseService.parseResource(jsonInput, Immunization.class);
210+
String outputMessage = observationStatementMapper.mapImmunizationToObservationStatement(parsedImmunization, false);
211+
assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutput);
212+
}
213+
214+
@Test
215+
void When_MappingImmunizationWithoutRequiredPertinentInformation_Expect_ObservationStatementXmlOutput() {
216+
var expectedOutput = ResourceTestFileUtils.getFileContent(OUTPUT_XML_WITHOUT_REQUIRED_PERTINENT_INFORMATION);
217+
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITHOUT_REQUIRED_PERTINENT_INFORMATION);
218+
219+
reset(randomIdGeneratorService);
220+
221+
Immunization parsedImmunization = fhirParseService.parseResource(jsonInput, Immunization.class);
222+
String outputMessage = observationStatementMapper.mapImmunizationToObservationStatement(parsedImmunization, false);
223+
224+
assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutput);
225+
}
226+
227+
228+
229+
@Test
230+
void When_MappingImmunizationWithoutPractitioner_Expect_ObservationStatementXmlOutput() {
231+
var expectedOutput = ResourceTestFileUtils.getFileContent(OUTPUT_XML_WITHOUT_PARTICIPANT);
232+
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITHOUT_PRACTITIONER);
233+
234+
Immunization parsedImmunization = fhirParseService.parseResource(jsonInput, Immunization.class);
235+
String outputMessage = observationStatementMapper.mapImmunizationToObservationStatement(parsedImmunization, false);
236+
assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutput);
237+
}
238+
239+
@Test
240+
void When_MappingImmunizationWithPractitionerButNoActor_Expect_ObservationStatementXmlOutput() {
241+
var expectedOutput = ResourceTestFileUtils.getFileContent(OUTPUT_XML_WITHOUT_PARTICIPANT);
242+
var jsonInput = ResourceTestFileUtils.getFileContent(INPUT_JSON_WITH_PRACTITIONER_BUT_NO_ACTOR);
243+
244+
Immunization parsedImmunization = fhirParseService.parseResource(jsonInput, Immunization.class);
245+
String outputMessage = observationStatementMapper.mapImmunizationToObservationStatement(parsedImmunization, false);
246+
assertThat(outputMessage).isEqualToIgnoringWhitespace(expectedOutput);
247+
}
248+
249+
250+
251+
205252
private static Stream<Arguments> resourceFileParams() {
206253
return Stream.of(
207254
Arguments.of(INPUT_JSON_WITH_PERTINENT_INFORMATION, OUTPUT_XML_WITH_PERTINENT_INFORMATION, false),
208-
Arguments.of(INPUT_JSON_WITHOUT_CODEABLE_CONCEPT_TEXT, OUTPUT_XML_WITH_PERTINENT_INFORMATION, false),
209255
Arguments.of(INPUT_JSON_WITHOUT_DATE, OUTPUT_XML_WITHOUT_DATE, false),
210-
Arguments.of(INPUT_JSON_WITHOUT_REQUIRED_PERTINENT_INFORMATION, OUTPUT_XML_WITHOUT_REQUIRED_PERTINENT_INFORMATION, false),
211256
Arguments.of(INPUT_JSON_REASON_NOT_GIVEN, OUTPUT_XML_WITH_REASON_NOT_GIVEN, false),
212257
Arguments.of(INPUT_JSON_REASON_NOT_GIVEN_TEXT, OUTPUT_XML_WITH_REASON_NOT_GIVEN, false),
213258
Arguments.of(INPUT_JSON_WITH_PERTINENT_INFORMATION, OUTPUT_XML_WITHOUT_CONTEXT, true),
@@ -219,8 +264,6 @@ private static Stream<Arguments> resourceFileParams() {
219264
Arguments.of(INPUT_JSON_WITH_NO_RELATION_TO_CONDITION,
220265
OUTPUT_XML_WITH_IMMUNIZATION_WITH_NO_RELATION_TO_CONDITION, false),
221266
Arguments.of(INPUT_JSON_WITH_VACCINE_CODE, OUTPUT_XML_WITH_VACCINE_CODE, false),
222-
Arguments.of(INPUT_JSON_WITHOUT_PRACTITIONER, OUTPUT_XML_WITHOUT_PARTICIPANT, false),
223-
Arguments.of(INPUT_JSON_WITH_PRACTITIONER_BUT_NO_ACTOR, OUTPUT_XML_WITHOUT_PARTICIPANT, false),
224267
Arguments.of(INPUT_JSON_WITH_REPORT_ORIGIN, OUTPUT_XML_WITH_IMMUNIZATION_WITH_REPORT_ORIGIN, false),
225268
Arguments.of(INPUT_JSON_WITH_PARENT_PRESENT_FALSE, OUTPUT_XML_WITH_IMMUNIZATION_PARENT_PRESENT_FALSE, false),
226269
Arguments.of(INPUT_JSON_WITH_NO_PARENT_PRESENT, OUTPUT_XML_WITH_IMMUNIZATION_NO_PARENT_PRESENT, false),
@@ -259,6 +302,7 @@ void When_MappingImmunizationWithoutNopatMetaSecurity_Expect_MessageContainsConf
259302
final var parsedImmunization = fhirParseService.parseResource(jsonInput, Immunization.class);
260303
when(confidentialityService.generateConfidentialityCode(parsedImmunization))
261304
.thenReturn(Optional.of(NOPAT_HL7_CONFIDENTIALITY_CODE));
305+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
262306

263307
final var actualMessage = observationStatementMapper.mapImmunizationToObservationStatement(
264308
parsedImmunization,

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import static org.assertj.core.api.Assertions.assertThat;
2828
import static org.junit.jupiter.api.Assertions.assertAll;
2929
import static org.mockito.ArgumentMatchers.any;
30-
import static org.mockito.Mockito.lenient;
3130
import static org.mockito.Mockito.times;
3231
import static org.mockito.Mockito.verify;
3332
import static org.mockito.Mockito.when;
@@ -97,7 +96,6 @@ class NonConsultationResourceMapperTest {
9796

9897
@BeforeEach
9998
void setUp() {
100-
lenient().when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
10199
messageContext = new MessageContext(randomIdGeneratorService);
102100
fhirParseService = new FhirParseService();
103101
}
@@ -112,6 +110,7 @@ void tearDown() {
112110
void When_TransformingResourceToEhrComp_Expect_CorrectValuesToBeExtracted(String stubEhrComponentMapperXml, String inputBundle,
113111
String output) {
114112
setupMock(ResourceTestFileUtils.getFileContent(stubEhrComponentMapperXml));
113+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
115114
String bundle = ResourceTestFileUtils.getFileContent(inputBundle);
116115
String expectedOutput = ResourceTestFileUtils.getFileContent(output);
117116
Bundle parsedBundle = fhirParseService.parseResource(bundle, Bundle.class);
@@ -125,6 +124,7 @@ void When_TransformingResourceToEhrComp_Expect_CorrectValuesToBeExtracted(String
125124
@MethodSource("endedAllergiesArgs")
126125
void When_TransformingEndedAllergyListToEhrComp_Expect_CorrectValuesToBeExtracted(String inputBundle, String output) {
127126
setupMock(ResourceTestFileUtils.getFileContent(ALLERGY_INTOLERANCE_XML));
127+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
128128
String bundle = ResourceTestFileUtils.getFileContent(inputBundle);
129129
String expectedOutput = ResourceTestFileUtils.getFileContent(output);
130130
Bundle parsedBundle = fhirParseService.parseResource(bundle, Bundle.class);
@@ -143,6 +143,7 @@ void When_TransformingContainedResourceToEhrComp_WithSupportedComponent_Expect_C
143143
String bundle = ResourceTestFileUtils.getFileContent(CONTAINED_MISCELLANEOUS_RECORDS_BUNDLE);
144144
String expectedOutput = ResourceTestFileUtils.getFileContent(EXPECTED_MISCELLANEOUS_RECORDS_OUTPUT);
145145
Bundle parsedBundle = fhirParseService.parseResource(bundle, Bundle.class);
146+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
146147

147148
List<String> translatedOutput = nonConsultationResourceMapper.mapRemainingResourcesToEhrCompositions(parsedBundle);
148149

@@ -154,6 +155,7 @@ void When_TransformingContainedResourceToEhrComp_WithSupportedComponent_Expect_C
154155

155156
@Test
156157
void When_TransformingContainedResourceToEhrComp_WithUnsupportedComponent_Expect_ComponentNotMapped() {
158+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
157159
nonConsultationResourceMapper = new NonConsultationResourceMapper(
158160
messageContext,
159161
randomIdGeneratorService,
@@ -190,6 +192,7 @@ void When_TransformingResourcesToEhrComp_Expect_ObservationToBeProcessedLast() {
190192
setupMock("<MappedResourceStub/>");
191193
String bundle = ResourceTestFileUtils.getFileContent(DIAGNOSTIC_REPORT_AFTER_OBSERVATION_BUNDLE);
192194
Bundle parsedBundle = fhirParseService.parseResource(bundle, Bundle.class);
195+
when(randomIdGeneratorService.createNewId()).thenReturn(TEST_ID);
193196

194197
// ACT
195198
nonConsultationResourceMapper.mapRemainingResourcesToEhrCompositions(parsedBundle);
@@ -235,7 +238,7 @@ private static Stream<Arguments> endedAllergiesArgs() {
235238
}
236239

237240
private void setupMock(String stubEhrComponentMapperXml) {
238-
lenient().when(encounterComponentsMapper.mapResourceToComponent(any(Resource.class)))
241+
when(encounterComponentsMapper.mapResourceToComponent(any(Resource.class)))
239242
.thenReturn(Optional.of(stubEhrComponentMapperXml));
240243
nonConsultationResourceMapper = new NonConsultationResourceMapper(messageContext,
241244
randomIdGeneratorService,

0 commit comments

Comments
 (0)