33import static org .assertj .core .api .Assertions .assertThat ;
44import static org .assertj .core .api .Assertions .assertThatThrownBy ;
55import static org .mockito .ArgumentMatchers .anyString ;
6- import static org .mockito .Mockito .lenient ;
76import static org .mockito .Mockito .verify ;
87import static org .mockito .Mockito .when ;
98
@@ -83,14 +82,8 @@ public class EncounterMapperTest {
8382
8483 @ BeforeEach
8584 void setUp () {
86- lenient ().when (randomIdGeneratorService .createNewOrUseExistingUUID (anyString ())).thenReturn (TEST_ID );
87-
8885 messageContext = new MessageContext (randomIdGeneratorService );
8986 messageContext .initialize (bundle );
90- lenient ().when (bundle .getEntry ()).thenReturn (List .of (
91- BUNDLE_ENTRY_WITH_CONSULTATION ,
92- BUNDLE_ENTRY_WITH_LOCATION
93- ));
9487 encounterMapper = new EncounterMapper (messageContext , encounterComponentsMapper , confidentialityService );
9588 }
9689
@@ -101,7 +94,14 @@ void tearDown() {
10194
10295 @ Test
10396 void testEncounterWithNOPATAddsConfidentialityCodeIntoEhrComposition () {
104- lenient ().when (randomIdGeneratorService .createNewId ()).thenReturn (TEST_ID );
97+ when (randomIdGeneratorService .createNewId ()).thenReturn (TEST_ID );
98+ when (randomIdGeneratorService .createNewOrUseExistingUUID (anyString ())).thenReturn (TEST_ID );
99+
100+ when (bundle .getEntry ()).thenReturn (List .of (
101+ BUNDLE_ENTRY_WITH_CONSULTATION ,
102+ BUNDLE_ENTRY_WITH_LOCATION
103+ ));
104+
105105 var sampleComponent = ResourceTestFileUtils .getFileContent (SAMPLE_EHR_COMPOSITION_COMPONENT );
106106 var encounterJsonInput = ResourceTestFileUtils .getFileContent (TEST_FILES_DIRECTORY + "input-encounter-with-nopat.json" );
107107 var expectedOutputWithConfidentialityCode
@@ -120,7 +120,13 @@ void testEncounterWithNOPATAddsConfidentialityCodeIntoEhrComposition() {
120120 @ ParameterizedTest
121121 @ MethodSource ("testFilePaths" )
122122 void When_MappingParsedEncounterJson_Expect_EhrCompositionXmlOutput (String input , String output ) {
123- lenient ().when (randomIdGeneratorService .createNewId ()).thenReturn (TEST_ID );
123+ when (randomIdGeneratorService .createNewId ()).thenReturn (TEST_ID );
124+ when (randomIdGeneratorService .createNewOrUseExistingUUID (anyString ())).thenReturn (TEST_ID );
125+ when (bundle .getEntry ()).thenReturn (List .of (
126+ BUNDLE_ENTRY_WITH_CONSULTATION ,
127+ BUNDLE_ENTRY_WITH_LOCATION
128+ ));
129+
124130 var sampleComponent = ResourceTestFileUtils .getFileContent (SAMPLE_EHR_COMPOSITION_COMPONENT );
125131
126132 String expectedOutputMessage = ResourceTestFileUtils .getFileContent (TEST_FILES_DIRECTORY + output );
@@ -134,6 +140,27 @@ void When_MappingParsedEncounterJson_Expect_EhrCompositionXmlOutput(String input
134140
135141 verify (encounterComponentsMapper ).mapComponents (parsedEncounter );
136142 }
143+ @ Test
144+ void When_MappingParsedEncounterJson_Expect_EhrCompositionXmlOutputWithNulAuthor () {
145+ when (randomIdGeneratorService .createNewOrUseExistingUUID (anyString ())).thenReturn (TEST_ID );
146+ when (bundle .getEntry ()).thenReturn (List .of (
147+ BUNDLE_ENTRY_WITH_CONSULTATION ,
148+ BUNDLE_ENTRY_WITH_LOCATION
149+ ));
150+
151+ var sampleComponent = ResourceTestFileUtils .getFileContent (SAMPLE_EHR_COMPOSITION_COMPONENT );
152+
153+ String expectedOutputMessage = ResourceTestFileUtils .getFileContent (TEST_FILES_DIRECTORY + "output-with-nul-author-participant2.xml" );
154+
155+ var jsonInput = ResourceTestFileUtils .getFileContent (TEST_FILES_DIRECTORY + "input-without-recorder-participant.json" );
156+ Encounter parsedEncounter = new FhirParseService ().parseResource (jsonInput , Encounter .class );
157+ when (encounterComponentsMapper .mapComponents (parsedEncounter )).thenReturn (sampleComponent );
158+
159+ String outputMessage = encounterMapper .mapEncounterToEhrComposition (parsedEncounter );
160+ assertThat (outputMessage ).isEqualTo (expectedOutputMessage );
161+
162+ verify (encounterComponentsMapper ).mapComponents (parsedEncounter );
163+ }
137164
138165 private static Stream <Arguments > testFilePaths () {
139166 return Stream .of (
@@ -153,7 +180,6 @@ private static Stream<Arguments> testFilePaths() {
153180 "output-with-type-and-no-coding-and-text-and-no-text.xml"
154181 ),
155182 Arguments .of ("input-without-performer-participant.json" , "output-with-recorder-as-participant2.xml" ),
156- Arguments .of ("input-without-recorder-participant.json" , "output-with-nul-author-participant2.xml" ),
157183 Arguments .of ("input-with-no-location-reference.json" , "output-with-no-location-reference.xml" )
158184 );
159185 }
@@ -175,8 +201,6 @@ void When_MappingEncounterWithNoType_Expect_Exception() {
175201
176202 @ Test
177203 void When_MappingEncounterLocationWithNoReference_Expect_Exception () {
178- lenient ().when (randomIdGeneratorService .createNewId ()).thenReturn (TEST_ID );
179- lenient ().when (bundle .getEntry ()).thenReturn (List .of (BUNDLE_ENTRY_WITH_CONSULTATION ));
180204 var sampleComponent = ResourceTestFileUtils .getFileContent (SAMPLE_EHR_COMPOSITION_COMPONENT );
181205
182206 var jsonInput = ResourceTestFileUtils .getFileContent (TEST_FILES_DIRECTORY
@@ -191,6 +215,11 @@ void When_MappingEncounterLocationWithNoReference_Expect_Exception() {
191215
192216 @ Test
193217 void When_MappingEncounterWithInvalidParticipantReferenceResourceType_Expect_Exception () {
218+ when (bundle .getEntry ()).thenReturn (List .of (
219+ BUNDLE_ENTRY_WITH_CONSULTATION ,
220+ BUNDLE_ENTRY_WITH_LOCATION
221+ ));
222+
194223 var sampleComponent = ResourceTestFileUtils .getFileContent (SAMPLE_EHR_COMPOSITION_COMPONENT );
195224
196225 var jsonInput = ResourceTestFileUtils .getFileContent (TEST_FILES_DIRECTORY
0 commit comments