Skip to content

Commit

Permalink
Merging previous commits together
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph_Br4un committed Mar 13, 2016
1 parent eb26ff3 commit 3a0e16e
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by
- IEEEXplore fetcher replaces keyword separator with the preferred
- Fixed [#710](https://github.com/JabRef/jabref/issues/710): Fixed quit behaviour under OSX
- Merge from DOI now honors removed fields
- Fixed whitespace handling in year and volume in InspecImporter
- Fixed [#778](https://github.com/JabRef/jabref/issues/778): Fixed NPE when exporting to .sql File
- Fixed [#824](https://github.com/JabRef/jabref/issues/824): MimeTypeDetector can now also handle local file links
- Fixed [#803](https://github.com/JabRef/jabref/issues/803): Fixed dynamically group, free-form search
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,15 @@ public List<BibEntry> importEntries(InputStream stream, OutputPrinter status) th
frest = frest.substring(m);
m = frest.indexOf(';');
if (m >= 5) {
String yr = frest.substring(m - 5, m);
String yr = frest.substring(m - 5, m).trim();
h.put("year", yr);
frest = frest.substring(m);
m = frest.indexOf(':');
if (m >= 0) {
String pg = frest.substring(m + 1).trim();
h.put("pages", pg);
h.put("volume", frest.substring(1, m));
String vol = frest.substring(1, m).trim();
h.put("volume", vol);
}
}
}
Expand Down
118 changes: 118 additions & 0 deletions src/test/java/net/sf/jabref/importer/fileformat/InspecImportTest.java
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());
}

}
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

0 comments on commit 3a0e16e

Please sign in to comment.