-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate importer tests to JUnit5 (#3665)
* Migrate paramterized RIS tests to JUnit5 * Extract generic importer testing code to new class * Switch to JUnit5 assertions in BibEntryAssert * Remove unused imports * Use static import for Assertion when possible * Extract file collection from importer test classes * Refactor biblioscape importer tests * Refactor BiblioscapeImporterTestTypes to JUnit5 syntax * Refactor CopacImporterTestFiles * Migrate medline importer tests to JUnit5 * Convert BibTeXML importer tests to JUnit5 * Move several non-parametric importer test classes to JUnit5 * Refactor Medline importer tests to JUni5 * Migrate parameterized MODS importer tests to JUnit5 * Migrate MrDLib importer tests to JUnit5 * Migrate MsBibImporter tests to JUnit5 * Migrate OvidImporter tests to JUnit5 * Migrate PdfContentImporter tests to JUnit5 * Migrate PdfXmpImporter tests to JUnit5 * Migrate RepecNepImporter tests to JUnit5 * Migrate RISImporter tests to JUnit5 * Migrate SilverPlatterImporter tests to JUnit5 * Fix imports in SilverPlatterImporterTest * Fix BibTeXMLImporter tests * Fix and clarify BibTeXMLImporterTestTypes * Fix medline tests for malformed files * Remove unused imports * Fix broken test files that can be fixed and remove the ones with larger syntactic problem * Fix MODSImporter tests * Fix test file for MsBibImporter tests * Convert Before to BeforeEach in OvidImporterTests * Check starting line of a file for checking whether it is a PDF * Migrate additional BibTeXML tests to JUnit5 * Refactor and restructure BibTexParser tests * Refactor CopacImporter tests * Refactor BibTeXMLImporter tests * Refactor EndnoteImporter tests * Refactor FreeCiteImporter tests * Refactor InspecImporter tests * Refactor IsiImporter tests * Refactor MedlineImporter tests * Refactor MrDLibImporter tests * Refactor MsBibImporter tests * Refactor OvidImporter tests * Refactor PdfXmpImporter tests * Refactor RepecNepImporter tests * Refactor SilverPlatterImporter tests * Fix a bunch of codacy issues
- Loading branch information
1 parent
5189a26
commit 608e415
Showing
47 changed files
with
1,384 additions
and
1,868 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 25 additions & 51 deletions
76
src/test/java/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestFiles.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,43 @@ | ||
package org.jabref.logic.importer.fileformat; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Stream; | ||
|
||
import org.jabref.logic.bibtex.BibEntryAssert; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.runners.Parameterized.Parameter; | ||
import org.junit.runners.Parameterized.Parameters; | ||
|
||
@RunWith(Parameterized.class) | ||
public class BibTeXMLImporterTestFiles { | ||
|
||
private static final Pattern PATTERN = Pattern.compile("\\D*[0123456789]"); | ||
|
||
private BibTeXMLImporter bibtexmlImporter; | ||
|
||
@Parameter | ||
public Path importFile; | ||
private static final String FILE_ENDING = ".xml"; | ||
|
||
|
||
@Before | ||
public void setUp() { | ||
bibtexmlImporter = new BibTeXMLImporter(); | ||
private static Stream<String> fileNames() throws IOException { | ||
Predicate<String> fileName = name -> name.startsWith("BibTeXMLImporterTest") | ||
&& name.endsWith(FILE_ENDING); | ||
return ImporterTestEngine.getTestFiles(fileName).stream(); | ||
} | ||
|
||
@Parameters(name = "{0}") | ||
public static List<Path> files() throws Exception { | ||
try (Stream<Path> stream = Files.list(Paths.get(BibTeXMLImporterTest.class.getResource("").toURI()))) { | ||
return stream.filter(n -> n.getFileName().toString().startsWith("BibTeXMLImporterTest") | ||
&& n.getFileName().toString().endsWith(".xml")).collect(Collectors.toList()); | ||
} | ||
private static Stream<String> nonBibTeXMLfileNames() throws IOException { | ||
Predicate<String> fileName = name -> !name.startsWith("BibTeXMLImporterTest"); | ||
return ImporterTestEngine.getTestFiles(fileName).stream(); | ||
} | ||
|
||
@Test | ||
public void testIsRecognizedFormat() throws IOException { | ||
Assert.assertTrue(bibtexmlImporter.isRecognizedFormat(importFile, StandardCharsets.UTF_8)); | ||
@ParameterizedTest | ||
@MethodSource("fileNames") | ||
public void testIsRecognizedFormat(String fileName) throws IOException { | ||
ImporterTestEngine.testIsRecognizedFormat(new BibTeXMLImporter(), fileName); | ||
} | ||
|
||
@Test | ||
public void testImportEntries() throws IOException { | ||
List<BibEntry> bibtexmlEntries = bibtexmlImporter.importDatabase(importFile, StandardCharsets.UTF_8) | ||
.getDatabase().getEntries(); | ||
@ParameterizedTest | ||
@MethodSource("nonBibTeXMLfileNames") | ||
public void testIsNotRecognizedFormat(String fileName) throws IOException { | ||
ImporterTestEngine.testIsNotRecognizedFormat(new BibTeXMLImporter(), fileName); | ||
} | ||
|
||
String bibFileName = importFile.getFileName().toString().replace(".xml", ".bib"); | ||
while (PATTERN.matcher(bibFileName).find()) { | ||
bibFileName = bibFileName.replaceFirst("[0123456789]", ""); | ||
} | ||
if (bibtexmlEntries.isEmpty()) { | ||
Assert.assertEquals(Collections.emptyList(), bibtexmlEntries); | ||
} else { | ||
BibEntryAssert.assertEquals(BibTeXMLImporterTest.class, bibFileName, bibtexmlEntries); | ||
} | ||
@ParameterizedTest | ||
@MethodSource("fileNames") | ||
public void testImportEntries(String fileName) throws IOException { | ||
ImporterTestEngine.testImportEntries(new BibTeXMLImporter(), fileName, FILE_ENDING); | ||
} | ||
|
||
} |
Oops, something went wrong.