Skip to content

Commit cd9a4c6

Browse files
committed
Fix ModsExportFormatTestFiles
1 parent 08f21c1 commit cd9a4c6

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/test/java/org/jabref/logic/exporter/ModsExportFormatTestFiles.java

+14-5
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@
1818
import org.jabref.model.util.DummyFileUpdateMonitor;
1919

2020
import org.junit.jupiter.api.BeforeEach;
21-
import org.junit.jupiter.api.Disabled;
2221
import org.junit.jupiter.api.io.TempDir;
2322
import org.junit.jupiter.params.ParameterizedTest;
2423
import org.junit.jupiter.params.provider.MethodSource;
2524
import org.mockito.Answers;
2625
import org.mockito.Mockito;
26+
import org.xmlunit.diff.DefaultNodeMatcher;
27+
import org.xmlunit.diff.ElementSelectors;
2728

29+
import static org.hamcrest.MatcherAssert.assertThat;
2830
import static org.junit.jupiter.api.Assertions.assertEquals;
2931
import static org.mockito.Mockito.mock;
32+
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
3033

3134
public class ModsExportFormatTestFiles {
3235

@@ -66,7 +69,6 @@ public void setUp(@TempDir Path testFolder) throws Exception {
6669

6770
@ParameterizedTest
6871
@MethodSource("fileNames")
69-
@Disabled("Ordering of XML elements changed 2019-08-25")
7072
public final void testPerformExport(String filename) throws Exception {
7173
importFile = Paths.get(ModsExportFormatTestFiles.class.getResource(filename).toURI());
7274
String xmlFileName = filename.replace(".bib", ".xml");
@@ -75,9 +77,16 @@ public final void testPerformExport(String filename) throws Exception {
7577

7678
exporter.export(databaseContext, tempFile, charset, entries);
7779

78-
assertEquals(
79-
String.join("\n", Files.readAllLines(xmlFile)),
80-
String.join("\n", Files.readAllLines(tempFile)));
80+
String expected = String.join("\n", Files.readAllLines(xmlFile));
81+
String actual = String.join("\n", Files.readAllLines(tempFile));
82+
83+
// The order of elements changes from Windows to Travis environment somehow
84+
// The order does not really matter, so we ignore it.
85+
// Source: https://stackoverflow.com/a/16540679/873282
86+
assertThat(expected, isSimilarTo(expected)
87+
.ignoreWhitespace()
88+
.normalizeWhitespace()
89+
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)));
8190
}
8291

8392
@ParameterizedTest

0 commit comments

Comments
 (0)