From cd9a4c6da42a2a38f72ecb260b11e8b71a7992fc Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 25 Aug 2019 15:54:52 +0200 Subject: [PATCH] Fix ModsExportFormatTestFiles --- .../exporter/ModsExportFormatTestFiles.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/jabref/logic/exporter/ModsExportFormatTestFiles.java b/src/test/java/org/jabref/logic/exporter/ModsExportFormatTestFiles.java index 35508b3e48f..c4972511691 100644 --- a/src/test/java/org/jabref/logic/exporter/ModsExportFormatTestFiles.java +++ b/src/test/java/org/jabref/logic/exporter/ModsExportFormatTestFiles.java @@ -18,15 +18,18 @@ import org.jabref.model.util.DummyFileUpdateMonitor; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Answers; import org.mockito.Mockito; +import org.xmlunit.diff.DefaultNodeMatcher; +import org.xmlunit.diff.ElementSelectors; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; +import static org.xmlunit.matchers.CompareMatcher.isSimilarTo; public class ModsExportFormatTestFiles { @@ -66,7 +69,6 @@ public void setUp(@TempDir Path testFolder) throws Exception { @ParameterizedTest @MethodSource("fileNames") - @Disabled("Ordering of XML elements changed 2019-08-25") public final void testPerformExport(String filename) throws Exception { importFile = Paths.get(ModsExportFormatTestFiles.class.getResource(filename).toURI()); String xmlFileName = filename.replace(".bib", ".xml"); @@ -75,9 +77,16 @@ public final void testPerformExport(String filename) throws Exception { exporter.export(databaseContext, tempFile, charset, entries); - assertEquals( - String.join("\n", Files.readAllLines(xmlFile)), - String.join("\n", Files.readAllLines(tempFile))); + String expected = String.join("\n", Files.readAllLines(xmlFile)); + String actual = String.join("\n", Files.readAllLines(tempFile)); + + // The order of elements changes from Windows to Travis environment somehow + // The order does not really matter, so we ignore it. + // Source: https://stackoverflow.com/a/16540679/873282 + assertThat(expected, isSimilarTo(expected) + .ignoreWhitespace() + .normalizeWhitespace() + .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))); } @ParameterizedTest