Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed testExportAsModsAndThenImportAsMods #4369

Merged
merged 3 commits into from
Oct 14, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.jabref.logic.exporter;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand All @@ -16,23 +19,20 @@
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.util.DummyFileUpdateMonitor;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junitpioneer.jupiter.TempDirectory;
import org.mockito.Answers;
import org.mockito.Mockito;
import org.xmlunit.builder.Input;
import org.xmlunit.builder.Input.Builder;
import org.xmlunit.diff.DefaultNodeMatcher;
import org.xmlunit.diff.ElementSelectors;
import org.xmlunit.matchers.CompareMatcher;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;

@ExtendWith(TempDirectory.class)
public class ModsExportFormatTestFiles {

Expand Down Expand Up @@ -65,8 +65,10 @@ public void setUp(@TempDirectory.TempDir Path testFolder) throws Exception {
Path path = testFolder.resolve("ARandomlyNamedFile.tmp");
Files.createFile(path);
tempFile = path.toAbsolutePath();
bibtexImporter = new BibtexImporter(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS), new DummyFileUpdateMonitor());
modsImporter = new ModsImporter(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS));
ImportFormatPreferences mock = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS);
bibtexImporter = new BibtexImporter(mock, new DummyFileUpdateMonitor());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the indent here.

Mockito.when(mock.getKeywordSeparator()).thenReturn(',');
modsImporter = new ModsImporter(mock);
}

@Disabled
Expand All @@ -78,17 +80,17 @@ public final void testPerformExport(String filename) throws Exception {
Path tempFilename = tempFile.toAbsolutePath();
List<BibEntry> entries = bibtexImporter.importDatabase(importFile, charset).getDatabase().getEntries();
Path xmlFile = Paths.get(ModsExportFormatTestFiles.class.getResource(xmlFileName).toURI());

modsExportFormat.export(databaseContext, tempFile, charset, entries);

Builder control = Input.from(Files.newInputStream(xmlFile));
Builder test = Input.from(Files.newInputStream(tempFilename));

assertThat(test, CompareMatcher.isSimilarTo(control)
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)).throwComparisonFailure());
CompareMatcher matcher = CompareMatcher.isSimilarTo(control)
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)).throwComparisonFailure();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be an indent here (or put everything on one line).

assertThat(test, matcher);
}

@Disabled

@ParameterizedTest
@MethodSource("fileNames")
public final void testExportAsModsAndThenImportAsMods(String filename) throws Exception {
Expand Down