-
-
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.
- Loading branch information
Christoph_Br4un
committed
Mar 13, 2016
1 parent
eb26ff3
commit 3a0e16e
Showing
6 changed files
with
135 additions
and
2 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
118 changes: 118 additions & 0 deletions
118
src/test/java/net/sf/jabref/importer/fileformat/InspecImportTest.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 |
---|---|---|
@@ -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 { | ||
|
||
//create the correct BibEntry | ||
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"; | ||
try (InputStream inStream = new ByteArrayInputStream(testInput.getBytes())) { | ||
List<BibEntry> entries = inspecImp.importEntries(inStream, new OutputPrinterToNull()); | ||
inStream.close(); | ||
assertEquals(1, entries.size()); | ||
BibEntry entry = entries.get(0); | ||
assertEquals(BibtexEntryTypes.INPROCEEDINGS.getName().toLowerCase(), entry.getType()); | ||
} | ||
} | ||
|
||
@Test | ||
public void importMiscGivesMisc() throws IOException { | ||
String testInput = "Record.*INSPEC.*\n" + | ||
"\n" + | ||
"RT ~ Misc"; | ||
try (InputStream inStream = new ByteArrayInputStream(testInput.getBytes())) { | ||
List<BibEntry> entries = inspecImp.importEntries(inStream, new OutputPrinterToNull()); | ||
assertEquals(1, entries.size()); | ||
BibEntry entry = entries.get(0); | ||
assertEquals(BibtexEntryTypes.MISC.getName().toLowerCase(), entry.getType()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testGetFormatName() { | ||
assertEquals("INSPEC", inspecImp.getFormatName()); | ||
} | ||
|
||
@Test | ||
public void testGetCLIId() { | ||
assertEquals("inspec", inspecImp.getCLIId()); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
src/test/resources/net/sf/jabref/importer/fileformat/InspecImportTest.txt
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Record.testINSPEC.test |
11 changes: 11 additions & 0 deletions
11
src/test/resources/net/sf/jabref/importer/fileformat/InspecImportTest2.txt
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 |
---|---|---|
@@ -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 | ||
|
1 change: 1 addition & 0 deletions
1
src/test/resources/net/sf/jabref/importer/fileformat/InspecImportTestFalse.txt
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
this should fail |