Skip to content

Commit

Permalink
Fix ModsExportFormatTestFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Aug 25, 2019
1 parent 08f21c1 commit cd9a4c6
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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");
Expand All @@ -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
Expand Down

0 comments on commit cd9a4c6

Please sign in to comment.