Skip to content

Commit c1674a6

Browse files
author
Adrian Clay
authored
Allow whitespace differences when comparing expected and actual XML (#1020)
1 parent 23e4676 commit c1674a6

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
import uk.nhs.adaptors.gp2gp.ehr.utils.BloodPressureValidator;
1919
import uk.nhs.adaptors.gp2gp.utils.ResourceTestFileUtils;
2020

21-
import java.io.IOException;
2221
import java.util.List;
2322
import java.util.Optional;
2423
import java.util.stream.Collectors;
2524
import java.util.stream.Stream;
2625

2726
import static java.util.Arrays.asList;
2827
import static org.assertj.core.api.Assertions.assertThat;
28+
import static org.junit.jupiter.api.Assertions.assertAll;
2929
import static org.mockito.ArgumentMatchers.any;
3030
import static org.mockito.Mockito.lenient;
3131
import static org.mockito.Mockito.times;
@@ -110,46 +110,49 @@ public void tearDown() {
110110
@ParameterizedTest
111111
@MethodSource("testArgs")
112112
public void When_TransformingResourceToEhrComp_Expect_CorrectValuesToBeExtracted(String stubEhrComponentMapperXml, String inputBundle,
113-
String output) throws IOException {
113+
String output) {
114114
setupMock(ResourceTestFileUtils.getFileContent(stubEhrComponentMapperXml));
115115
String bundle = ResourceTestFileUtils.getFileContent(inputBundle);
116116
String expectedOutput = ResourceTestFileUtils.getFileContent(output);
117117
Bundle parsedBundle = fhirParseService.parseResource(bundle, Bundle.class);
118118

119119
var translatedOutput = nonConsultationResourceMapper.mapRemainingResourcesToEhrCompositions(parsedBundle).get(0);
120-
assertThat(translatedOutput).isEqualTo(expectedOutput);
120+
assertThat(translatedOutput).isEqualToIgnoringWhitespace(expectedOutput);
121121
}
122122

123123
@ParameterizedTest
124124
@MethodSource("endedAllergiesArgs")
125-
public void When_TransformingEndedAllergyListToEhrComp_Expect_CorrectValuesToBeExtracted(String inputBundle, String output)
126-
throws IOException {
125+
public void When_TransformingEndedAllergyListToEhrComp_Expect_CorrectValuesToBeExtracted(String inputBundle, String output) {
127126
setupMock(ResourceTestFileUtils.getFileContent(ALLERGY_INTOLERANCE_XML));
128127
String bundle = ResourceTestFileUtils.getFileContent(inputBundle);
129128
String expectedOutput = ResourceTestFileUtils.getFileContent(output);
130129
Bundle parsedBundle = fhirParseService.parseResource(bundle, Bundle.class);
131130

132131
var translatedOutput = nonConsultationResourceMapper.mapRemainingResourcesToEhrCompositions(parsedBundle);
133-
assertThat(translatedOutput.size()).isEqualTo(2);
134-
assertThat(translatedOutput.get(0)).isEqualTo(expectedOutput);
135-
assertThat(translatedOutput.get(1)).isEqualTo(expectedOutput);
132+
assertAll(
133+
() -> assertThat(translatedOutput.size()).isEqualTo(2),
134+
() -> assertThat(translatedOutput.get(0)).isEqualToIgnoringWhitespace(expectedOutput),
135+
() -> assertThat(translatedOutput.get(1)).isEqualToIgnoringWhitespace(expectedOutput)
136+
);
136137
}
137138

138139
@Test
139-
public void When_TransformingContainedResourceToEhrComp_WithSupportedComponent_Expect_CorrectValuesExtracted() throws IOException {
140+
public void When_TransformingContainedResourceToEhrComp_WithSupportedComponent_Expect_CorrectValuesExtracted() {
140141
setupMock(ResourceTestFileUtils.getFileContent(OBSERVATION_STATEMENT_XML));
141142
String bundle = ResourceTestFileUtils.getFileContent(CONTAINED_MISCELLANEOUS_RECORDS_BUNDLE);
142143
String expectedOutput = ResourceTestFileUtils.getFileContent(EXPECTED_MISCELLANEOUS_RECORDS_OUTPUT);
143144
Bundle parsedBundle = fhirParseService.parseResource(bundle, Bundle.class);
144145

145146
List<String> translatedOutput = nonConsultationResourceMapper.mapRemainingResourcesToEhrCompositions(parsedBundle);
146147

147-
assertThat(translatedOutput.size()).isOne();
148-
assertThat(translatedOutput.get(0)).isEqualToIgnoringWhitespace(expectedOutput);
148+
assertAll(
149+
() -> assertThat(translatedOutput.size()).isOne(),
150+
() -> assertThat(translatedOutput.get(0)).isEqualToIgnoringWhitespace(expectedOutput)
151+
);
149152
}
150153

151154
@Test
152-
public void When_TransformingContainedResourceToEhrComp_WithUnsupportedComponent_Expect_ComponentNotMapped() throws IOException {
155+
public void When_TransformingContainedResourceToEhrComp_WithUnsupportedComponent_Expect_ComponentNotMapped() {
153156
nonConsultationResourceMapper = new NonConsultationResourceMapper(
154157
messageContext,
155158
randomIdGeneratorService,
@@ -166,22 +169,22 @@ public void When_TransformingContainedResourceToEhrComp_WithUnsupportedComponent
166169

167170
List<String> translatedOutput = nonConsultationResourceMapper.mapRemainingResourcesToEhrCompositions(parsedBundle);
168171

169-
assertThat(translatedOutput.isEmpty()).isTrue();
172+
assertThat(translatedOutput).isEmpty();
170173

171174
}
172175

173176
@Test
174-
public void When_TransformingResourceToEhrComp_Expect_IgnoredResourceToBeIgnored() throws IOException {
177+
public void When_TransformingResourceToEhrComp_Expect_IgnoredResourceToBeIgnored() {
175178
setupMock(ResourceTestFileUtils.getFileContent("")); // empty filePath provided as this isn't expected to return anything
176179
String bundle = ResourceTestFileUtils.getFileContent(UNCATAGORISED_IGNORED_RESOURCE_BUNDLE);
177180
Bundle parsedBundle = fhirParseService.parseResource(bundle, Bundle.class);
178181

179182
var translatedOutput = nonConsultationResourceMapper.mapRemainingResourcesToEhrCompositions(parsedBundle);
180-
assertThat(translatedOutput.isEmpty()).isTrue();
183+
assertThat(translatedOutput).isEmpty();
181184
}
182185

183186
@Test
184-
public void When_TransformingResourcesToEhrComp_Expect_ObservationToBeProcessedLast() throws IOException {
187+
public void When_TransformingResourcesToEhrComp_Expect_ObservationToBeProcessedLast() {
185188
// ARRANGE
186189
setupMock("<MappedResourceStub/>");
187190
String bundle = ResourceTestFileUtils.getFileContent(DIAGNOSTIC_REPORT_AFTER_OBSERVATION_BUNDLE);

0 commit comments

Comments
 (0)