Skip to content

Commit

Permalink
Removed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
zesaro committed Nov 13, 2015
2 parents 9a02def + 1349582 commit c722b6e
Showing 1 changed file with 102 additions and 82 deletions.
184 changes: 102 additions & 82 deletions src/test/java/net/sf/jabref/importer/fileformat/CopacImporterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import org.junit.rules.ExpectedException;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class CopacImporterTest {
Expand Down Expand Up @@ -48,35 +51,49 @@ public void testGetCLIId() {
Assert.assertEquals("cpc", importer.getCLIId());
}

/**
* Test cases for Accepted File Formats.
*
* @throws IOException
*/
@Test
public void testIsRecognizedFormat() throws IOException {

public void testIsRecognizedFormatAccept() throws IOException {
CopacImporter importer = new CopacImporter();
Assert.assertTrue(
importer.isRecognizedFormat(CopacImporterTest.class.getResourceAsStream("CopacImporterTest1.txt")));

Assert.assertTrue(
importer.isRecognizedFormat(CopacImporterTest.class.getResourceAsStream("CopacImporterTest2.txt")));

Assert.assertFalse(
importer.isRecognizedFormat(CopacImporterTest.class.getResourceAsStream("CopacImporterTest3.txt")));

Assert.assertFalse(importer.isRecognizedFormat(CopacImporterTest.class.getResourceAsStream("IEEEImport1.txt")));

Assert.assertFalse(
importer.isRecognizedFormat(CopacImporterTest.class.getResourceAsStream("IsiImporterTest1.isi")));
List<String> list = new LinkedList<>();
list.add("CopacImporterTest1.txt");
list.add("CopacImporterTest2.txt");

Assert.assertFalse(
importer.isRecognizedFormat(CopacImporterTest.class.getResourceAsStream("IsiImporterTestInspec.isi")));

Assert.assertFalse(
importer.isRecognizedFormat(CopacImporterTest.class.getResourceAsStream("IsiImporterTestWOS.isi")));
for (String str : list) {
try (InputStream is = CopacImporterTest.class.getResourceAsStream(str)) {
Assert.assertTrue(importer.isRecognizedFormat(is));
}
}
}

Assert.assertFalse(
importer.isRecognizedFormat(CopacImporterTest.class.getResourceAsStream("IsiImporterTestMedline.isi")));
/**
* Test cases for Rejected File Formats.
*
* @throws IOException
*/
@Test
public void testIsRecognizedFormatReject() throws IOException {
CopacImporter importer = new CopacImporter();

Assert.assertFalse(
importer.isRecognizedFormat(CopacImporterTest.class.getResourceAsStream("RisImporterTest1.ris")));
List<String> list = new LinkedList<>();
list.add("CopacImporterTest3.txt");
list.add("IEEEImport1.txt");
list.add("IsiImporterTest1.isi");
list.add("IsiImporterTestInspec.isi");
list.add("IsiImporterTestWOS.isi");
list.add("IsiImporterTestMedline.isi");
list.add("RisImporterTest1.ris");

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

@Test
Expand All @@ -85,76 +102,79 @@ public void testImportEntries() throws IOException {

CopacImporter importer = new CopacImporter();

List<BibtexEntry> entries = importer.importEntries(
CopacImporterTest.class.getResourceAsStream("CopacImporterTest1.txt"), new OutputPrinterToNull());
Assert.assertEquals(1, entries.size());
BibtexEntry 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(BibtexEntryTypes.BOOK, entry.getType());
try (InputStream is = CopacImporterTest.class.getResourceAsStream("CopacImporterTest1.txt")) {
List<BibtexEntry> entries = importer.importEntries(is, new OutputPrinterToNull());
Assert.assertEquals(1, entries.size());
BibtexEntry 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(BibtexEntryTypes.BOOK, entry.getType());
}
}

@Test
public void testImportEntries2() throws IOException {
CopacImporter importer = new CopacImporter();

List<BibtexEntry> entries = importer.importEntries(
CopacImporterTest.class.getResourceAsStream("CopacImporterTest2.txt"), new OutputPrinterToNull());
Assert.assertEquals(2, entries.size());

BibtexEntry 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(BibtexEntryTypes.BOOK, one.getType());

BibtexEntry 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(BibtexEntryTypes.BOOK, two.getType());
try (InputStream stream = CopacImporterTest.class.getResourceAsStream("CopacImporterTest2.txt")) {
List<BibtexEntry> entries = importer.importEntries(stream, new OutputPrinterToNull());
Assert.assertEquals(2, entries.size());
BibtexEntry 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(BibtexEntryTypes.BOOK, one.getType());

BibtexEntry 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(BibtexEntryTypes.BOOK, two.getType());
}
}

@Test
public void testImportEntries3() throws IOException {
CopacImporter importer = new CopacImporter();

//CopacImporterTest3.txt is an empty file.
List<BibtexEntry> entries = importer.importEntries(
CopacImporterTest.class.getResourceAsStream("CopacImporterTest3.txt"), new OutputPrinterToNull());
Assert.assertEquals(0, entries.size());
try (InputStream is = CopacImporterTest.class.getResourceAsStream("CopacImporterTest3.txt")) {
List<BibtexEntry> entries = importer.importEntries(is, new OutputPrinterToNull());
Assert.assertEquals(0, entries.size());
Assert.assertEquals(Collections.emptyList(), entries);
}
}
}

0 comments on commit c722b6e

Please sign in to comment.