Skip to content

Commit

Permalink
Switch to parameterized tests
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Mar 12, 2016
1 parent 72ee018 commit 96b14c2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
package net.sf.jabref.importer.fileformat;

import net.sf.jabref.Globals;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.bibtex.BibtexEntryAssert;
import net.sf.jabref.model.entry.BibEntry;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.junit.Assert.*;

public class PdfContentImporterTest {

@BeforeClass
public static void setUp() {
Globals.prefs = JabRefPreferences.getInstance();
}

@Test
public void doesNotHandleEncryptedPdfs() throws IOException {
PdfContentImporter importer = new PdfContentImporter();
Expand All @@ -32,18 +20,4 @@ public void doesNotHandleEncryptedPdfs() throws IOException {
assertEquals(Collections.emptyList(), result);
}

@Test
public void correctContent() throws IOException {
PdfContentImporter importer = new PdfContentImporter();
// The test folder contains pairs of PDFs and BibTeX files. We check each pair.
// Currently only one pair available
List<String> prefixes = Arrays.asList("LNCS-minimal");
for (String prefix : prefixes) {
try (InputStream is = PdfContentImporter.class.getResourceAsStream(prefix + ".pdf")) {
List<BibEntry> result = importer.importEntries(is, null);
Assert.assertEquals(1, result.size());
BibtexEntryAssert.assertEquals(PdfContentImporterTest.class, prefix + ".bib", result.get(0));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package net.sf.jabref.importer.fileformat;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.junit.Assert;
import org.junit.BeforeClass;
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;

import net.sf.jabref.Globals;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.bibtex.BibtexEntryAssert;
import net.sf.jabref.model.entry.BibEntry;

@RunWith(Parameterized.class)
public class PdfContentImporterTestFiles {

@BeforeClass
public static void setUp() {
Globals.prefs = JabRefPreferences.getInstance();
}

@Parameters(name = "{index}: {0}")
public static Collection<Object[]> fileNames() {
// The test folder contains pairs of PDFs and BibTeX files. We check each pair.
// This method returns the basenames of the available pairs

// currently, only one test case "LNCS-minimal" is existing
// code review demanded that @Paramters should be used
// Arrays.asList only works for multiple parameters, therefore, there are two parameters written
return Arrays.asList(new Object[] {"LNCS-minimal"}, new Object[] {"LNCS-minimal"});
}


@Parameter
public String fileName;

@Test
public void correctContent() throws IOException {
String pdfFileName = fileName + ".pdf";
String bibFileName = fileName + ".bib";
PdfContentImporter importer = new PdfContentImporter();
try (InputStream is = PdfContentImporter.class.getResourceAsStream(pdfFileName)) {
List<BibEntry> result = importer.importEntries(is, null);
Assert.assertEquals(1, result.size());
BibtexEntryAssert.assertEquals(PdfContentImporterTest.class, bibFileName, result.get(0));
}
}

}

0 comments on commit 96b14c2

Please sign in to comment.