Skip to content

Commit

Permalink
Use BibtexEntryAssert for CopacImporterTest
Browse files Browse the repository at this point in the history
  • Loading branch information
zesaro committed Apr 4, 2016
1 parent 82da2ab commit 2773bf5
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.sf.jabref.importer.fileformat;

import net.sf.jabref.*;
import net.sf.jabref.bibtex.BibtexEntryAssert;
import net.sf.jabref.importer.OutputPrinterToNull;
import net.sf.jabref.model.entry.BibEntry;
import org.junit.Assert;
Expand Down Expand Up @@ -72,71 +73,38 @@ public void testImportEntries() throws IOException {

CopacImporter importer = new CopacImporter();

try (InputStream stream = CopacImporterTest.class.getResourceAsStream("CopacImporterTest1.txt")) {
List<BibEntry> entries = importer.importEntries(stream, new OutputPrinterToNull());
Assert.assertEquals(1, entries.size());
try (InputStream is = CopacImporter.class.getResourceAsStream("CopacImporterTest1.txt");
InputStream bibis = CopacImporter.class.getResourceAsStream("CopacImporterTest1.bib")) {
List<BibEntry> entries = importer.importEntries(is, new OutputPrinterToNull());
Assert.assertFalse(entries.isEmpty());

BibEntry entry = entries.get(0);

Assert.assertEquals("The SIS project : software reuse with a natural language approach",
entry.getField("title"));
Assert.assertEquals("Prechelt, Lutz and Universität Karlsruhe. Fakultät für Informatik",
entry.getField("author"));
Assert.assertEquals("Interner Bericht ; Nr.2/92", entry.getField("series"));
Assert.assertEquals("1992", entry.getField("year"));
Assert.assertEquals("Karlsruhe : Universitat Karlsruhe, Fakultat fur Informatik",
entry.getField("publisher"));
Assert.assertEquals("Edinburgh", entry.getField("HL"));
Assert.assertEquals("TXT", entry.getField("documenttype"));
Assert.assertEquals("book", entry.getType());
BibtexEntryAssert.assertEquals(bibis, entry);
}
}
}

@Test
public void testImportEntries2() throws IOException {
Globals.prefs.put("defaultEncoding", StandardCharsets.UTF_8.name());

CopacImporter importer = new CopacImporter();

try (InputStream stream = CopacImporterTest.class.getResourceAsStream("CopacImporterTest2.txt")) {
List<BibEntry> entries = importer.importEntries(stream, new OutputPrinterToNull());
Assert.assertEquals(2, entries.size());
BibEntry one = entries.get(0);

Assert.assertEquals("Computing and operational research at the London Hospital", one.getField("title"));
Assert.assertEquals("Barber, Barry and Abbott, W.", one.getField("author"));
Assert.assertEquals("Computers in medicine series", one.getField("series"));
Assert.assertEquals("London : Butterworths", one.getField("publisher"));
Assert.assertEquals("x, 102p, leaf : ill., form, port ; 22cm", one.getField("physicaldimensions"));
Assert.assertEquals("0407517006 (Pbk)", one.getField("isbn"));
Assert.assertEquals("Bibl.p.94-97. - Index", one.getField("note"));
Assert.assertEquals(
"London Hospital and Medical College, Electronic data processing - Medicine, Computers - Hospital administration, Hospital planning, Operations research, Hospital equipment and supplies, Electronic data processing - Hospitals - Administration, Hospitals, London, London Hospital and Medical College, Records management, Applications of computer systems, to 1971",
one.getField("keywords"));
Assert.assertEquals("TXT, PDF", one.getField("documenttype"));
Assert.assertEquals(
"Aberdeen ; Birmingham ; Edinburgh ; Trinity College Dublin ; UCL (University College London)",
one.getField("HL"));

Assert.assertEquals("book", one.getType());

BibEntry two = entries.get(1);

Assert.assertEquals("Real time systems : management and design", two.getField("title"));
Assert.assertEquals("Tebbs, David and Collins, Garfield", two.getField("author"));
Assert.assertEquals("London ; New York : McGraw-Hill", two.getField("publisher"));
Assert.assertEquals("1977", two.getField("year"));
Assert.assertEquals("ix, 357p : ill., forms ; 24cm", two.getField("physicaldimensions"));
Assert.assertEquals("0070844828", two.getField("isbn"));
Assert.assertEquals("Index", two.getField("note"));
Assert.assertEquals("Real-time data processing - Management, Real time computer systems, Design",
two.getField("keywords"));
Assert.assertEquals("TXT, PDF", two.getField("documenttype"));
Assert.assertEquals(
"Aberdeen ; Birmingham ; Edinburgh ; Imperial College ; Liverpool ; Manchester ; Oxford ; Trinity College Dublin",
two.getField("HL"));

Assert.assertEquals("book", two.getType());
try (InputStream is = CopacImporter.class.getResourceAsStream("CopacImporterTest2.txt");
InputStream bibis1 = CopacImporter.class.getResourceAsStream("CopacImporterTest21.bib");
InputStream bibis2 = CopacImporter.class.getResourceAsStream("CopacImporterTest22.bib")) {
List<BibEntry> entries = importer.importEntries(is, new OutputPrinterToNull());
Assert.assertFalse(entries.isEmpty());

BibEntry entry1 = entries.get(0);
BibEntry entry2 = entries.get(1);

BibtexEntryAssert.assertEquals(bibis1, entry1);
BibtexEntryAssert.assertEquals(bibis2, entry2);
}
}


@Test
public void testImportEmptyEntries() throws IOException {
CopacImporter importer = new CopacImporter();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@Book{,
title = {The SIS project : software reuse with a natural language approach},
publisher = {Karlsruhe : Universitat Karlsruhe, Fakultat fur Informatik},
year = {1992},
author = {Prechelt, Lutz and Universität Karlsruhe. Fakultät für Informatik},
series = {Interner Bericht ; Nr.2/92},
documenttype = {TXT},
hl = {Edinburgh}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ TI- The SIS project : software reuse with a natural language approach
AU- Prechelt, Lutz
AU- Universität Karlsruhe. Fakultät für Informatik
SE- Interner Bericht ; Nr.2/92
PU- Karlsruhe : Universitat Karlsruhe, Fakultat fur Informatik
PU- Karlsruhe : Universitat Karlsruhe, Fakultat fur Informatik
PY- 1992
HL- Edinburgh
DT- TXT
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TI- Computing and operational research at the London Hospital
AU- Barber, Barry
AU- Abbott, W.
SE- Computers in medicine series
PU- London : Butterworths
PU- London : Butterworths
PY- 1972
PD- x, 102p, leaf : ill., form, port ; 22cm
IS- 0407517006 (Pbk)
Expand All @@ -24,7 +24,7 @@ DT- PDF
TI- Real time systems : management and design
AU- Tebbs, David
AU- Collins, Garfield
PU- London ; New York : McGraw-Hill
PU- London ; New York : McGraw-Hill
PY- 1977
PD- ix, 357p : ill., forms ; 24cm
IS- 0070844828
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@Book{,
title = {Computing and operational research at the London Hospital},
publisher = {London : Butterworths},
year = {1972},
author = {Barber, Barry and Abbott, W.},
series = {Computers in medicine series},
note = {Bibl.p.94-97. - Index},
documenttype = {TXT, PDF},
hl = {Aberdeen ; Birmingham ; Edinburgh ; Trinity College Dublin ; UCL (University College London)},
isbn = {0407517006 (Pbk)},
keywords = {London Hospital and Medical College, Electronic data processing - Medicine, Computers - Hospital administration, Hospital planning, Operations research, Hospital equipment and supplies, Electronic data processing - Hospitals - Administration, Hospitals, London, London Hospital and Medical College, Records management, Applications of computer systems, to 1971},
physicaldimensions = {x, 102p, leaf : ill., form, port ; 22cm}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@Book{,
title = {Real time systems : management and design},
publisher = {London ; New York : McGraw-Hill},
year = {1977},
author = {Tebbs, David and Collins, Garfield},
note = {Index},
documenttype = {TXT, PDF},
hl = {Aberdeen ; Birmingham ; Edinburgh ; Imperial College ; Liverpool ; Manchester ; Oxford ; Trinity College Dublin},
isbn = {0070844828},
keywords = {Real-time data processing - Management, Real time computer systems, Design},
physicaldimensions = {ix, 357p : ill., forms ; 24cm}
}

0 comments on commit 2773bf5

Please sign in to comment.