33import static org .assertj .core .api .Assertions .assertThat ;
44import static org .junit .jupiter .api .Assertions .assertAll ;
55import static org .mockito .ArgumentMatchers .any ;
6- import static org .mockito .Mockito .lenient ;
76import static org .mockito .Mockito .when ;
87import static uk .nhs .adaptors .gp2gp .utils .ConfidentialityCodeUtility .NOPAT_HL7_CONFIDENTIALITY_CODE ;
98
@@ -89,7 +88,7 @@ void When_MappingSpecimen_Expect_XmlOutput(String inputPath, String expectedPath
8988 var inputBundle = new FhirParseService ().parseResource (inputBundleString , Bundle .class );
9089
9190 when (messageContext .getIdMapper ()).thenReturn (idMapper );
92- lenient (). when (messageContext .getInputBundleHolder ()).thenReturn (new InputBundle (inputBundle ));
91+ when (messageContext .getInputBundleHolder ()).thenReturn (new InputBundle (inputBundle ));
9392 when (idMapper .getOrNew (any (ResourceType .class ), any (IdType .class ))).thenAnswer (mockId ());
9493 when (observationMapper .mapObservationToCompoundStatement (any (Observation .class )))
9594 .thenAnswer (mockObservationMapping ());
@@ -99,6 +98,22 @@ void When_MappingSpecimen_Expect_XmlOutput(String inputPath, String expectedPath
9998 assertThat (actualXml ).isEqualTo (expectedXml );
10099 }
101100
101+ @ ParameterizedTest
102+ @ MethodSource ("testDataNoNeedToMockBundle" )
103+ void When_MappingSpecimen_Expect_XmlOutputWithoutCertainData (String inputPath , String expectedPath ) {
104+ final Specimen specimen = getSpecimenResourceFromJson (inputPath );
105+ final String expectedXml = ResourceTestFileUtils .getFileContent (SPECIMEN_TEST_FILES_DIRECTORY + expectedPath );
106+
107+ when (messageContext .getIdMapper ()).thenReturn (idMapper );
108+ when (idMapper .getOrNew (any (ResourceType .class ), any (IdType .class ))).thenAnswer (mockId ());
109+ when (observationMapper .mapObservationToCompoundStatement (any (Observation .class )))
110+ .thenAnswer (mockObservationMapping ());
111+
112+ final String actualXml = specimenMapper .mapSpecimenToCompoundStatement (specimen , observations , DIAGNOSTIC_REPORT );
113+
114+ assertThat (actualXml ).isEqualTo (expectedXml );
115+ }
116+
102117 @ Test
103118 void When_MappingDefaultSpecimenWithDefaultObservation_Expect_DefaultXmlOutput () {
104119 final Specimen specimen = getDefaultSpecimen ();
@@ -197,13 +212,6 @@ private Specimen getSpecimenResourceFromJson(String filename) {
197212 private static Stream <Arguments > testData () {
198213 return Stream .of (
199214 Arguments .of ("input-specimen.json" , "expected-specimen.xml" ),
200- Arguments .of ("input-specimen-with-collection-period.json" , "expected-specimen-with-collection-period.xml" ),
201- Arguments .of ("input-specimen-without-accession-identifier.json" , "expected-specimen-without-accession-identifier.xml" ),
202- Arguments .of ("input-specimen-without-collection-time.json" , "expected-specimen-without-collection-time.xml" ),
203- Arguments .of ("input-specimen-without-type.json" , "expected-specimen-without-type.xml" ),
204- Arguments .of ("input-specimen-without-type-text.json" , "expected-specimen-without-type-text.xml" ),
205- Arguments .of ("input-specimen-without-agent-person.json" , "expected-specimen-without-agent-person.xml" ),
206- Arguments .of ("input-specimen-without-collection-details.json" , "expected-specimen-without-collection-details.xml" ),
207215 Arguments .of ("input-specimen-without-fasting-status.json" , "expected-specimen-without-fasting-status.xml" ),
208216 Arguments .of ("input-specimen-without-fasting-duration.json" , "expected-specimen-without-fasting-duration.xml" ),
209217 Arguments .of ("input-specimen-without-quantity.json" , "expected-specimen-without-quantity.xml" ),
@@ -215,6 +223,18 @@ private static Stream<Arguments> testData() {
215223 );
216224 }
217225
226+ private static Stream <Arguments > testDataNoNeedToMockBundle () {
227+ return Stream .of (
228+ Arguments .of ("input-specimen-with-collection-period.json" , "expected-specimen-with-collection-period.xml" ),
229+ Arguments .of ("input-specimen-without-accession-identifier.json" , "expected-specimen-without-accession-identifier.xml" ),
230+ Arguments .of ("input-specimen-without-collection-time.json" , "expected-specimen-without-collection-time.xml" ),
231+ Arguments .of ("input-specimen-without-type.json" , "expected-specimen-without-type.xml" ),
232+ Arguments .of ("input-specimen-without-type-text.json" , "expected-specimen-without-type-text.xml" ),
233+ Arguments .of ("input-specimen-without-agent-person.json" , "expected-specimen-without-agent-person.xml" ),
234+ Arguments .of ("input-specimen-without-collection-details.json" , "expected-specimen-without-collection-details.xml" )
235+ );
236+ }
237+
218238 private Answer <String > mockId () {
219239 return invocation -> {
220240 ResourceType resourceType = invocation .getArgument (0 );
@@ -223,13 +243,6 @@ private Answer<String> mockId() {
223243 };
224244 }
225245
226- private Answer <String > mockReference () {
227- return invocation -> {
228- Reference reference = invocation .getArgument (0 );
229- return String .format ("REFERENCE-to-%s" , reference .getReference ());
230- };
231- }
232-
233246 private Answer <String > mockObservationMapping () {
234247 return invocation -> {
235248 Observation observation = invocation .getArgument (0 );
0 commit comments