Skip to content
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

Endnote importer test #321

Merged
merged 1 commit into from
Jan 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package net.sf.jabref.importer.fileformat;

import net.sf.jabref.Globals;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.importer.OutputPrinterToNull;
import net.sf.jabref.model.entry.BibEntry;
import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.*;


public class EndnoteImporterTest {

EndnoteImporter importer;

@Before
public void setUp() {
Globals.prefs = JabRefPreferences.getInstance();
importer = new EndnoteImporter();
}

@Test
public void testGetFormatName() {
assertEquals("Refer/Endnote", importer.getFormatName());
}

@Test
public void testGetCLIId() {
assertEquals("refer", importer.getCLIId());
}

@Test
public void testIsRecognizedFormat() throws IOException {
List<String> list = Arrays.asList("Endnote.pattern.A.enw", "Endnote.pattern.E.enw", "Endnote.book.example.enw");

for (String str : list) {
try (InputStream is = EndnoteImporterTest.class.getResourceAsStream(str)) {
assertTrue(importer.isRecognizedFormat(is));
}
}
}

@Test
public void testIsRecognizedFormatReject() throws IOException {
List<String> list = Arrays.asList("IEEEImport1.txt", "IsiImporterTest1.isi", "IsiImporterTestInspec.isi",
"IsiImporterTestWOS.isi", "IsiImporterTestMedline.isi", "RisImporterTest1.ris",
"Endnote.pattern.no_enw", "empty.pdf", "annotated.pdf");

for (String str : list) {
try (InputStream is = EndnoteImporterTest.class.getResourceAsStream(str)) {
assertFalse(importer.isRecognizedFormat(is));
}
}
}

@Test
public void testImportEntries0() throws IOException {
try (InputStream is = EndnoteImporterTest.class.getResourceAsStream("Endnote.entries.enw")) {
List<BibEntry> bibEntries = importer.importEntries(is, new OutputPrinterToNull());

assertEquals(5, bibEntries.size());

BibEntry be0 = bibEntries.get(0);
assertEquals("Misc", be0.getType().getName());
assertEquals("testA0 and testA1", be0.getField("author"));
assertEquals("testE0 and testE1", be0.getField("editor"));
assertEquals("testT", be0.getField("title"));

BibEntry be1 = bibEntries.get(1);
assertEquals("Misc", be1.getType().getName());
assertEquals("testC", be1.getField("address"));
assertEquals("testB2", be1.getField("booktitle"));
assertEquals("test8", be1.getField("date"));
assertEquals("test7", be1.getField("edition"));
assertEquals("testJ", be1.getField("journal"));
assertEquals("testD", be1.getField("year"));

BibEntry be2 = bibEntries.get(2);
assertEquals("Article", be2.getType().getName());
assertEquals("testB0", be2.getField("journal"));

BibEntry be3 = bibEntries.get(3);
assertEquals("Book", be3.getType().getName());
assertEquals("testI0", be3.getField("publisher"));
assertEquals("testB1", be3.getField("series"));

BibEntry be4 = bibEntries.get(4);
assertEquals("MastersThesis", be4.getType().getName());
assertEquals("testX", be4.getField("abstract"));
assertEquals("testF", be4.getField("bibtexkey"));
assertEquals("testR", be4.getField("doi"));
assertEquals("testK", be4.getField("keywords"));
assertEquals("testO1", be4.getField("note"));
assertEquals("testN", be4.getField("number"));
assertEquals("testP", be4.getField("pages"));
assertEquals("testI1", be4.getField("school"));
assertEquals("testU", be4.getField("url"));
assertEquals("testV", be4.getField("volume"));
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split this in 3 different tests.

@Test
public void testImportEntries1() throws IOException {
String s = "%O Artn\\\\s testO\n%A testA,\n%E testE0, testE1";
InputStream is = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
List<BibEntry> bibEntries = importer.importEntries(is, new OutputPrinterToNull());

assertEquals(1, bibEntries.size());

BibEntry be = bibEntries.get(0);
assertEquals("Misc", be.getType().getName());
assertEquals("testA", be.getField("author"));
assertEquals("testE0, testE1", be.getField("editor"));
assertEquals("testO", be.getField("pages"));
}

@Test
public void testImportEntriesBookExample() throws IOException {
try (InputStream is = EndnoteImporterTest.class.getResourceAsStream("Endnote.book.example.enw")) {
List<BibEntry> bibEntries = importer.importEntries(is, new OutputPrinterToNull());

assertEquals(1, bibEntries.size());

BibEntry be = bibEntries.get(0);
assertEquals("Book", be.getType().getName());
assertEquals("Heidelberg", be.getField("address"));
assertEquals("Preißel, René and Stachmann, Bjørn", be.getField("author"));
assertEquals("3., aktualisierte und erweiterte Auflage", be.getField("edition"));
assertEquals("Versionsverwaltung", be.getField("keywords"));
assertEquals("XX, 327", be.getField("pages"));
assertEquals("dpunkt.verlag", be.getField("publisher"));
assertEquals("Git : dezentrale Versionsverwaltung im Team : Grundlagen und Workflows", be.getField("title"));
assertEquals("http://d-nb.info/107601965X", be.getField("url"));
assertEquals("2016", be.getField("year"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%0 Book
%A Preißel, René
%A Stachmann, Bjørn
%C Heidelberg
%D 2016
%I dpunkt.verlag
%K Versionsverwaltung
%L 6H 1249(3)
%P XX, 327
%T Git : dezentrale Versionsverwaltung im Team : Grundlagen und Workflows
%U http://d-nb.info/107601965X
%7 3., aktualisierte und erweiterte Auflage
%@ 978-3-86490-311-3
%[ 20151028
%= 20151125
%1 UB Vaihingen (geschlossen: 24.12.15 - 3.1.16)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
%0
%A testA0
%A testA1
%E testE0
%E testE1
%T testT
%0 Journal
%0 Book Section
%0 Book
%0 Edited Book
%0 Conference
%0 Report
%0 Review
%0 Thesis
%0 Test0
%7 test7
%C testC
%D testD
%8 test8
%J testJ
%J testJ1
%B testB2
%0 Journal
%B testB0
%0 Book
%B testB1
%I testI0
%0 Thesis
%I testI1
%P testP
%V testV
%N testN
%U testU
%R testRw
%R doi:testR
%O Artn \\s testO0
%O testO1
%K testK
%X testX
%9 Ph.D.
%9 Masters
%F testF
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%A testA
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%E testE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%0