diff --git a/src/test/java/net/sf/jabref/importer/fileformat/CopacImporterTest.java b/src/test/java/net/sf/jabref/importer/fileformat/CopacImporterTest.java index f56c4a2ff91..e075c40fa62 100644 --- a/src/test/java/net/sf/jabref/importer/fileformat/CopacImporterTest.java +++ b/src/test/java/net/sf/jabref/importer/fileformat/CopacImporterTest.java @@ -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; @@ -72,71 +73,38 @@ public void testImportEntries() throws IOException { CopacImporter importer = new CopacImporter(); - try (InputStream stream = CopacImporterTest.class.getResourceAsStream("CopacImporterTest1.txt")) { - List 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 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 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 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(); diff --git a/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest1.bib b/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest1.bib new file mode 100644 index 00000000000..5a87e6f42f6 --- /dev/null +++ b/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest1.bib @@ -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} +} \ No newline at end of file diff --git a/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest1.txt b/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest1.txt index eddd70550e6..f87626ad352 100644 --- a/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest1.txt +++ b/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest1.txt @@ -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 diff --git a/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest2.txt b/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest2.txt index eb3d8d89cba..5f05c1d504a 100644 --- a/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest2.txt +++ b/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest2.txt @@ -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) @@ -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 diff --git a/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest21.bib b/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest21.bib new file mode 100644 index 00000000000..aad837bf081 --- /dev/null +++ b/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest21.bib @@ -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} +} \ No newline at end of file diff --git a/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest22.bib b/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest22.bib new file mode 100644 index 00000000000..310988c4709 --- /dev/null +++ b/src/test/resources/net/sf/jabref/importer/fileformat/CopacImporterTest22.bib @@ -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} +} \ No newline at end of file