Skip to content

Commit 82ac348

Browse files
Added test to fix pitest
1 parent 1f6c74d commit 82ac348

File tree

2 files changed

+458
-9
lines changed

2 files changed

+458
-9
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package uk.nhs.adaptors.gp2gp.ehr.mapper;
22

33
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
4+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
45
import static org.mockito.ArgumentMatchers.any;
56
import static org.mockito.ArgumentMatchers.eq;
67
import static org.junit.jupiter.api.Assertions.assertThrows;
78
import static org.mockito.Mockito.when;
89
import static org.mockito.Mockito.mock;
910

1011

12+
import java.nio.file.Files;
13+
import java.nio.file.Paths;
1114
import java.time.Instant;
1215
import java.time.temporal.ChronoUnit;
1316
import java.util.Arrays;
@@ -161,7 +164,7 @@ void When_BuildEhrCompositionForSkeletonEhrExtract_Expect_ExpectedComponentBuilt
161164
}
162165

163166
@Test
164-
void When_ValidateXmlAgainstSchemaWithInvalidXmlAndRedactionID_Expect_XmlSchemaValidationExceptionIsThrown() {
167+
void When_ValidateXmlAgainstSchemaWithInvalidXmlAndAnyId_Expect_XmlSchemaValidationExceptionIsThrown() {
165168
String invalidXml = "<invalid><xml>";
166169

167170
when(redactionsContext.ehrExtractInteractionId())
@@ -175,18 +178,19 @@ void When_ValidateXmlAgainstSchemaWithInvalidXmlAndRedactionID_Expect_XmlSchemaV
175178
}
176179

177180
@Test
178-
void When_ValidateXmlAgainstSchemaWithInvalidXmlAndNonRedactionID_Expect_XmlSchemaValidationExceptionIsThrown() {
179-
String invalidXml = "<invalid><xml>";
181+
void When_ValidateXmlAgainstSchemaWithValidXmlAndAnyId_Expect_NoExceptionIsThrown() throws Exception {
182+
String basePath = Paths.get("src/").toFile().getAbsoluteFile().getAbsolutePath()
183+
+ "/../../service/src/test/resources/";
184+
String xmlFilePath = basePath + "complete-and-validated-xml-test-file.xml";
180185

181-
when(redactionsContext.ehrExtractInteractionId())
182-
.thenReturn("non-redaction-id");
186+
String validXml = Files.readString(Paths.get(xmlFilePath));
183187

184-
XmlSchemaValidationException ex = assertThrows(XmlSchemaValidationException.class, () -> {
185-
ehrExtractMapper.validateXmlAgainstSchema(invalidXml);
186-
});
188+
when(redactionsContext.ehrExtractInteractionId())
189+
.thenReturn(RedactionsContext.REDACTION_INTERACTION_ID);
187190

188-
assertThat(ex.getMessage()).contains("XML schema validation failed");
191+
assertDoesNotThrow(() -> ehrExtractMapper.validateXmlAgainstSchema(validXml));
189192
}
190193

191194

195+
192196
}

0 commit comments

Comments
 (0)