-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Test for InspecImporter #356
Changes from all commits
f56e689
c8ba49e
6d0e813
15ee8f7
d8c61e2
180db7e
70ce056
8bbc6c2
e8d6e6e
6a5a950
c0e48db
867377b
672144f
bd33762
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package net.sf.jabref.importer.fileformat; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import net.sf.jabref.bibtex.BibtexEntryAssert; | ||
import net.sf.jabref.importer.OutputPrinterToNull; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
import net.sf.jabref.model.entry.BibtexEntryTypes; | ||
|
||
import net.sf.jabref.Globals; | ||
import net.sf.jabref.JabRefPreferences; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class InspecImportTest { | ||
|
||
private InspecImporter inspecImp; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
Globals.prefs = JabRefPreferences.getInstance(); | ||
this.inspecImp = new InspecImporter(); | ||
} | ||
|
||
@Test | ||
public void testIsRecognizedFormatAccept() throws IOException { | ||
List<String> testList = Arrays.asList("InspecImportTest.txt", "InspecImportTest2.txt"); | ||
for (String str : testList) { | ||
try (InputStream inStream = InspecImportTest.class.getResourceAsStream(str)) { | ||
assertTrue(inspecImp.isRecognizedFormat(inStream)); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void testIsRecognizedFormatReject() throws IOException { | ||
List<String> testList = Arrays.asList("CopacImporterTest1.txt", "CopacImporterTest2.txt", | ||
"IEEEImport1.txt", "IsiImporterTest1.isi", "IsiImporterTestInspec.isi", "IsiImporterTestWOS.isi", | ||
"IsiImporterTestMedline.isi", "RisImporterTest1.ris", "InspecImportTestFalse.txt"); | ||
for (String str : testList) { | ||
try (InputStream inStream = InspecImportTest.class.getResourceAsStream(str)) { | ||
assertFalse(inspecImp.isRecognizedFormat(inStream)); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void testCompleteBibtexEntryOnJournalPaperImport() throws IOException { | ||
|
||
BibEntry shouldBeEntry = new BibEntry(); | ||
shouldBeEntry.setType("article"); | ||
shouldBeEntry.setField("title", "The SIS project : software reuse with a natural language approach"); | ||
shouldBeEntry.setField("author", "Prechelt, Lutz"); | ||
shouldBeEntry.setField("year", "1992"); | ||
shouldBeEntry.setField("abstract", "Abstrakt"); | ||
shouldBeEntry.setField("keywords", "key"); | ||
shouldBeEntry.setField("journal", "10000"); | ||
shouldBeEntry.setField("pages", "20"); | ||
shouldBeEntry.setField("volume", "19"); | ||
|
||
try (InputStream inStream = InspecImportTest.class.getResourceAsStream("InspecImportTest2.txt")) { | ||
List<BibEntry> entries = inspecImp.importEntries(inStream, new OutputPrinterToNull()); | ||
assertEquals(1, entries.size()); | ||
BibEntry entry = entries.get(0); | ||
BibtexEntryAssert.assertEquals(shouldBeEntry, entry); | ||
|
||
} | ||
} | ||
|
||
@Test | ||
public void importConferencePaperGivesInproceedings() throws IOException { | ||
String testInput = "Record.*INSPEC.*\n" + | ||
"\n" + | ||
"RT ~ Conference-Paper"; | ||
BibEntry shouldBeEntry = new BibEntry(); | ||
shouldBeEntry.setType("Inproceedings"); | ||
|
||
try (InputStream inStream = new ByteArrayInputStream(testInput.getBytes())) { | ||
List<BibEntry> entries = inspecImp.importEntries(inStream, new OutputPrinterToNull()); | ||
assertEquals(1, entries.size()); | ||
BibEntry entry = entries.get(0); | ||
BibtexEntryAssert.assertEquals(shouldBeEntry, entry); | ||
} | ||
} | ||
|
||
@Test | ||
public void importMiscGivesMisc() throws IOException { | ||
String testInput = "Record.*INSPEC.*\n" + | ||
"\n" + | ||
"RT ~ Misc"; | ||
BibEntry shouldBeEntry = new BibEntry(); | ||
shouldBeEntry.setType("Misc"); | ||
|
||
try (InputStream inStream = new ByteArrayInputStream(testInput.getBytes())) { | ||
List<BibEntry> entries = inspecImp.importEntries(inStream, new OutputPrinterToNull()); | ||
assertEquals(1, entries.size()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use BibtexEntryAssert.assertEquals(Collections.singletonList(shouldbeEntry), entries); |
||
BibEntry entry = entries.get(0); | ||
BibtexEntryAssert.assertEquals(shouldBeEntry, entry); | ||
} | ||
} | ||
|
||
@Test | ||
public void testGetFormatName() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "testGetFormatName failed" can be removed (it doesn't add any information...) same below There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please fix this |
||
assertEquals("INSPEC", inspecImp.getFormatName()); | ||
} | ||
|
||
@Test | ||
public void testGetCLIId() { | ||
assertEquals("inspec", inspecImp.getCLIId()); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Record.testINSPEC.test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Record.*INSPEC.* | ||
|
||
TI ~ The SIS project : software reuse with a natural language approach | ||
AU ~ Prechelt, Lutz | ||
AB ~ Abstrakt | ||
PU ~ Karlsruhe : Universitat Karlsruhe, Fakultat fur Informatik | ||
PY ~ 10000 | ||
SO ~ 10000. 1992; 19: 20 | ||
ID ~ key | ||
RT ~ Journal-Paper | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
this should fail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace this with BibtexEntryAssert.assertEquals(Arrays.ListOf(shouldBeEntry), entries).