From fafc402755199a1c29983c40b81d123e6a0bc2ab Mon Sep 17 00:00:00 2001 From: Stanley F Date: Thu, 5 Sep 2019 14:02:05 +0200 Subject: [PATCH 1/3] Unify month field formatting in test bib files (fixes JabRef/jabref#5116) --- .../logic/exporter/BibTeXMLExporter.java | 15 ++++++++++++++ .../importer/fileformat/BibTeXMLImporter.java | 17 +++++++++++++++- .../importer/fileformat/BibtexParser.java | 6 +++++- .../importer/fileformat/MedlineImporter.java | 7 ++++++- .../java/org/jabref/model/entry/Month.java | 2 +- .../logic/bibtex/BibEntryWriterTest.java | 2 +- .../logic/cleanup/CleanupWorkerTest.java | 2 +- .../cleanup/ConvertToBibtexCleanupTest.java | 2 +- .../NormalizeMonthFormatterTest.java | 2 +- .../importer/fileformat/IsiImporterTest.java | 20 +++++++++---------- .../org/jabref/model/entry/BibEntryTests.java | 6 +++--- .../exporter/BibTeXMLExporterTestArticle.bib | 2 +- .../BibTeXMLExporterTestArticleWithoutID.bib | 2 +- .../exporter/BibTeXMLExporterTestBook.bib | 2 +- .../exporter/BibTeXMLExporterTestBooklet.bib | 2 +- .../BibTeXMLExporterTestConference.bib | 2 +- .../exporter/BibTeXMLExporterTestInBook.bib | 2 +- .../BibTeXMLExporterTestInCollection.bib | 2 +- .../BibTeXMLExporterTestInProceedings.bib | 2 +- .../BibTeXMLExporterTestInbookLessFields.bib | 2 +- .../exporter/BibTeXMLExporterTestManual.bib | 2 +- .../BibTeXMLExporterTestMasterThesis.bib | 2 +- .../exporter/BibTeXMLExporterTestMisc.bib | 2 +- .../BibTeXMLExporterTestPhdThesis.bib | 2 +- .../BibTeXMLExporterTestProceedings.bib | 2 +- .../BibTeXMLExporterTestTechReport.bib | 2 +- .../BibTeXMLExporterTestUnpublished.bib | 2 +- .../BibTeXMLImporterTestArticle.bib | 2 +- .../BibTeXMLImporterTestArticle2.bib | 2 +- .../BibTeXMLImporterTestArticleWithoutID.bib | 2 +- .../fileformat/BibTeXMLImporterTestBook.bib | 2 +- .../BibTeXMLImporterTestBooklet.bib | 2 +- .../BibTeXMLImporterTestConference.bib | 2 +- .../fileformat/BibTeXMLImporterTestInBook.bib | 2 +- .../BibTeXMLImporterTestInCollection.bib | 2 +- .../BibTeXMLImporterTestInProceedings.bib | 2 +- .../BibTeXMLImporterTestInbookLessFields.bib | 2 +- ...ImporterTestIncollectionWithoutChapter.bib | 2 +- .../fileformat/BibTeXMLImporterTestManual.bib | 2 +- .../BibTeXMLImporterTestMasterThesis.bib | 2 +- .../fileformat/BibTeXMLImporterTestMisc.bib | 2 +- .../BibTeXMLImporterTestPhdThesis.bib | 2 +- .../BibTeXMLImporterTestProceedings.bib | 2 +- .../BibTeXMLImporterTestTechReport.bib | 2 +- .../BibTeXMLImporterTestUnpublished.bib | 2 +- .../MedlineImporterTestArticleID.bib | 2 +- .../MedlineImporterTestArticleNoISSN.bib | 2 +- .../MedlineImporterTestBookArticleSet.bib | 2 +- .../fileformat/MedlineImporterTestNbib.bib | 2 +- .../MedlineImporterTestPubmedBook.bib | 2 +- .../jabref/logic/xmp/article_dublinCore.bib | 2 +- src/test/resources/org/jabref/util/twente.bib | 2 +- src/test/resources/testbib/jabref-authors.bib | 14 ++++++------- src/test/resources/testbib/saveactions2.bib | 4 ++-- .../resources/testbib/testjabref_210as292.bib | 10 +++++----- src/test/resources/testbib/testjabref_292.bib | 10 +++++----- 56 files changed, 120 insertions(+), 81 deletions(-) diff --git a/src/main/java/org/jabref/logic/exporter/BibTeXMLExporter.java b/src/main/java/org/jabref/logic/exporter/BibTeXMLExporter.java index 2c0100b5f12..1e5b6b310ca 100644 --- a/src/main/java/org/jabref/logic/exporter/BibTeXMLExporter.java +++ b/src/main/java/org/jabref/logic/exporter/BibTeXMLExporter.java @@ -10,6 +10,7 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.stream.Collectors; import javax.xml.bind.JAXBContext; @@ -40,6 +41,7 @@ import org.jabref.logic.util.StandardFileType; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.Month; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.EntryType; @@ -153,6 +155,13 @@ private void parseInbook(Inbook inbook, BibEntry bibEntry, Entry entry) { JAXBElement number = new JAXBElement<>(new QName(BIBTEXML_NAMESPACE_URI, "number"), BigInteger.class, new BigInteger(value)); inbook.getContent().add(number); + } else if (StandardField.MONTH.equals(key)) { + Optional month = bibEntry.getMonth(); + if (month.isPresent()) { + JAXBElement element = new JAXBElement<>(new QName(BIBTEXML_NAMESPACE_URI, key.getName()), + String.class, month.get().getFullName()); + inbook.getContent().add(element); + } } else { JAXBElement element = new JAXBElement<>(new QName(BIBTEXML_NAMESPACE_URI, key.getName()), String.class, value); @@ -205,6 +214,12 @@ private void parse(T entryType, BibEntry bibEntry, Entry entry) { LOGGER.warn("The value %s of the 'number' field is not an integer and thus is ignored for the export", value); } break; + } else if (StandardField.MONTH.equals(key)) { + Optional month = bibEntry.getMonth(); + if (month.isPresent()) { + method.invoke(entryType, month.get().getFullName()); + } + break; } else { method.invoke(entryType, value); break; diff --git a/src/main/java/org/jabref/logic/importer/fileformat/BibTeXMLImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/BibTeXMLImporter.java index 7465b5c3a8c..24293c6ec2e 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/BibTeXMLImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/BibTeXMLImporter.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.regex.Pattern; import javax.xml.bind.JAXBContext; @@ -27,6 +28,7 @@ import org.jabref.logic.importer.fileformat.bibtexml.Incollection; import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.Month; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; import org.jabref.model.entry.field.StandardField; @@ -176,6 +178,9 @@ private void parse(T entryType, Map fields) { } else if (method.getName().equals("getNumber")) { putNumber(fields, (BigInteger) method.invoke(entryType)); continue; + } else if (method.getName().equals("getMonth")) { + putMonth(fields, Month.parse((String)method.invoke(entryType))); + continue; } else if (isMethodToIgnore(method.getName())) { continue; } else if (method.getName().startsWith("get")) { @@ -208,7 +213,11 @@ private void parseInbook(Inbook inbook, Map fields) { Object elementValue = element.getValue(); if (elementValue instanceof String) { String value = (String) elementValue; - putIfValueNotNull(fields, field, value); + if (StandardField.MONTH.equals(field)) { + putMonth(fields, Month.parse(value)); + } else { + putIfValueNotNull(fields, field, value); + } } else if (elementValue instanceof BigInteger) { BigInteger value = (BigInteger) elementValue; if (StandardField.NUMBER.equals(field)) { @@ -241,6 +250,12 @@ private void putNumber(Map fields, BigInteger number) { } } + private void putMonth(Map fields, Optional month) { + if (month.isPresent()) { + fields.put(StandardField.MONTH, month.get().getJabRefFormat()); + } + } + private void putIfValueNotNull(Map fields, Field field, String value) { if (value != null) { fields.put(field, value); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java b/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java index 3cdfa7e10e1..eb7fd730852 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java @@ -614,7 +614,11 @@ private String parseFieldContent(Field field) throws IOException { throw new IOException("Error in line " + line + " or above: " + "Empty text token.\nThis could be caused " + "by a missing comma between two fields."); } - value.append('#').append(textToken).append('#'); + if (field != StandardField.MONTH) { + value.append('#').append(textToken).append('#'); + } else { + value.append(textToken); + } } skipWhitespace(); } diff --git a/src/main/java/org/jabref/logic/importer/fileformat/MedlineImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/MedlineImporter.java index bc8feb039f0..c37038bbb81 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/MedlineImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/MedlineImporter.java @@ -13,6 +13,7 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; +import java.util.Optional; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; @@ -74,6 +75,7 @@ import org.jabref.logic.importer.fileformat.medline.Text; import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.Month; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; import org.jabref.model.entry.field.InternalField; @@ -603,7 +605,10 @@ private void addPubDate(Map fields, PubDate pubDate) { } else { fields.put(StandardField.YEAR, pubDate.getYear()); if (pubDate.getMonth() != null) { - fields.put(StandardField.MONTH, pubDate.getMonth()); + Optional month = Month.parse(pubDate.getMonth()); + if (month.isPresent()) { + fields.put(StandardField.MONTH, month.get().getJabRefFormat()); + } } else if (pubDate.getSeason() != null) { fields.put(new UnknownField("season"), pubDate.getSeason()); } diff --git a/src/main/java/org/jabref/model/entry/Month.java b/src/main/java/org/jabref/model/entry/Month.java index 6d6f6fbfe15..101476c9d60 100644 --- a/src/main/java/org/jabref/model/entry/Month.java +++ b/src/main/java/org/jabref/model/entry/Month.java @@ -174,7 +174,7 @@ public String getShortName() { * @return Month in JabRef format */ public String getJabRefFormat() { - return String.format("#%s#", shortName); + return String.format("%s", shortName); } /** diff --git a/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java b/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java index b2e6183c8ed..f91afa630ba 100644 --- a/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java +++ b/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java @@ -416,7 +416,7 @@ void monthFieldSpecialSyntax() throws IOException { // modify month field Set fields = entry.getFields(); assertTrue(fields.contains(StandardField.MONTH)); - assertEquals("#mar#", entry.getField(StandardField.MONTH).get()); + assertEquals("mar", entry.getField(StandardField.MONTH).get()); //write out bibtex string StringWriter stringWriter = new StringWriter(); diff --git a/src/test/java/org/jabref/logic/cleanup/CleanupWorkerTest.java b/src/test/java/org/jabref/logic/cleanup/CleanupWorkerTest.java index 009cce0cb2d..007a179adaa 100644 --- a/src/test/java/org/jabref/logic/cleanup/CleanupWorkerTest.java +++ b/src/test/java/org/jabref/logic/cleanup/CleanupWorkerTest.java @@ -183,7 +183,7 @@ void cleanupMonthChangesNumberToBibtex() { entry.setField(StandardField.MONTH, "01"); worker.cleanup(preset, entry); - assertEquals(Optional.of("#jan#"), entry.getField(StandardField.MONTH)); + assertEquals(Optional.of("jan"), entry.getField(StandardField.MONTH)); } @Test diff --git a/src/test/java/org/jabref/logic/cleanup/ConvertToBibtexCleanupTest.java b/src/test/java/org/jabref/logic/cleanup/ConvertToBibtexCleanupTest.java index 38259aaef2f..d8cdb70ee69 100644 --- a/src/test/java/org/jabref/logic/cleanup/ConvertToBibtexCleanupTest.java +++ b/src/test/java/org/jabref/logic/cleanup/ConvertToBibtexCleanupTest.java @@ -27,7 +27,7 @@ public void cleanupMovesDateToYearAndMonth() { assertEquals(Optional.empty(), entry.getField(StandardField.DATE)); assertEquals(Optional.of("2011"), entry.getField(StandardField.YEAR)); - assertEquals(Optional.of("#jan#"), entry.getField(StandardField.MONTH)); + assertEquals(Optional.of("jan"), entry.getField(StandardField.MONTH)); } @Test diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java index 31c3f935989..1d6ebd292c4 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java @@ -19,6 +19,6 @@ public void setUp() { @Test public void formatExample() { - assertEquals("#dec#", formatter.format(formatter.getExampleInput())); + assertEquals("dec", formatter.format(formatter.getExampleInput())); } } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/IsiImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/IsiImporterTest.java index daa7834214b..6fc0ea874c0 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/IsiImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/IsiImporterTest.java @@ -191,7 +191,7 @@ public void testImportEntriesINSPEC() throws IOException, URISyntaxException { first.getField(StandardField.AUTHOR)); assertEquals(Optional.of("Applied Physics Letters"), first.getField(StandardField.JOURNAL)); assertEquals(Optional.of("2006"), first.getField(StandardField.YEAR)); - assertEquals(Optional.of("#jul#"), first.getField(StandardField.MONTH)); + assertEquals(Optional.of("jul"), first.getField(StandardField.MONTH)); assertEquals(Optional.of("89"), first.getField(StandardField.VOLUME)); assertEquals(Optional.of("4"), first.getField(StandardField.NUMBER)); assertEquals(Optional.of("Lorem ipsum abstract"), first.getField(StandardField.ABSTRACT)); @@ -235,14 +235,14 @@ public void testIsiAuthorsConvert() { @Test public void testMonthConvert() { - assertEquals("#jun#", IsiImporter.parseMonth("06")); - assertEquals("#jun#", IsiImporter.parseMonth("JUN")); - assertEquals("#jun#", IsiImporter.parseMonth("jUn")); - assertEquals("#may#", IsiImporter.parseMonth("MAY-JUN")); - assertEquals("#jun#", IsiImporter.parseMonth("2006 06")); - assertEquals("#jun#", IsiImporter.parseMonth("2006 06-07")); - assertEquals("#jul#", IsiImporter.parseMonth("2006 07 03")); - assertEquals("#may#", IsiImporter.parseMonth("2006 May-Jun")); + assertEquals("jun", IsiImporter.parseMonth("06")); + assertEquals("jun", IsiImporter.parseMonth("JUN")); + assertEquals("jun", IsiImporter.parseMonth("jUn")); + assertEquals("may", IsiImporter.parseMonth("MAY-JUN")); + assertEquals("jun", IsiImporter.parseMonth("2006 06")); + assertEquals("jun", IsiImporter.parseMonth("2006 06-07")); + assertEquals("jul", IsiImporter.parseMonth("2006 07 03")); + assertEquals("may", IsiImporter.parseMonth("2006 May-Jun")); } @Test @@ -334,7 +334,7 @@ public void testImportEntriesMedline() throws IOException, URISyntaxException { "Joffe, Hadine and Hall, Janet E. and Gruber, Staci and Sarmiento, Ingrid A. and Cohen, Lee S. and Yurgelun-Todd, Deborah and Martin, Kathryn A."), second.getField(StandardField.AUTHOR)); assertEquals(Optional.of("2006"), second.getField(StandardField.YEAR)); - assertEquals(Optional.of("#may#"), second.getField(StandardField.MONTH)); + assertEquals(Optional.of("may"), second.getField(StandardField.MONTH)); assertEquals(Optional.of("13"), second.getField(StandardField.VOLUME)); assertEquals(Optional.of("3"), second.getField(StandardField.NUMBER)); assertEquals(Optional.of("411--22"), second.getField(StandardField.PAGES)); diff --git a/src/test/java/org/jabref/model/entry/BibEntryTests.java b/src/test/java/org/jabref/model/entry/BibEntryTests.java index a0e2ee64ad0..586d939a776 100644 --- a/src/test/java/org/jabref/model/entry/BibEntryTests.java +++ b/src/test/java/org/jabref/model/entry/BibEntryTests.java @@ -117,7 +117,7 @@ public void getFieldOrAliasDateWithYearNumericalMonthString() { @Test public void getFieldOrAliasDateWithYearAbbreviatedMonth() { emptyEntry.setField(StandardField.YEAR, "2003"); - emptyEntry.setField(StandardField.MONTH, "#mar#"); + emptyEntry.setField(StandardField.MONTH, "mar"); assertEquals(Optional.of("2003-03"), emptyEntry.getFieldOrAlias(StandardField.DATE)); } @@ -161,13 +161,13 @@ public void getFieldOrAliasMonthWithDateYYYYReturnsNull() { @Test public void getFieldOrAliasMonthWithDateYYYYMM() { emptyEntry.setField(StandardField.DATE, "2003-03"); - assertEquals(Optional.of("#mar#"), emptyEntry.getFieldOrAlias(StandardField.MONTH)); + assertEquals(Optional.of("mar"), emptyEntry.getFieldOrAlias(StandardField.MONTH)); } @Test public void getFieldOrAliasMonthWithDateYYYYMMDD() { emptyEntry.setField(StandardField.DATE, "2003-03-30"); - assertEquals(Optional.of("#mar#"), emptyEntry.getFieldOrAlias(StandardField.MONTH)); + assertEquals(Optional.of("mar"), emptyEntry.getFieldOrAlias(StandardField.MONTH)); } @Test diff --git a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestArticle.bib b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestArticle.bib index f170c7f5e10..8bae7ec117a 100644 --- a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestArticle.bib +++ b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestArticle.bib @@ -6,6 +6,6 @@ @Article{Mustermann2016 journal = {Java Journal}, year = {2016}, pages = {2}, - month = {February}, + month = feb, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestArticleWithoutID.bib b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestArticleWithoutID.bib index b759fbeebf0..8e05175af26 100644 --- a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestArticleWithoutID.bib +++ b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestArticleWithoutID.bib @@ -6,6 +6,6 @@ @Article{ journal = {Java Journal}, year = {2016}, pages = {2}, - month = {February}, + month = feb, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestBook.bib b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestBook.bib index d4b21de4684..fa5079267a5 100644 --- a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestBook.bib +++ b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestBook.bib @@ -6,6 +6,6 @@ @Book{Mustermann2016 year = {2016}, author = {Max Mustermann}, volume = {1}, - month = {February}, + month = feb, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestBooklet.bib b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestBooklet.bib index 3dad334bf5f..ae3762ef13b 100644 --- a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestBooklet.bib +++ b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestBooklet.bib @@ -4,7 +4,7 @@ @Booklet{Mustermann2016 title = {Java Booklet}, author = {Max Mustermann}, address = {Stuttgart}, - month = {February}, + month = feb, year = {2016}, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestConference.bib b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestConference.bib index e7709cedf11..55e24a662f7 100644 --- a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestConference.bib +++ b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestConference.bib @@ -11,7 +11,7 @@ @Conference{Mustermann2016 series = {1}, pages = {3-9}, address = {Stuttgart}, - month = {February}, + month = feb, organization = {Java Org}, publisher = {Java Publisher}, keywords = {java} diff --git a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestInBook.bib b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestInBook.bib index d0e1c4d6686..a3d080037ca 100644 --- a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestInBook.bib +++ b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestInBook.bib @@ -8,6 +8,6 @@ @InBook{Mustermann2016 year = {2016}, author = {Max Mustermann}, volume = {1}, - month = {February}, + month = feb, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestInCollection.bib b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestInCollection.bib index 9fa735acd67..f9e6451fd56 100644 --- a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestInCollection.bib +++ b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestInCollection.bib @@ -11,6 +11,6 @@ @InCollection{Mustermann2016 number = {1}, chapter = {3}, pages = {18-26}, - month = {February}, + month = feb, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestInProceedings.bib b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestInProceedings.bib index 0a9546563d9..a2f650259c1 100644 --- a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestInProceedings.bib +++ b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestInProceedings.bib @@ -5,7 +5,7 @@ @InProceedings{Mustermann2016 title = {Java InProceedings}, booktitle = {Java Book}, year = {2016}, - month = {February}, + month = feb, organization = {Java Org}, publisher = {Java Publisher}, keywords = {java} diff --git a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestInbookLessFields.bib b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestInbookLessFields.bib index 4014194c1b0..1c7c0aa3c7b 100644 --- a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestInbookLessFields.bib +++ b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestInbookLessFields.bib @@ -9,7 +9,7 @@ @InBook{Mustermann2016 series = {1}, address = {Stuttgart}, edition = {10}, - month = {February}, + month = feb, note = {some note}, keywords = {java}, } diff --git a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestManual.bib b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestManual.bib index 21a7961789e..8a4f5228bc8 100644 --- a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestManual.bib +++ b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestManual.bib @@ -5,7 +5,7 @@ @Manual{Mustermann2016 author = {Max Mustermann}, organization = {Java Users}, address = {Stuttgart}, - month = {February}, + month = feb, year = {2016}, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestMasterThesis.bib b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestMasterThesis.bib index 003c2879c6c..54d02f07c16 100644 --- a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestMasterThesis.bib +++ b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestMasterThesis.bib @@ -7,6 +7,6 @@ @MastersThesis{Mustermann2016 year = {2016}, type = {Thesis}, address = {Stuttgart}, - month = {February}, + month = feb, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestMisc.bib b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestMisc.bib index 9101bba68e2..1d67e193341 100644 --- a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestMisc.bib +++ b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestMisc.bib @@ -4,7 +4,7 @@ @Misc{Mustermann2016 author = {Max Mustermann}, title = {Java Misc}, howpublished = {Internet}, - month = {February}, + month = feb, year = {2016}, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestPhdThesis.bib b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestPhdThesis.bib index 6121bc38d24..66707a4015e 100644 --- a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestPhdThesis.bib +++ b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestPhdThesis.bib @@ -7,6 +7,6 @@ @PhdThesis{Mustermann2016 year = {2016}, type = {Thesis}, address = {Stuttgart}, - month = {February}, + month = feb, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestProceedings.bib b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestProceedings.bib index 8d6cbe4c661..c20654b07b9 100644 --- a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestProceedings.bib +++ b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestProceedings.bib @@ -6,6 +6,6 @@ @Proceedings{Musterfrau2016 editor = {Maxima Musterfrau}, address = {Stuttgart}, publisher = {Java Pub}, - month = {February}, + month = feb, organization = {Java Org} } diff --git a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestTechReport.bib b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestTechReport.bib index 1ab28ba275c..d88e3c1335a 100644 --- a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestTechReport.bib +++ b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestTechReport.bib @@ -6,6 +6,6 @@ @TechReport{Mustermann2016 type = {Report}, number = {1}, address = {Stuttgart}, - month = {February}, + month = feb, keywords = {java}, } diff --git a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestUnpublished.bib b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestUnpublished.bib index f1720ddef2b..a3dceb11d4b 100644 --- a/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestUnpublished.bib +++ b/src/test/resources/org/jabref/logic/exporter/BibTeXMLExporterTestUnpublished.bib @@ -3,7 +3,7 @@ @Unpublished{Mustermann2016, author = {Max Mustermann}, title = {Java Unpublished}, - month = {February}, + month = feb, year = {2016}, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestArticle.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestArticle.bib index f170c7f5e10..8bae7ec117a 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestArticle.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestArticle.bib @@ -6,6 +6,6 @@ @Article{Mustermann2016 journal = {Java Journal}, year = {2016}, pages = {2}, - month = {February}, + month = feb, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestArticle2.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestArticle2.bib index 515e1a1367b..580a364c6a3 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestArticle2.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestArticle2.bib @@ -2,7 +2,7 @@ @article{Mustermann2016 author = {Max Mustermann}, journal = {Java Journal}, keywords = {java}, - month = {February}, + month = feb, pages = {2}, title = {Java tricks}, year = {2016} diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestArticleWithoutID.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestArticleWithoutID.bib index b759fbeebf0..8e05175af26 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestArticleWithoutID.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestArticleWithoutID.bib @@ -6,6 +6,6 @@ @Article{ journal = {Java Journal}, year = {2016}, pages = {2}, - month = {February}, + month = feb, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestBook.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestBook.bib index d4b21de4684..fa5079267a5 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestBook.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestBook.bib @@ -6,6 +6,6 @@ @Book{Mustermann2016 year = {2016}, author = {Max Mustermann}, volume = {1}, - month = {February}, + month = feb, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestBooklet.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestBooklet.bib index 3dad334bf5f..ae3762ef13b 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestBooklet.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestBooklet.bib @@ -4,7 +4,7 @@ @Booklet{Mustermann2016 title = {Java Booklet}, author = {Max Mustermann}, address = {Stuttgart}, - month = {February}, + month = feb, year = {2016}, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestConference.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestConference.bib index e7709cedf11..55e24a662f7 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestConference.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestConference.bib @@ -11,7 +11,7 @@ @Conference{Mustermann2016 series = {1}, pages = {3-9}, address = {Stuttgart}, - month = {February}, + month = feb, organization = {Java Org}, publisher = {Java Publisher}, keywords = {java} diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestInBook.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestInBook.bib index d0e1c4d6686..a3d080037ca 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestInBook.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestInBook.bib @@ -8,6 +8,6 @@ @InBook{Mustermann2016 year = {2016}, author = {Max Mustermann}, volume = {1}, - month = {February}, + month = feb, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestInCollection.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestInCollection.bib index 9fa735acd67..f9e6451fd56 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestInCollection.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestInCollection.bib @@ -11,6 +11,6 @@ @InCollection{Mustermann2016 number = {1}, chapter = {3}, pages = {18-26}, - month = {February}, + month = feb, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestInProceedings.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestInProceedings.bib index 0a9546563d9..a2f650259c1 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestInProceedings.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestInProceedings.bib @@ -5,7 +5,7 @@ @InProceedings{Mustermann2016 title = {Java InProceedings}, booktitle = {Java Book}, year = {2016}, - month = {February}, + month = feb, organization = {Java Org}, publisher = {Java Publisher}, keywords = {java} diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestInbookLessFields.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestInbookLessFields.bib index 4014194c1b0..1c7c0aa3c7b 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestInbookLessFields.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestInbookLessFields.bib @@ -9,7 +9,7 @@ @InBook{Mustermann2016 series = {1}, address = {Stuttgart}, edition = {10}, - month = {February}, + month = feb, note = {some note}, keywords = {java}, } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestIncollectionWithoutChapter.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestIncollectionWithoutChapter.bib index b716c95368d..9b8b1626563 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestIncollectionWithoutChapter.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestIncollectionWithoutChapter.bib @@ -9,6 +9,6 @@ @InCollection{Mustermann2016 volume = {1}, number = {1}, pages = {18-26}, - month = {February}, + month = feb, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestManual.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestManual.bib index 21a7961789e..8a4f5228bc8 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestManual.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestManual.bib @@ -5,7 +5,7 @@ @Manual{Mustermann2016 author = {Max Mustermann}, organization = {Java Users}, address = {Stuttgart}, - month = {February}, + month = feb, year = {2016}, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestMasterThesis.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestMasterThesis.bib index 003c2879c6c..54d02f07c16 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestMasterThesis.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestMasterThesis.bib @@ -7,6 +7,6 @@ @MastersThesis{Mustermann2016 year = {2016}, type = {Thesis}, address = {Stuttgart}, - month = {February}, + month = feb, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestMisc.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestMisc.bib index 9101bba68e2..1d67e193341 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestMisc.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestMisc.bib @@ -4,7 +4,7 @@ @Misc{Mustermann2016 author = {Max Mustermann}, title = {Java Misc}, howpublished = {Internet}, - month = {February}, + month = feb, year = {2016}, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestPhdThesis.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestPhdThesis.bib index 6121bc38d24..66707a4015e 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestPhdThesis.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestPhdThesis.bib @@ -7,6 +7,6 @@ @PhdThesis{Mustermann2016 year = {2016}, type = {Thesis}, address = {Stuttgart}, - month = {February}, + month = feb, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestProceedings.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestProceedings.bib index 8d6cbe4c661..c20654b07b9 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestProceedings.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestProceedings.bib @@ -6,6 +6,6 @@ @Proceedings{Musterfrau2016 editor = {Maxima Musterfrau}, address = {Stuttgart}, publisher = {Java Pub}, - month = {February}, + month = feb, organization = {Java Org} } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestTechReport.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestTechReport.bib index 1ab28ba275c..d88e3c1335a 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestTechReport.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestTechReport.bib @@ -6,6 +6,6 @@ @TechReport{Mustermann2016 type = {Report}, number = {1}, address = {Stuttgart}, - month = {February}, + month = feb, keywords = {java}, } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestUnpublished.bib b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestUnpublished.bib index f1720ddef2b..a3dceb11d4b 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestUnpublished.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/BibTeXMLImporterTestUnpublished.bib @@ -3,7 +3,7 @@ @Unpublished{Mustermann2016, author = {Max Mustermann}, title = {Java Unpublished}, - month = {February}, + month = feb, year = {2016}, keywords = {java} } diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestArticleID.bib b/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestArticleID.bib index 720a0cdd464..e0ab059dc0e 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestArticleID.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestArticleID.bib @@ -8,7 +8,7 @@ @article{ journal = {Diagnostic microbiology and infectious disease}, journal-abbreviation = {Diagn Microbiol Infect Dis}, keywords = {Cryptococcal meningitis; Diagnostics; HIV; Immunocompromised; Meningitis; PCR}, - month = {Dec}, + month = dec, nlm-id = {8305899}, owner = {NLM}, pages = {1234}, diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestArticleNoISSN.bib b/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestArticleNoISSN.bib index f7b2362fbcc..b381cdc6486 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestArticleNoISSN.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestArticleNoISSN.bib @@ -8,7 +8,7 @@ @Article{ issue = {3}, pages = {228--242}, doi = {10.1080/1357650X.2015.1125914}, - month = {May}, + month = may, citation-subset = {IM}, country = {England}, created = {2016-03-10}, diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestBookArticleSet.bib b/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestBookArticleSet.bib index 4befa1c8704..cf6ed424c9b 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestBookArticleSet.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestBookArticleSet.bib @@ -4,7 +4,7 @@ @article{ contribution = {2012-03-27}, doi = {10.3275/8949}, isbn = {9781860163593}, - month = {02}, + month = feb, pii = {1223321}, pmid = {21413195}, publisher = {Royal College of Physicians (UK)}, diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestNbib.bib b/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestNbib.bib index 45a1448438a..6d897517d74 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestNbib.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestNbib.bib @@ -41,7 +41,7 @@ @article{ author = {National Collaborating Centre for Chronic Conditions (UK)}, copyright = {Copyright from somwhere}, isbn = {9781860163593}, - month = {02}, + month = feb, pmid = {21413195}, publisher = {Royal College of Physicians (UK)}, publocation = {London}, diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestPubmedBook.bib b/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestPubmedBook.bib index ea185bb5717..6b838e30345 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestPubmedBook.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/MedlineImporterTestPubmedBook.bib @@ -1,7 +1,7 @@ @Article{, title = {Rheumatoid Arthritis: National Clinical Guideline for Management and Treatment in Adults}, year = {2009}, - month = {02}, + month = feb, abstract = {just a dummy.}, author = {National Collaborating Centre for Chronic Conditions (UK) and Williams, Darlisha A}, copyright = {Copyright from somwhere}, diff --git a/src/test/resources/org/jabref/logic/xmp/article_dublinCore.bib b/src/test/resources/org/jabref/logic/xmp/article_dublinCore.bib index 42645b694f6..7a0af0f2d01 100644 --- a/src/test/resources/org/jabref/logic/xmp/article_dublinCore.bib +++ b/src/test/resources/org/jabref/logic/xmp/article_dublinCore.bib @@ -6,7 +6,7 @@ @Article{Olly2018 volume = {1}, number = {1}, pages = {1-2}, - month = {mar}, + month = mar, issn = {978-123-123}, note = {That's a note}, abstract = {That's an abstract}, diff --git a/src/test/resources/org/jabref/util/twente.bib b/src/test/resources/org/jabref/util/twente.bib index f8d4d51f0da..a02f1c17499 100644 --- a/src/test/resources/org/jabref/util/twente.bib +++ b/src/test/resources/org/jabref/util/twente.bib @@ -144,7 +144,7 @@ @TECHREPORT{Patterson06 year = {2006}, type = {Presentation}, address = {Palo Alto, CA}, - month = {August}, + month = aug, pdf = {Patterson06.pdf}, url = {http://www.hotchips.org/hc18/program/conference_day_one.htm} } diff --git a/src/test/resources/testbib/jabref-authors.bib b/src/test/resources/testbib/jabref-authors.bib index 3ff9ce751e5..d79207bb5fd 100644 --- a/src/test/resources/testbib/jabref-authors.bib +++ b/src/test/resources/testbib/jabref-authors.bib @@ -1136,7 +1136,7 @@ @InProceedings{GeigerHarrerLenhardEtAl2016 year = {2016}, pages = {120--128}, address = {Oxford, UK}, - month = {March/April}, + month = mar, doi = {10.1109/sose.2016.39}, file = {:geiger2016evolution.pdf:PDF}, keywords = {rank4}, @@ -1148,7 +1148,7 @@ @InProceedings{GeigerHarrerLenhard2016 booktitle = {Proceedings of the 8th Central-European Workshop on Services and their Composition (ZEUS), January 27-28, Vienna, Austria}, year = {2016}, pages = {37--44}, - month = {jan}, + month = jan, file = {:Geiger2016ProcessEngineBenchmarking.pdf:PDF}, } @@ -1315,7 +1315,7 @@ @TechReport{Geiger2013 year = {2013}, type = {Bamberger Beitr\"age zur Wirtschaftsinformatik und Angewandten Informatik,}, number = {no. 92}, - month = {May}, + month = may, file = {:Geiger2013BPMN20Process.pdf:PDF}, } @@ -1451,7 +1451,7 @@ @InProceedings{GeigerSchoenbergerWirtz2011 year = {2011}, series = {CEUR Workshop Proceedings}, pages = {24--25}, - month = {Feb}, + month = feb, publisher = {CEUR-WS.org}, file = {:Geiger2011ProposalCheckingConformance.pdf:PDF}, } @@ -1480,9 +1480,9 @@ @InProceedings{SchoenbergerSchwalbWirtz2011 @InProceedings{GeigerSchoenbergerWirtz2011a, author = {Matthias Geiger and Andreas Sch\"onberger and Guido Wirtz}, title = {{Towards Automated Conformance Checking of {ebBP-ST} Choreographies and Corresponding {WS-BPEL} Based Orchestrations}}, - booktitle = {Conference on Software Engineering and Knowledge Engineering (SEKE), Miami, Florida, USA}, + booktitle = {Conference on Software Engineering and Knowledge Engineering (SEKE), Miami, Florida, USA, July 7-9, 2011}, year = {2011}, - month = {7.-9. July}, + month = jul, publisher = {Knowledge Systems Institute}, file = {:Geiger2011TowardsAutomatedConformance.pdf:PDF}, } @@ -1501,7 +1501,7 @@ @InProceedings{SchoenbergerBenkerFritzemeierEtAl2009 title = {{QoS}-{E}nabled {B}usiness-to-{B}usiness {I}ntegration {U}sing {ebBP} to {WS-BPEL} {T}ranslations}, booktitle = {Proceedings of the IEEE SCC 2009 International Conference on Services Computing, Bangalore, India}, year = {2009}, - month = {September}, + month = sep, organization = {IEEE}, doi = {10.1109/scc.2009.56}, keywords = {B2Bi, ebXML BPSS, WS-BPEL, Quality of Service, NES, conformance}, diff --git a/src/test/resources/testbib/saveactions2.bib b/src/test/resources/testbib/saveactions2.bib index fe5a0921276..284697a6741 100644 --- a/src/test/resources/testbib/saveactions2.bib +++ b/src/test/resources/testbib/saveactions2.bib @@ -3,11 +3,11 @@ @InProceedings{Pautasso2015TowardsWorkflowBenchmarking, author = {Pautasso, Cesare and Ferme, Vincenzo and Roller, Dieter and Leymann, Frank and Skouradaki, Marigianna}, title = {{Towards Workflow Benchmarking: Open Research Challenges}}, - booktitle = {Proceedings of the 16\textsuperscript{th} Conference on Database Systems for Business, Technology, and Web}, + booktitle = {Proceedings of the 16\textsuperscript{th} Conference on Database Systems for Business, Technology, and Web, March 2-6, 2015}, year = {2015}, pages = {1--20}, address = {Hamburg, Germany}, - month = {March 2-6}, + month = mar file = {:Pautasso2015TowardsWorkflowBenchmarking.pdf:PDF}, keywords = {benchflow} } diff --git a/src/test/resources/testbib/testjabref_210as292.bib b/src/test/resources/testbib/testjabref_210as292.bib index eaf4c6f3516..9885433cb84 100644 --- a/src/test/resources/testbib/testjabref_210as292.bib +++ b/src/test/resources/testbib/testjabref_210as292.bib @@ -16,7 +16,7 @@ @ARTICLE{Aziz2009256-ChannelNeuralRecordingandDeltaCompressionMicrosystemWith3DE volume = {44}, pages = {995-1005}, number = {3}, - month = {MAR}, + month = mar, abstract = {A 3D microsystem for multi-site penetrating extracellular neural recording from the brain is presented. A 16 x 16-channel neural recording interface @@ -161,7 +161,7 @@ @ARTICLE{Baccus1998Synapticfacilitationbyreflectedactionpotentials--enhancemento volume = {95}, pages = {8345--8350}, number = {14}, - month = {Jul}, + month = jul, abstract = {A rapid, reversible enhancement of synaptic transmission from a sensory neuron is reported and explained by impulses that reverse direction, @@ -240,7 +240,7 @@ @ARTICLE{Brewer1995Serum-freeB27/neurobasalmediumsupportsdifferentiatedgrowthofn volume = {42}, pages = {674--683}, number = {5}, - month = {Dec}, + month = dec, abstract = {Two fundamental questions about neuron cell culture were addressed. Can one serum-free medium that was developed for optimum growth of @@ -342,7 +342,7 @@ @ARTICLE{Brewer1997Isolationandcultureofadultrathippocampalneurons.JNeurosciMeth volume = {71}, pages = {143--155}, number = {2}, - month = {Feb}, + month = feb, abstract = {Inability to culture adult central neurons and the failure of injured neurons to regenerate in the brain could be due to genetic controls @@ -417,7 +417,7 @@ @ARTICLE{Brewer2008NbActiv4mediumimprovementtoNeurobasal/B27increasesneuronsynap volume = {170}, pages = {181--187}, number = {2}, - month = {May}, + month = may, abstract = {The most interesting property of neurons is their long-distance propagation of signals as spiking action potentials. Since 1993, Neurobasal/B27 diff --git a/src/test/resources/testbib/testjabref_292.bib b/src/test/resources/testbib/testjabref_292.bib index d267b33c4e7..939e1b14fd3 100644 --- a/src/test/resources/testbib/testjabref_292.bib +++ b/src/test/resources/testbib/testjabref_292.bib @@ -12,7 +12,7 @@ @ARTICLE{Aziz2009256-ChannelNeuralRecordingandDeltaCompressionMicrosystemWith3DE volume = {44}, pages = {995-1005}, number = {3}, - month = {MAR}, + month = mar, abstract = {A 3D microsystem for multi-site penetrating extracellular neural recording from the brain is presented. A 16 x 16-channel neural recording interface integrated prototype fabricated in 0.35 mu m CMOS occupies 3.5 mm @@ -83,7 +83,7 @@ @ARTICLE{Baccus1998Synapticfacilitationbyreflectedactionpotentials--enhancemento volume = {95}, pages = {8345--8350}, number = {14}, - month = {Jul}, + month = jul, abstract = {A rapid, reversible enhancement of synaptic transmission from a sensory neuron is reported and explained by impulses that reverse direction, or reflect, at axon branch points. In leech mechanosensory neurons, @@ -154,7 +154,7 @@ @ARTICLE{Brewer1997Isolationandcultureofadultrathippocampalneurons.JNeurosciMeth volume = {71}, pages = {143--155}, number = {2}, - month = {Feb}, + month = feb, abstract = {Inability to culture adult central neurons and the failure of injured neurons to regenerate in the brain could be due to genetic controls or environmental inhibitors. We tested the environmental inhibitor @@ -200,7 +200,7 @@ @ARTICLE{Brewer1995Serum-freeB27/neurobasalmediumsupportsdifferentiatedgrowthofn volume = {42}, pages = {674--683}, number = {5}, - month = {Dec}, + month = dec, abstract = {Two fundamental questions about neuron cell culture were addressed. Can one serum-free medium that was developed for optimum growth of hippocampal neurons support the growth of neurons from other regions @@ -262,7 +262,7 @@ @ARTICLE{Brewer2008NbActiv4mediumimprovementtoNeurobasal/B27increasesneuronsynap volume = {170}, pages = {181--187}, number = {2}, - month = {May}, + month = may, abstract = {The most interesting property of neurons is their long-distance propagation of signals as spiking action potentials. Since 1993, Neurobasal/B27 has been used as a serum-free medium optimized for hippocampal neuron From 28bd008b91faaa85d8c8615de0410c300c7294ab Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Fri, 8 Nov 2019 11:03:45 +0100 Subject: [PATCH 2/3] Fix month creation. #name# is really used within JabRef to determine a BibTeX string content (and not plain text) - Fix tests - Sort BibEntryTests: default constructor, keywords, all others - Fix name of "CanonicalBibEntry" (from CanonicalBibtexEntry) - Revert "fix jabref format of month", this also reverts commit 77c25ca0f1702991493cf37278a4cedad0d984a4. - Format some code - Add comments --- .../importer/fileformat/BibTeXMLImporter.java | 2 +- .../importer/fileformat/BibtexParser.java | 9 +- .../importer/fileformat/IsiImporter.java | 16 +- .../importer/fileformat/RepecNepImporter.java | 10 +- .../jabref/logic/xmp/DublinCoreExtractor.java | 58 ++- .../java/org/jabref/model/entry/BibEntry.java | 2 +- ...ibtexEntry.java => CanonicalBibEntry.java} | 16 +- .../java/org/jabref/model/entry/Month.java | 7 +- .../logic/bibtex/BibEntryWriterTest.java | 2 +- .../logic/cleanup/CleanupWorkerTest.java | 2 +- .../cleanup/ConvertToBibtexCleanupTest.java | 2 +- .../NormalizeMonthFormatterTest.java | 2 +- .../importer/fileformat/BibtexParserTest.java | 7 + .../importer/fileformat/IsiImporterTest.java | 24 +- .../org/jabref/model/entry/BibEntryTest.java | 166 +++---- .../org/jabref/model/entry/BibEntryTests.java | 404 ------------------ .../BibEntryWithDefaultConstructorTest.java | 272 ++++++++++++ .../model/entry/BibEntryWithKeywordsTest.java | 289 +++++++++++++ .../model/entry/CanonicalBibEntryTest.java | 15 +- src/test/resources/testbib/saveactions2.bib | 2 +- 20 files changed, 699 insertions(+), 608 deletions(-) rename src/main/java/org/jabref/model/entry/{CanonicalBibtexEntry.java => CanonicalBibEntry.java} (78%) delete mode 100644 src/test/java/org/jabref/model/entry/BibEntryTests.java create mode 100644 src/test/java/org/jabref/model/entry/BibEntryWithDefaultConstructorTest.java create mode 100644 src/test/java/org/jabref/model/entry/BibEntryWithKeywordsTest.java diff --git a/src/main/java/org/jabref/logic/importer/fileformat/BibTeXMLImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/BibTeXMLImporter.java index 24293c6ec2e..ab69185bc43 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/BibTeXMLImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/BibTeXMLImporter.java @@ -179,7 +179,7 @@ private void parse(T entryType, Map fields) { putNumber(fields, (BigInteger) method.invoke(entryType)); continue; } else if (method.getName().equals("getMonth")) { - putMonth(fields, Month.parse((String)method.invoke(entryType))); + putMonth(fields, Month.parse((String) method.invoke(entryType))); continue; } else if (isMethodToIgnore(method.getName())) { continue; diff --git a/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java b/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java index eb7fd730852..0fb4526f741 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/BibtexParser.java @@ -589,7 +589,6 @@ private String parseFieldContent(Field field) throws IOException { int character; while (((character = peek()) != ',') && (character != '}') && (character != ')')) { - if (eof) { throw new IOException("Error in line " + line + ": EOF in mid-string"); } @@ -602,7 +601,6 @@ private String parseFieldContent(Field field) throws IOException { // brackets to know when the string is finished. StringBuilder text = parseBracketedTextExactly(); value.append(fieldContentParser.format(text, field)); - } else if (Character.isDigit((char) character)) { // value is a number String number = parseTextToken(); value.append(number); @@ -614,16 +612,11 @@ private String parseFieldContent(Field field) throws IOException { throw new IOException("Error in line " + line + " or above: " + "Empty text token.\nThis could be caused " + "by a missing comma between two fields."); } - if (field != StandardField.MONTH) { - value.append('#').append(textToken).append('#'); - } else { - value.append(textToken); - } + value.append('#').append(textToken).append('#'); } skipWhitespace(); } return value.toString(); - } /** diff --git a/src/main/java/org/jabref/logic/importer/fileformat/IsiImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/IsiImporter.java index 8451e1914b0..8e5b9873075 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/IsiImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/IsiImporter.java @@ -143,7 +143,7 @@ private static void processCapitalization(Map map) { public ParserResult importDatabase(BufferedReader reader) throws IOException { Objects.requireNonNull(reader); - List bibitems = new ArrayList<>(); + List bibEntries = new ArrayList<>(); StringBuilder sb = new StringBuilder(); // Pattern fieldPattern = Pattern.compile("^AU |^TI |^SO |^DT |^C1 |^AB @@ -233,7 +233,6 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { } else if ("SO".equals(beg) || "JA".equals(beg)) { hm.put(StandardField.JOURNAL, EOL_PATTERN.matcher(value).replaceAll(" ")); } else if ("ID".equals(beg) || "KW".equals(beg)) { - value = EOL_PATTERN.matcher(value).replaceAll(" "); String existingKeywords = hm.get(StandardField.KEYWORDS); if ((existingKeywords == null) || existingKeywords.contains(value)) { @@ -242,7 +241,6 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { existingKeywords += ", " + value; } hm.put(StandardField.KEYWORDS, existingKeywords); - } else if ("AB".equals(beg)) { hm.put(StandardField.ABSTRACT, EOL_PATTERN.matcher(value).replaceAll(" ")); } else if ("BP".equals(beg) || "BR".equals(beg) || "SP".equals(beg)) { @@ -271,12 +269,10 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { } else if ("DI".equals(beg)) { hm.put(StandardField.DOI, value); } else if ("PD".equals(beg)) { - String month = IsiImporter.parseMonth(value); if (month != null) { hm.put(StandardField.MONTH, month); } - } else if ("DT".equals(beg)) { if ("Review".equals(value)) { type = StandardEntryType.Article; // set "Review" in Note/Comment? @@ -327,17 +323,19 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { b.setField(hm); - bibitems.add(b); + bibEntries.add(b); } - return new ParserResult(bibitems); + return new ParserResult(bibEntries); } private static String parsePages(String value) { return value.replace("-", "--"); } - public static String parseMonth(String value) { - + /** + * Parses the month and returns it in the JabRef format + */ + static String parseMonth(String value) { String[] parts = value.split("\\s|\\-"); for (String part1 : parts) { Optional month = Month.getMonthByShortName(part1.toLowerCase(Locale.ROOT)); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/RepecNepImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/RepecNepImporter.java index c330a465c6b..550972ea591 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/RepecNepImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/RepecNepImporter.java @@ -330,22 +330,22 @@ private void parseAdditionalFields(BibEntry be, boolean multilineUrlFieldAllowed // skip keyword this.lastLine = "".equals(this.lastLine) ? "" : this.lastLine.substring(this.lastLine.indexOf(':') + 1).trim(); - // parse keywords field if ("Keywords".equals(keyword)) { + // parse keywords field String content = readMultipleLines(in); String[] keywords = content.split("[,;]"); be.addKeywords(Arrays.asList(keywords), importFormatPreferences.getKeywordSeparator()); - // parse JEL field } else if ("JEL".equals(keyword)) { + // parse JEL field be.setField(new UnknownField("jel"), readMultipleLines(in)); } else if (keyword.startsWith("Date")) { // parse date field String content = readMultipleLines(in); Date.parse(content).ifPresent(be::setDate); - // parse URL field } else if (keyword.startsWith("URL")) { + // parse URL field String content; if (multilineUrlFieldAllowed) { content = readMultipleLines(in); @@ -354,10 +354,8 @@ private void parseAdditionalFields(BibEntry be, boolean multilineUrlFieldAllowed readLine(in); } be.setField(StandardField.URL, content); - - // authors field } else if (keyword.startsWith("By")) { - // parse authors + // parse authors field parseAuthors(be, in); } else { readLine(in); diff --git a/src/main/java/org/jabref/logic/xmp/DublinCoreExtractor.java b/src/main/java/org/jabref/logic/xmp/DublinCoreExtractor.java index def4bb4c4ba..9c54524bc0a 100644 --- a/src/main/java/org/jabref/logic/xmp/DublinCoreExtractor.java +++ b/src/main/java/org/jabref/logic/xmp/DublinCoreExtractor.java @@ -67,13 +67,11 @@ private void extractAuthor() { /** * Year in BibTex - Date in DublinCore is only the year information, because dc interprets empty months as January. - * Tries to extract the month as well. - * In JabRef the bibtex/month/value is prioritized. - *
- * The problem is the default value of the calendar, which is always January, also if there is no month information in - * the xmp metdata. The idea is, to reject all information with YYYY-01-01. In cases, where xmp is written with JabRef - * the month property filled with jan will override this behavior and no data is lost. In the cases, where xmp - * is written by another service, the assumption is, that the 1st January is not a publication date at all. + * Tries to extract the month as well. In JabRef the bibtex/month/value is prioritized.
The problem is the + * default value of the calendar, which is always January, also if there is no month information in the xmp metdata. + * The idea is, to reject all information with YYYY-01-01. In cases, where xmp is written with JabRef the month + * property filled with jan will override this behavior and no data is lost. In the cases, where xmp is written by + * another service, the assumption is, that the 1st January is not a publication date at all. */ private void extractYearAndMonth() { List dates = dcSchema.getUnqualifiedSequenceValueList("date"); @@ -87,12 +85,11 @@ private void extractYearAndMonth() { } if (calender != null) { bibEntry.setField(StandardField.YEAR, String.valueOf(calender.get(Calendar.YEAR))); + int monthNumber = calender.get(Calendar.MONTH) + 1; // not the 1st of January - if (!((calender.get(Calendar.MONTH) == 0) && (calender.get(Calendar.DAY_OF_MONTH) == 1))) { - Optional month = Month.getMonthByNumber(calender.get(Calendar.MONTH) + 1); - if (month.isPresent()) { - bibEntry.setField(StandardField.MONTH, month.get().getShortName()); - } + if (!((monthNumber == 1) && (calender.get(Calendar.DAY_OF_MONTH) == 1))) { + Month.getMonthByNumber(monthNumber) + .ifPresent(month -> bibEntry.setMonth(month)); } } } @@ -129,15 +126,13 @@ private void extractPublisher() { } /** - * This method sets all fields, which are custom in bibtext and therefore supported by jabref, but which are not included in the DublinCore format. - *

+ * This method sets all fields, which are custom in BibTeX and therefore supported by JabRef, but which are not + * included in the DublinCore format. + *

* The relation attribute of DublinCore is abused to insert these custom fields. */ private void extractBibTexFields() { - List relationships = dcSchema.getRelations(); - Predicate isBibTeXElement = s -> s.startsWith("bibtex/"); - Consumer splitBibTeXElement = s -> { // the default pattern is bibtex/key/value, but some fields contains url etc. // so the value property contains additional slashes, which makes the usage of @@ -154,15 +149,15 @@ private void extractBibTexFields() { // see also DublinCoreExtractor#extractYearAndMonth if (StandardField.MONTH.equals(key)) { Optional parsedMonth = Month.parse(value); - parsedMonth.ifPresent(month -> bibEntry.setField(key, month.getShortName())); + parsedMonth.ifPresent(bibEntry::setMonth); } } - }; + List relationships = dcSchema.getRelations(); if (relationships != null) { relationships.stream() - .filter(isBibTeXElement) - .forEach(splitBibTeXElement); + .filter(isBibTeXElement) + .forEach(splitBibTeXElement); } } @@ -220,26 +215,27 @@ private void extractType() { } /** - * Helper function for retrieving a BibEntry from the DublinCore metadata - * in a PDF file. + * Helper function for retrieving a BibEntry from the DublinCore metadata in a PDF file. + *

+ * To understand how to get hold of a DublinCore have a look in the test cases for XMPUtil. + *

+ * The BibEntry is build by mapping individual fields in the dublin core (like creator, title, subject) to fields in + * a bibtex bibEntry. In case special "bibtex/" entries are contained, the normal dublin core fields take + * precedence. For instance, the dublin core date takes precedence over bibtex/month. * - * To understand how to get hold of a DublinCore have a look in the - * test cases for XMPUtil. - * - * The BibEntry is build by mapping individual fields in the dublin core - * (like creator, title, subject) to fields in a bibtex bibEntry. - * - * @return The bibtex bibEntry found in the document information. + * @return The bibEntry extracted from the document information. */ public Optional extractBibtexEntry() { + // first extract "bibtex/" entries + this.extractBibTexFields(); + // then extract all "standard" dublin core entries this.extractEditor(); this.extractAuthor(); this.extractYearAndMonth(); this.extractAbstract(); this.extractDOI(); this.extractPublisher(); - this.extractBibTexFields(); this.extractRights(); this.extractSource(); this.extractSubject(); diff --git a/src/main/java/org/jabref/model/entry/BibEntry.java b/src/main/java/org/jabref/model/entry/BibEntry.java index a600d5892a3..0fa8519f85f 100644 --- a/src/main/java/org/jabref/model/entry/BibEntry.java +++ b/src/main/java/org/jabref/model/entry/BibEntry.java @@ -614,7 +614,7 @@ public Object clone() { */ @Override public String toString() { - return CanonicalBibtexEntry.getCanonicalRepresentation(this); + return CanonicalBibEntry.getCanonicalRepresentation(this); } /** diff --git a/src/main/java/org/jabref/model/entry/CanonicalBibtexEntry.java b/src/main/java/org/jabref/model/entry/CanonicalBibEntry.java similarity index 78% rename from src/main/java/org/jabref/model/entry/CanonicalBibtexEntry.java rename to src/main/java/org/jabref/model/entry/CanonicalBibEntry.java index 0f9ba8e3022..a854db41907 100644 --- a/src/main/java/org/jabref/model/entry/CanonicalBibtexEntry.java +++ b/src/main/java/org/jabref/model/entry/CanonicalBibEntry.java @@ -11,16 +11,19 @@ import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.InternalField; -public class CanonicalBibtexEntry { +public class CanonicalBibEntry { - private CanonicalBibtexEntry() { + private CanonicalBibEntry() { } /** - * This returns a canonical BibTeX serialization. Special characters such as "{" or "&" are NOT escaped, but written - * as is + * This returns a canonical BibTeX serialization. Serializes all fields, even the JabRef internal ones. Does NOT + * serialize "KEY_FIELD" as field, but as key * - * Serializes all fields, even the JabRef internal ones. Does NOT serialize "KEY_FIELD" as field, but as key + *

    + *
  • Special characters such as "{" or "&" are NOT escaped, but written as
  • + *
  • String constants are not handled. That means, month = apr in a bib file gets month = {#apr#}. This indicates that the month field is correctly stored
  • + *
*/ public static String getCanonicalRepresentation(BibEntry entry) { StringBuilder sb = new StringBuilder(); @@ -50,7 +53,7 @@ public static String getCanonicalRepresentation(BibEntry entry) { // generate field entries StringJoiner sj = new StringJoiner(",\n", "", "\n"); for (String fieldName : sortedFields) { - String line = String.format(" %s = {%s}", fieldName, String.valueOf(mapFieldToValue.get(fieldName)).replaceAll("\\r\\n","\n")); + String line = String.format(" %s = {%s}", fieldName, String.valueOf(mapFieldToValue.get(fieldName)).replaceAll("\\r\\n", "\n")); sj.add(line); } sb.append(sj); @@ -59,5 +62,4 @@ public static String getCanonicalRepresentation(BibEntry entry) { sb.append('}'); return sb.toString(); } - } diff --git a/src/main/java/org/jabref/model/entry/Month.java b/src/main/java/org/jabref/model/entry/Month.java index 101476c9d60..bb9d3b44147 100644 --- a/src/main/java/org/jabref/model/entry/Month.java +++ b/src/main/java/org/jabref/model/entry/Month.java @@ -168,13 +168,14 @@ public String getShortName() { * Returns the month in JabRef format. The format is the short 3-digit name surrounded by a '#'. * Example: #jan#, #feb#, etc. * - * See https://github.com/JabRef/jabref/issues/263#issuecomment-151246595 for a discussion on that thing. - * This seems to be an invalid format in terms of plain BiBTeX, but a valid format in the case of JabRef + * See Issue 263 for a discussion on that thing. + * This seems to be an invalid format in terms of plain BiBTeX, but a valid format in the case of JabRef. + * The documentation is available at the Strings help of JabRef. * * @return Month in JabRef format */ public String getJabRefFormat() { - return String.format("%s", shortName); + return String.format("#%s#", shortName); } /** diff --git a/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java b/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java index f91afa630ba..b2e6183c8ed 100644 --- a/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java +++ b/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java @@ -416,7 +416,7 @@ void monthFieldSpecialSyntax() throws IOException { // modify month field Set fields = entry.getFields(); assertTrue(fields.contains(StandardField.MONTH)); - assertEquals("mar", entry.getField(StandardField.MONTH).get()); + assertEquals("#mar#", entry.getField(StandardField.MONTH).get()); //write out bibtex string StringWriter stringWriter = new StringWriter(); diff --git a/src/test/java/org/jabref/logic/cleanup/CleanupWorkerTest.java b/src/test/java/org/jabref/logic/cleanup/CleanupWorkerTest.java index 007a179adaa..009cce0cb2d 100644 --- a/src/test/java/org/jabref/logic/cleanup/CleanupWorkerTest.java +++ b/src/test/java/org/jabref/logic/cleanup/CleanupWorkerTest.java @@ -183,7 +183,7 @@ void cleanupMonthChangesNumberToBibtex() { entry.setField(StandardField.MONTH, "01"); worker.cleanup(preset, entry); - assertEquals(Optional.of("jan"), entry.getField(StandardField.MONTH)); + assertEquals(Optional.of("#jan#"), entry.getField(StandardField.MONTH)); } @Test diff --git a/src/test/java/org/jabref/logic/cleanup/ConvertToBibtexCleanupTest.java b/src/test/java/org/jabref/logic/cleanup/ConvertToBibtexCleanupTest.java index d8cdb70ee69..38259aaef2f 100644 --- a/src/test/java/org/jabref/logic/cleanup/ConvertToBibtexCleanupTest.java +++ b/src/test/java/org/jabref/logic/cleanup/ConvertToBibtexCleanupTest.java @@ -27,7 +27,7 @@ public void cleanupMovesDateToYearAndMonth() { assertEquals(Optional.empty(), entry.getField(StandardField.DATE)); assertEquals(Optional.of("2011"), entry.getField(StandardField.YEAR)); - assertEquals(Optional.of("jan"), entry.getField(StandardField.MONTH)); + assertEquals(Optional.of("#jan#"), entry.getField(StandardField.MONTH)); } @Test diff --git a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java index 1d6ebd292c4..31c3f935989 100644 --- a/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java +++ b/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeMonthFormatterTest.java @@ -19,6 +19,6 @@ public void setUp() { @Test public void formatExample() { - assertEquals("dec", formatter.format(formatter.getExampleInput())); + assertEquals("#dec#", formatter.format(formatter.getExampleInput())); } } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java b/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java index 1dcd5ba75c8..b4ac66f03d4 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/BibtexParserTest.java @@ -1784,4 +1784,11 @@ void bibTeXConstantAprilIsDisplayedAsConstant() throws ParseException { assertEquals("#apr#", result.get().getField(StandardField.MONTH).get()); } + + @Test + void bibTeXConstantAprilIsParsedAsStringMonthAprilWhenReadingTheField() throws ParseException { + Optional result = parser.parseSingleEntry("@Misc{m, month = apr }" ); + + assertEquals(Optional.of("#apr#"), result.get().getField(StandardField.MONTH)); + } } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/IsiImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/IsiImporterTest.java index 6fc0ea874c0..e470436f40d 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/IsiImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/IsiImporterTest.java @@ -13,6 +13,7 @@ import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.Month; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.field.UnknownField; @@ -24,9 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -/** - * Test cases for the IsiImporter - */ public class IsiImporterTest { private static final String FILE_ENDING = ".isi"; @@ -191,7 +189,7 @@ public void testImportEntriesINSPEC() throws IOException, URISyntaxException { first.getField(StandardField.AUTHOR)); assertEquals(Optional.of("Applied Physics Letters"), first.getField(StandardField.JOURNAL)); assertEquals(Optional.of("2006"), first.getField(StandardField.YEAR)); - assertEquals(Optional.of("jul"), first.getField(StandardField.MONTH)); + assertEquals(Optional.of(Month.JULY), first.getMonth()); assertEquals(Optional.of("89"), first.getField(StandardField.VOLUME)); assertEquals(Optional.of("4"), first.getField(StandardField.NUMBER)); assertEquals(Optional.of("Lorem ipsum abstract"), first.getField(StandardField.ABSTRACT)); @@ -235,14 +233,14 @@ public void testIsiAuthorsConvert() { @Test public void testMonthConvert() { - assertEquals("jun", IsiImporter.parseMonth("06")); - assertEquals("jun", IsiImporter.parseMonth("JUN")); - assertEquals("jun", IsiImporter.parseMonth("jUn")); - assertEquals("may", IsiImporter.parseMonth("MAY-JUN")); - assertEquals("jun", IsiImporter.parseMonth("2006 06")); - assertEquals("jun", IsiImporter.parseMonth("2006 06-07")); - assertEquals("jul", IsiImporter.parseMonth("2006 07 03")); - assertEquals("may", IsiImporter.parseMonth("2006 May-Jun")); + assertEquals("#jun#", IsiImporter.parseMonth("06")); + assertEquals("#jun#", IsiImporter.parseMonth("JUN")); + assertEquals("#jun#", IsiImporter.parseMonth("jUn")); + assertEquals("#may#", IsiImporter.parseMonth("MAY-JUN")); + assertEquals("#jun#", IsiImporter.parseMonth("2006 06")); + assertEquals("#jun#", IsiImporter.parseMonth("2006 06-07")); + assertEquals("#jul#", IsiImporter.parseMonth("2006 07 03")); + assertEquals("#may#", IsiImporter.parseMonth("2006 May-Jun")); } @Test @@ -334,7 +332,7 @@ public void testImportEntriesMedline() throws IOException, URISyntaxException { "Joffe, Hadine and Hall, Janet E. and Gruber, Staci and Sarmiento, Ingrid A. and Cohen, Lee S. and Yurgelun-Todd, Deborah and Martin, Kathryn A."), second.getField(StandardField.AUTHOR)); assertEquals(Optional.of("2006"), second.getField(StandardField.YEAR)); - assertEquals(Optional.of("may"), second.getField(StandardField.MONTH)); + assertEquals(Optional.of(Month.MAY), second.getMonth()); assertEquals(Optional.of("13"), second.getField(StandardField.VOLUME)); assertEquals(Optional.of("3"), second.getField(StandardField.NUMBER)); assertEquals(Optional.of("411--22"), second.getField(StandardField.PAGES)); diff --git a/src/test/java/org/jabref/model/entry/BibEntryTest.java b/src/test/java/org/jabref/model/entry/BibEntryTest.java index 2c16dbe91d4..65bfeb66abd 100644 --- a/src/test/java/org/jabref/model/entry/BibEntryTest.java +++ b/src/test/java/org/jabref/model/entry/BibEntryTest.java @@ -1,141 +1,73 @@ package org.jabref.model.entry; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; -import java.util.Optional; -import org.jabref.model.database.BibDatabase; -import org.jabref.model.entry.field.BibField; -import org.jabref.model.entry.field.FieldPriority; +import org.jabref.model.entry.field.InternalField; +import org.jabref.model.entry.field.OrFields; import org.jabref.model.entry.field.StandardField; -import org.jabref.model.entry.field.UnknownField; +import org.jabref.model.entry.types.StandardEntryType; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - -public class BibEntryTest { - - private BibEntry entry; - - @BeforeEach - public void setUp() { - entry = new BibEntry(); - } - - @AfterEach - public void tearDown() { - entry = null; - } +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +/** + * Contains misc tests for BibEntry especially not using the default constructor: {@link + * BibEntryWithDefaultConstructorTest} + */ +class BibEntryTest { @Test - public void getFieldIsCaseInsensitive() throws Exception { - entry.setField(new UnknownField("TeSt"), "value"); - - assertEquals(Optional.of("value"), entry.getField(new UnknownField("tEsT"))); + public void allFieldsPresentDefault() { + BibEntry e = new BibEntry(StandardEntryType.Article); + e.setField(StandardField.AUTHOR, "abc"); + e.setField(StandardField.TITLE, "abc"); + e.setField(StandardField.JOURNAL, "abc"); + + List requiredFields = new ArrayList<>(); + requiredFields.add(new OrFields(StandardField.AUTHOR)); + requiredFields.add(new OrFields(StandardField.TITLE)); + assertTrue(e.allFieldsPresent(requiredFields, null)); + + requiredFields.add(new OrFields(StandardField.YEAR)); + assertFalse(e.allFieldsPresent(requiredFields, null)); } @Test - public void getFieldWorksWithBibFieldAsWell() throws Exception { - entry.setField(StandardField.AUTHOR, "value"); - - assertEquals(Optional.of("value"), entry.getField(new BibField(StandardField.AUTHOR, FieldPriority.IMPORTANT).getField())); + public void allFieldsPresentOr() { + BibEntry e = new BibEntry(StandardEntryType.Article); + e.setField(StandardField.AUTHOR, "abc"); + e.setField(StandardField.TITLE, "abc"); + e.setField(StandardField.JOURNAL, "abc"); + + List requiredFields = new ArrayList<>(); + requiredFields.add(new OrFields(StandardField.JOURNAL, StandardField.YEAR)); + assertTrue(e.allFieldsPresent(requiredFields, null)); + + requiredFields.add(new OrFields(StandardField.YEAR, StandardField.ADDRESS)); + assertFalse(e.allFieldsPresent(requiredFields, null)); } @Test - public void setFieldWorksWithBibFieldAsWell() throws Exception { - entry.setField(new BibField(StandardField.AUTHOR, FieldPriority.IMPORTANT).getField(), "value"); - - assertEquals(Optional.of("value"), entry.getField(StandardField.AUTHOR)); + public void isNullCiteKeyThrowsNPE() { + BibEntry e = new BibEntry(StandardEntryType.Article); + assertThrows(NullPointerException.class, () -> e.setCiteKey(null)); } @Test - public void clonedBibentryHasUniqueID() throws Exception { - BibEntry entry = new BibEntry(); - BibEntry entryClone = (BibEntry) entry.clone(); + public void isEmptyCiteKey() { + BibEntry e = new BibEntry(StandardEntryType.Article); + assertFalse(e.hasCiteKey()); - assertNotEquals(entry.getId(), entryClone.getId()); - } - - @Test - public void testGetAndAddToLinkedFileList() { - List files = entry.getFiles(); - files.add(new LinkedFile("", "", "")); - entry.setFiles(files); - assertEquals(Arrays.asList(new LinkedFile("", "", "")), entry.getFiles()); - } - - @Test - public void testGetEmptyKeywords() { - KeywordList actual = entry.getKeywords(','); - - assertEquals(new KeywordList(), actual); - } - - @Test - public void testGetSingleKeywords() { - entry.addKeyword("kw", ','); - KeywordList actual = entry.getKeywords(','); - - assertEquals(new KeywordList(new Keyword("kw")), actual); - } - - @Test - public void testGetKeywords() { - entry.addKeyword("kw", ','); - entry.addKeyword("kw2", ','); - entry.addKeyword("kw3", ','); - KeywordList actual = entry.getKeywords(','); - - assertEquals(new KeywordList(new Keyword("kw"), new Keyword("kw2"), new Keyword("kw3")), actual); - } - - @Test - public void testGetEmptyResolvedKeywords() { - BibDatabase database = new BibDatabase(); - BibEntry entry2 = new BibEntry(); - entry.setField(StandardField.CROSSREF, "entry2"); - entry2.setCiteKey("entry2"); - database.insertEntry(entry2); - database.insertEntry(entry); - - KeywordList actual = entry.getResolvedKeywords(',', database); - - assertEquals(new KeywordList(), actual); - } - - @Test - public void testGetSingleResolvedKeywords() { - BibDatabase database = new BibDatabase(); - BibEntry entry2 = new BibEntry(); - entry.setField(StandardField.CROSSREF, "entry2"); - entry2.setCiteKey("entry2"); - entry2.addKeyword("kw", ','); - database.insertEntry(entry2); - database.insertEntry(entry); - - KeywordList actual = entry.getResolvedKeywords(',', database); - - assertEquals(new KeywordList(new Keyword("kw")), actual); - } - - @Test - public void testGetResolvedKeywords() { - BibDatabase database = new BibDatabase(); - BibEntry entry2 = new BibEntry(); - entry.setField(StandardField.CROSSREF, "entry2"); - entry2.setCiteKey("entry2"); - entry2.addKeyword("kw", ','); - entry2.addKeyword("kw2", ','); - entry2.addKeyword("kw3", ','); - database.insertEntry(entry2); - database.insertEntry(entry); + e.setCiteKey(""); + assertFalse(e.hasCiteKey()); - KeywordList actual = entry.getResolvedKeywords(',', database); + e.setCiteKey("key"); + assertTrue(e.hasCiteKey()); - assertEquals(new KeywordList(new Keyword("kw"), new Keyword("kw2"), new Keyword("kw3")), actual); + e.clearField(InternalField.KEY_FIELD); + assertFalse(e.hasCiteKey()); } } diff --git a/src/test/java/org/jabref/model/entry/BibEntryTests.java b/src/test/java/org/jabref/model/entry/BibEntryTests.java deleted file mode 100644 index 586d939a776..00000000000 --- a/src/test/java/org/jabref/model/entry/BibEntryTests.java +++ /dev/null @@ -1,404 +0,0 @@ -package org.jabref.model.entry; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -import org.jabref.model.FieldChange; -import org.jabref.model.entry.field.InternalField; -import org.jabref.model.entry.field.OrFields; -import org.jabref.model.entry.field.SpecialField; -import org.jabref.model.entry.field.StandardField; -import org.jabref.model.entry.types.StandardEntryType; - -import com.google.common.collect.Sets; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class BibEntryTests { - - private BibEntry keywordEntry; - private BibEntry emptyEntry; - - @BeforeEach - public void setUp() { - // Default entry for most keyword and some type tests - keywordEntry = new BibEntry(); - keywordEntry.setType(StandardEntryType.Article); - keywordEntry.setField(StandardField.KEYWORDS, "Foo, Bar"); - keywordEntry.setChanged(false); - - // Empty entry for some tests - emptyEntry = new BibEntry(); - emptyEntry.setType(StandardEntryType.Article); - emptyEntry.setChanged(false); - } - - @Test - public void testDefaultConstructor() { - BibEntry entry = new BibEntry(); - assertEquals(StandardEntryType.Misc, entry.getType()); - assertNotNull(entry.getId()); - assertFalse(entry.getField(StandardField.AUTHOR).isPresent()); - } - - @Test - public void allFieldsPresentDefault() { - BibEntry e = new BibEntry(StandardEntryType.Article); - e.setField(StandardField.AUTHOR, "abc"); - e.setField(StandardField.TITLE, "abc"); - e.setField(StandardField.JOURNAL, "abc"); - - List requiredFields = new ArrayList<>(); - requiredFields.add(new OrFields(StandardField.AUTHOR)); - requiredFields.add(new OrFields(StandardField.TITLE)); - assertTrue(e.allFieldsPresent(requiredFields, null)); - - requiredFields.add(new OrFields(StandardField.YEAR)); - assertFalse(e.allFieldsPresent(requiredFields, null)); - } - - @Test - public void allFieldsPresentOr() { - BibEntry e = new BibEntry(StandardEntryType.Article); - e.setField(StandardField.AUTHOR, "abc"); - e.setField(StandardField.TITLE, "abc"); - e.setField(StandardField.JOURNAL, "abc"); - - List requiredFields = new ArrayList<>(); - requiredFields.add(new OrFields(StandardField.JOURNAL, StandardField.YEAR)); - assertTrue(e.allFieldsPresent(requiredFields, null)); - - requiredFields.add(new OrFields(StandardField.YEAR, StandardField.ADDRESS)); - assertFalse(e.allFieldsPresent(requiredFields, null)); - } - - @Test - public void isNullCiteKeyThrowsNPE() { - BibEntry e = new BibEntry(StandardEntryType.Article); - assertThrows(NullPointerException.class, () -> e.setCiteKey(null)); - } - - @Test - public void isEmptyCiteKey() { - BibEntry e = new BibEntry(StandardEntryType.Article); - assertFalse(e.hasCiteKey()); - - e.setCiteKey(""); - assertFalse(e.hasCiteKey()); - - e.setCiteKey("key"); - assertTrue(e.hasCiteKey()); - - e.clearField(InternalField.KEY_FIELD); - assertFalse(e.hasCiteKey()); - } - - @Test - public void settingTypeToNullThrowsException() { - assertThrows(NullPointerException.class, () -> keywordEntry.setType(null)); - } - - @Test - public void getFieldOrAliasDateWithYearNumericalMonthString() { - emptyEntry.setField(StandardField.YEAR, "2003"); - emptyEntry.setField(StandardField.MONTH, "3"); - assertEquals(Optional.of("2003-03"), emptyEntry.getFieldOrAlias(StandardField.DATE)); - } - - @Test - public void getFieldOrAliasDateWithYearAbbreviatedMonth() { - emptyEntry.setField(StandardField.YEAR, "2003"); - emptyEntry.setField(StandardField.MONTH, "mar"); - assertEquals(Optional.of("2003-03"), emptyEntry.getFieldOrAlias(StandardField.DATE)); - } - - @Test - public void getFieldOrAliasDateWithYearAbbreviatedMonthString() { - emptyEntry.setField(StandardField.YEAR, "2003"); - emptyEntry.setField(StandardField.MONTH, "mar"); - assertEquals(Optional.of("2003-03"), emptyEntry.getFieldOrAlias(StandardField.DATE)); - } - - @Test - public void getFieldOrAliasDateWithOnlyYear() { - emptyEntry.setField(StandardField.YEAR, "2003"); - assertEquals(Optional.of("2003"), emptyEntry.getFieldOrAlias(StandardField.DATE)); - } - - @Test - public void getFieldOrAliasYearWithDateYYYY() { - emptyEntry.setField(StandardField.DATE, "2003"); - assertEquals(Optional.of("2003"), emptyEntry.getFieldOrAlias(StandardField.YEAR)); - } - - @Test - public void getFieldOrAliasYearWithDateYYYYMM() { - emptyEntry.setField(StandardField.DATE, "2003-03"); - assertEquals(Optional.of("2003"), emptyEntry.getFieldOrAlias(StandardField.YEAR)); - } - - @Test - public void getFieldOrAliasYearWithDateYYYYMMDD() { - emptyEntry.setField(StandardField.DATE, "2003-03-30"); - assertEquals(Optional.of("2003"), emptyEntry.getFieldOrAlias(StandardField.YEAR)); - } - - @Test - public void getFieldOrAliasMonthWithDateYYYYReturnsNull() { - emptyEntry.setField(StandardField.DATE, "2003"); - assertEquals(Optional.empty(), emptyEntry.getFieldOrAlias(StandardField.MONTH)); - } - - @Test - public void getFieldOrAliasMonthWithDateYYYYMM() { - emptyEntry.setField(StandardField.DATE, "2003-03"); - assertEquals(Optional.of("mar"), emptyEntry.getFieldOrAlias(StandardField.MONTH)); - } - - @Test - public void getFieldOrAliasMonthWithDateYYYYMMDD() { - emptyEntry.setField(StandardField.DATE, "2003-03-30"); - assertEquals(Optional.of("mar"), emptyEntry.getFieldOrAlias(StandardField.MONTH)); - } - - @Test - public void getFieldOrAliasLatexFreeAlreadyFreeValueIsUnchanged() { - emptyEntry.setField(StandardField.TITLE, "A Title Without any LaTeX commands"); - assertEquals(Optional.of("A Title Without any LaTeX commands"), emptyEntry.getFieldOrAliasLatexFree(StandardField.TITLE)); - } - - @Test - public void getFieldOrAliasLatexFreeAlreadyFreeAliasValueIsUnchanged() { - emptyEntry.setField(StandardField.JOURNAL, "A Title Without any LaTeX commands"); - assertEquals(Optional.of("A Title Without any LaTeX commands"), emptyEntry.getFieldOrAliasLatexFree(StandardField.JOURNALTITLE)); - } - - @Test - public void getFieldOrAliasLatexFreeBracesAreRemoved() { - emptyEntry.setField(StandardField.TITLE, "{A Title with some {B}ra{C}es}"); - assertEquals(Optional.of("A Title with some BraCes"), emptyEntry.getFieldOrAliasLatexFree(StandardField.TITLE)); - } - - @Test - public void getFieldOrAliasLatexFreeBracesAreRemovedFromAlias() { - emptyEntry.setField(StandardField.JOURNAL, "{A Title with some {B}ra{C}es}"); - assertEquals(Optional.of("A Title with some BraCes"), emptyEntry.getFieldOrAliasLatexFree(StandardField.JOURNALTITLE)); - } - - @Test - public void getFieldOrAliasLatexFreeComplexConversionInAlias() { - emptyEntry.setField(StandardField.JOURNAL, "A 32~{mA} {$\\Sigma\\Delta$}-modulator"); - assertEquals(Optional.of("A 32 mA ΣΔ-modulator"), emptyEntry.getFieldOrAliasLatexFree(StandardField.JOURNALTITLE)); - } - - @Test - public void setNullField() { - assertThrows(NullPointerException.class, () -> emptyEntry.setField(null)); - } - - @Test - public void addNullKeywordThrowsNPE() { - assertThrows(NullPointerException.class, () -> keywordEntry.addKeyword((Keyword) null, ',')); - } - - @Test - public void putNullKeywordListThrowsNPE() { - assertThrows(NullPointerException.class, () -> keywordEntry.putKeywords((KeywordList) null, ',')); - } - - @Test - public void putNullKeywordSeparatorThrowsNPE() { - assertThrows(NullPointerException.class, () -> keywordEntry.putKeywords(Arrays.asList("A", "B"), null)); - } - - @Test - public void testGetSeparatedKeywordsAreCorrect() { - assertEquals(new KeywordList("Foo", "Bar"), keywordEntry.getKeywords(',')); - } - - @Test - public void testAddKeywordIsCorrect() { - keywordEntry.addKeyword("FooBar", ','); - assertEquals(new KeywordList("Foo", "Bar", "FooBar"), keywordEntry.getKeywords(',')); - } - - @Test - public void testAddKeywordHasChanged() { - keywordEntry.addKeyword("FooBar", ','); - assertTrue(keywordEntry.hasChanged()); - } - - @Test - public void testAddKeywordTwiceYiedsOnlyOne() { - keywordEntry.addKeyword("FooBar", ','); - keywordEntry.addKeyword("FooBar", ','); - assertEquals(new KeywordList("Foo", "Bar", "FooBar"), keywordEntry.getKeywords(',')); - } - - @Test - public void addKeywordIsCaseSensitive() { - keywordEntry.addKeyword("FOO", ','); - assertEquals(new KeywordList("Foo", "Bar", "FOO"), keywordEntry.getKeywords(',')); - } - - @Test - public void testAddKeywordWithDifferentCapitalizationChanges() { - keywordEntry.addKeyword("FOO", ','); - assertTrue(keywordEntry.hasChanged()); - } - - @Test - public void testAddKeywordEmptyKeywordIsNotAdded() { - keywordEntry.addKeyword("", ','); - assertEquals(new KeywordList("Foo", "Bar"), keywordEntry.getKeywords(',')); - } - - @Test - public void testAddKeywordEmptyKeywordNotChanged() { - keywordEntry.addKeyword("", ','); - assertFalse(keywordEntry.hasChanged()); - } - - @Test - public void texNewBibEntryHasNoKeywords() { - assertTrue(emptyEntry.getKeywords(',').isEmpty()); - } - - @Test - public void texNewBibEntryHasNoKeywordsEvenAfterAddingEmptyKeyword() { - emptyEntry.addKeyword("", ','); - assertTrue(emptyEntry.getKeywords(',').isEmpty()); - } - - @Test - public void texNewBibEntryAfterAddingEmptyKeywordNotChanged() { - emptyEntry.addKeyword("", ','); - assertFalse(emptyEntry.hasChanged()); - } - - @Test - public void testAddKeywordsWorksAsExpected() { - emptyEntry.addKeywords(Arrays.asList("Foo", "Bar"), ','); - assertEquals(new KeywordList("Foo", "Bar"), emptyEntry.getKeywords(',')); - } - - @Test - public void testPutKeywordsOverwritesOldKeywords() { - keywordEntry.putKeywords(Arrays.asList("Yin", "Yang"), ','); - assertEquals(new KeywordList("Yin", "Yang"), keywordEntry.getKeywords(',')); - } - - @Test - public void testPutKeywordsHasChanged() { - keywordEntry.putKeywords(Arrays.asList("Yin", "Yang"), ','); - assertTrue(keywordEntry.hasChanged()); - } - - @Test - public void testPutKeywordsPutEmpyListErasesPreviousKeywords() { - keywordEntry.putKeywords(Collections.emptyList(), ','); - assertTrue(keywordEntry.getKeywords(',').isEmpty()); - } - - @Test - public void testPutKeywordsPutEmpyListHasChanged() { - keywordEntry.putKeywords(Collections.emptyList(), ','); - assertTrue(keywordEntry.hasChanged()); - } - - @Test - public void testPutKeywordsPutEmpyListToEmptyBibentry() { - emptyEntry.putKeywords(Collections.emptyList(), ','); - assertTrue(emptyEntry.getKeywords(',').isEmpty()); - } - - @Test - public void testPutKeywordsPutEmpyListToEmptyBibentryNotChanged() { - emptyEntry.putKeywords(Collections.emptyList(), ','); - assertFalse(emptyEntry.hasChanged()); - } - - @Test - public void putKeywordsToEmptyReturnsNoChange() { - Optional change = emptyEntry.putKeywords(Collections.emptyList(), ','); - assertEquals(Optional.empty(), change); - } - - @Test - public void clearKeywordsReturnsChange() { - Optional change = keywordEntry.putKeywords(Collections.emptyList(), ','); - assertEquals(Optional.of(new FieldChange(keywordEntry, StandardField.KEYWORDS, "Foo, Bar", null)), change); - } - - @Test - public void changeKeywordsReturnsChange() { - Optional change = keywordEntry.putKeywords(Arrays.asList("Test", "FooTest"), ','); - assertEquals(Optional.of(new FieldChange(keywordEntry, StandardField.KEYWORDS, "Foo, Bar", "Test, FooTest")), - change); - } - - @Test - public void putKeywordsToSameReturnsNoChange() { - Optional change = keywordEntry.putKeywords(Arrays.asList("Foo", "Bar"), ','); - assertEquals(Optional.empty(), change); - } - - @Test - public void getKeywordsReturnsParsedKeywordListFromKeywordsField() { - BibEntry entry = new BibEntry(); - entry.setField(StandardField.KEYWORDS, "w1, w2a w2b, w3"); - assertEquals(new KeywordList("w1", "w2a w2b", "w3"), entry.getKeywords(',')); - } - - @Test - public void removeKeywordsOnEntryWithoutKeywordsDoesNothing() { - BibEntry entry = new BibEntry(); - Optional change = entry.removeKeywords(SpecialField.RANKING.getKeyWords(), ','); - assertEquals(Optional.empty(), change); - } - - @Test - public void removeKeywordsWithEmptyListDoesNothing() { - keywordEntry.putKeywords(Arrays.asList("kw1", "kw2"), ','); - Optional change = keywordEntry.removeKeywords(new KeywordList(), ','); - assertEquals(Optional.empty(), change); - } - - @Test - public void removeKeywordsWithNonExistingKeywordsDoesNothing() { - keywordEntry.putKeywords(Arrays.asList("kw1", "kw2"), ','); - Optional change = keywordEntry.removeKeywords(KeywordList.parse("kw3, kw4", ','), ','); - assertEquals(Optional.empty(), change); - assertEquals(Sets.newHashSet("kw1", "kw2"), keywordEntry.getKeywords(',').toStringList()); - } - - @Test - public void removeKeywordsWithExistingKeywordsRemovesThem() { - keywordEntry.putKeywords(Arrays.asList("kw1", "kw2", "kw3"), ','); - Optional change = keywordEntry.removeKeywords(KeywordList.parse("kw1, kw2", ','), ','); - assertTrue(change.isPresent()); - assertEquals(KeywordList.parse("kw3", ','), keywordEntry.getKeywords(',')); - } - - @Test - public void setCiteKey() { - BibEntry be = new BibEntry(); - assertFalse(be.hasCiteKey()); - be.setField(StandardField.AUTHOR, "Albert Einstein"); - be.setCiteKey("Einstein1931"); - assertTrue(be.hasCiteKey()); - assertEquals(Optional.of("Einstein1931"), be.getCiteKeyOptional()); - assertEquals(Optional.of("Albert Einstein"), be.getField(StandardField.AUTHOR)); - be.clearField(StandardField.AUTHOR); - assertEquals(Optional.empty(), be.getField(StandardField.AUTHOR)); - } -} diff --git a/src/test/java/org/jabref/model/entry/BibEntryWithDefaultConstructorTest.java b/src/test/java/org/jabref/model/entry/BibEntryWithDefaultConstructorTest.java new file mode 100644 index 00000000000..19f7fb035c3 --- /dev/null +++ b/src/test/java/org/jabref/model/entry/BibEntryWithDefaultConstructorTest.java @@ -0,0 +1,272 @@ +package org.jabref.model.entry; + +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import org.jabref.model.entry.field.BibField; +import org.jabref.model.entry.field.FieldPriority; +import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.field.UnknownField; +import org.jabref.model.entry.types.StandardEntryType; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Simple tests for a BibEntry. There are more test classes testing special features. + */ +public class BibEntryWithDefaultConstructorTest { + + private BibEntry entry; + + @BeforeEach + public void setUp() { + entry = new BibEntry(); + } + + @AfterEach + public void tearDown() { + entry = null; + } + + @Test + public void testDefaultConstructor() { + assertEquals(StandardEntryType.Misc, entry.getType()); + assertNotNull(entry.getId()); + assertFalse(entry.getField(StandardField.AUTHOR).isPresent()); + } + + @Test + public void settingTypeToNullThrowsException() { + assertThrows(NullPointerException.class, () -> entry.setType(null)); + } + + @Test + public void setNullFieldThrowsNPE() { + assertThrows(NullPointerException.class, () -> entry.setField(null)); + } + + @Test + public void getFieldIsCaseInsensitive() throws Exception { + entry.setField(new UnknownField("TeSt"), "value"); + assertEquals(Optional.of("value"), entry.getField(new UnknownField("tEsT"))); + } + + @Test + public void getFieldWorksWithBibFieldAsWell() throws Exception { + entry.setField(StandardField.AUTHOR, "value"); + assertEquals(Optional.of("value"), entry.getField(new BibField(StandardField.AUTHOR, FieldPriority.IMPORTANT).getField())); + } + + @Test + public void setFieldWorksWithBibFieldAsWell() throws Exception { + entry.setField(new BibField(StandardField.AUTHOR, FieldPriority.IMPORTANT).getField(), "value"); + assertEquals(Optional.of("value"), entry.getField(StandardField.AUTHOR)); + } + + @Test + public void clonedBibEntryHasUniqueID() throws Exception { + BibEntry entryClone = (BibEntry) entry.clone(); + assertNotEquals(entry.getId(), entryClone.getId()); + } + + @Test + public void setAndGetAreConsistentForMonth() throws Exception { + entry.setField(StandardField.MONTH, "may"); + assertEquals(Optional.of("may"), entry.getField(StandardField.MONTH)); + } + + @Test + public void setAndGetAreConsistentForCapitalizedMonth() throws Exception { + entry.setField(StandardField.MONTH, "May"); + assertEquals(Optional.of("May"), entry.getField(StandardField.MONTH)); + } + + @Test + public void setAndGetAreConsistentForMonthString() throws Exception { + entry.setField(StandardField.MONTH, "#may#"); + assertEquals(Optional.of("#may#"), entry.getField(StandardField.MONTH)); + } + + @Test + public void monthCorrectlyReturnedForMonth() throws Exception { + entry.setField(StandardField.MONTH, "may"); + assertEquals(Optional.of(Month.MAY), entry.getMonth()); + } + + @Test + public void monthCorrectlyReturnedForCapitalizedMonth() throws Exception { + entry.setField(StandardField.MONTH, "May"); + assertEquals(Optional.of(Month.MAY), entry.getMonth()); + } + + @Test + public void monthCorrectlyReturnedForMonthString() throws Exception { + entry.setField(StandardField.MONTH, "#may#"); + assertEquals(Optional.of(Month.MAY), entry.getMonth()); + } + + @Test + public void monthCorrectlyReturnedForMonthMay() throws Exception { + entry.setMonth(Month.MAY); + assertEquals(Optional.of(Month.MAY), entry.getMonth()); + } + + @Test + public void monthFieldCorrectlyReturnedForMonthMay() throws Exception { + entry.setMonth(Month.MAY); + assertEquals(Optional.of("#may#"), entry.getField(StandardField.MONTH)); + } + + @Test + public void getFieldOrAliasDateWithYearNumericalMonthString() { + entry.setField(StandardField.YEAR, "2003"); + entry.setField(StandardField.MONTH, "3"); + assertEquals(Optional.of("2003-03"), entry.getFieldOrAlias(StandardField.DATE)); + } + + @Test + public void getFieldOrAliasDateWithYearAbbreviatedMonth() { + entry.setField(StandardField.YEAR, "2003"); + entry.setField(StandardField.MONTH, "#mar#"); + assertEquals(Optional.of("2003-03"), entry.getFieldOrAlias(StandardField.DATE)); + } + + @Test + public void getFieldOrAliasDateWithYearAbbreviatedMonthString() { + entry.setField(StandardField.YEAR, "2003"); + entry.setField(StandardField.MONTH, "mar"); + assertEquals(Optional.of("2003-03"), entry.getFieldOrAlias(StandardField.DATE)); + } + + @Test + public void getFieldOrAliasDateWithOnlyYear() { + entry.setField(StandardField.YEAR, "2003"); + assertEquals(Optional.of("2003"), entry.getFieldOrAlias(StandardField.DATE)); + } + + @Test + public void getFieldOrAliasYearWithDateYYYY() { + entry.setField(StandardField.DATE, "2003"); + assertEquals(Optional.of("2003"), entry.getFieldOrAlias(StandardField.YEAR)); + } + + @Test + public void getFieldOrAliasYearWithDateYYYYMM() { + entry.setField(StandardField.DATE, "2003-03"); + assertEquals(Optional.of("2003"), entry.getFieldOrAlias(StandardField.YEAR)); + } + + @Test + public void getFieldOrAliasYearWithDateYYYYMMDD() { + entry.setField(StandardField.DATE, "2003-03-30"); + assertEquals(Optional.of("2003"), entry.getFieldOrAlias(StandardField.YEAR)); + } + + @Test + public void getFieldOrAliasMonthWithDateYYYYReturnsNull() { + entry.setField(StandardField.DATE, "2003"); + assertEquals(Optional.empty(), entry.getFieldOrAlias(StandardField.MONTH)); + } + + @Test + public void getFieldOrAliasMonthWithDateYYYYMM() { + entry.setField(StandardField.DATE, "2003-03"); + assertEquals(Optional.of("#mar#"), entry.getFieldOrAlias(StandardField.MONTH)); + } + + @Test + public void getFieldOrAliasMonthWithDateYYYYMMDD() { + entry.setField(StandardField.DATE, "2003-03-30"); + assertEquals(Optional.of("#mar#"), entry.getFieldOrAlias(StandardField.MONTH)); + } + + @Test + public void getFieldOrAliasLatexFreeAlreadyFreeValueIsUnchanged() { + entry.setField(StandardField.TITLE, "A Title Without any LaTeX commands"); + assertEquals(Optional.of("A Title Without any LaTeX commands"), entry.getFieldOrAliasLatexFree(StandardField.TITLE)); + } + + @Test + public void getFieldOrAliasLatexFreeAlreadyFreeAliasValueIsUnchanged() { + entry.setField(StandardField.JOURNAL, "A Title Without any LaTeX commands"); + assertEquals(Optional.of("A Title Without any LaTeX commands"), entry.getFieldOrAliasLatexFree(StandardField.JOURNALTITLE)); + } + + @Test + public void getFieldOrAliasLatexFreeBracesAreRemoved() { + entry.setField(StandardField.TITLE, "{A Title with some {B}ra{C}es}"); + assertEquals(Optional.of("A Title with some BraCes"), entry.getFieldOrAliasLatexFree(StandardField.TITLE)); + } + + @Test + public void getFieldOrAliasLatexFreeBracesAreRemovedFromAlias() { + entry.setField(StandardField.JOURNAL, "{A Title with some {B}ra{C}es}"); + assertEquals(Optional.of("A Title with some BraCes"), entry.getFieldOrAliasLatexFree(StandardField.JOURNALTITLE)); + } + + @Test + public void getFieldOrAliasLatexFreeComplexConversionInAlias() { + entry.setField(StandardField.JOURNAL, "A 32~{mA} {$\\Sigma\\Delta$}-modulator"); + assertEquals(Optional.of("A 32 mA ΣΔ-modulator"), entry.getFieldOrAliasLatexFree(StandardField.JOURNALTITLE)); + } + + @Test + public void testGetAndAddToLinkedFileList() { + List files = entry.getFiles(); + files.add(new LinkedFile("", "", "")); + entry.setFiles(files); + assertEquals(Arrays.asList(new LinkedFile("", "", "")), entry.getFiles()); + } + + @Test + public void testGetEmptyKeywords() { + KeywordList actual = entry.getKeywords(','); + + assertEquals(new KeywordList(), actual); + } + + @Test + public void testGetSingleKeywords() { + entry.addKeyword("kw", ','); + KeywordList actual = entry.getKeywords(','); + + assertEquals(new KeywordList(new Keyword("kw")), actual); + } + + @Test + public void settingCiteKeyLeadsToCorrectCiteKey() { + assertFalse(entry.hasCiteKey()); + entry.setCiteKey("Einstein1931"); + assertEquals(Optional.of("Einstein1931"), entry.getCiteKeyOptional()); + } + + @Test + public void settingCiteKeyLeadsToHasCiteKy() { + assertFalse(entry.hasCiteKey()); + entry.setCiteKey("Einstein1931"); + assertTrue(entry.hasCiteKey()); + } + + @Test + public void clearFieldWorksForAuthor() { + entry.setField(StandardField.AUTHOR, "Albert Einstein"); + entry.clearField(StandardField.AUTHOR); + assertEquals(Optional.empty(), entry.getField(StandardField.AUTHOR)); + } + + @Test + public void setFieldWorksForAuthor() { + entry.setField(StandardField.AUTHOR, "Albert Einstein"); + assertEquals(Optional.of("Albert Einstein"), entry.getField(StandardField.AUTHOR)); + } +} diff --git a/src/test/java/org/jabref/model/entry/BibEntryWithKeywordsTest.java b/src/test/java/org/jabref/model/entry/BibEntryWithKeywordsTest.java new file mode 100644 index 00000000000..2ad3d867ba3 --- /dev/null +++ b/src/test/java/org/jabref/model/entry/BibEntryWithKeywordsTest.java @@ -0,0 +1,289 @@ +package org.jabref.model.entry; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Optional; + +import org.jabref.model.FieldChange; +import org.jabref.model.database.BibDatabase; +import org.jabref.model.entry.field.SpecialField; +import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.types.StandardEntryType; + +import com.google.common.collect.Sets; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class BibEntryWithKeywordsTest { + + private BibEntry keywordEntry; + + @BeforeEach + public void setUp() { + // Default entry for most keyword and some type tests + keywordEntry = new BibEntry(); + keywordEntry.setType(StandardEntryType.Article); + keywordEntry.setField(StandardField.KEYWORDS, "Foo, Bar"); + keywordEntry.setChanged(false); + } + + @Test + public void addNullKeywordThrowsNPE() { + assertThrows(NullPointerException.class, () -> keywordEntry.addKeyword((Keyword) null, ',')); + } + + @Test + public void putNullKeywordListThrowsNPE() { + assertThrows(NullPointerException.class, () -> keywordEntry.putKeywords((KeywordList) null, ',')); + } + + @Test + public void putNullKeywordSeparatorThrowsNPE() { + assertThrows(NullPointerException.class, () -> keywordEntry.putKeywords(Arrays.asList("A", "B"), null)); + } + + @Test + public void testGetSeparatedKeywordsAreCorrect() { + assertEquals(new KeywordList("Foo", "Bar"), keywordEntry.getKeywords(',')); + } + + @Test + public void testAddKeywordIsCorrect() { + keywordEntry.addKeyword("FooBar", ','); + assertEquals(new KeywordList("Foo", "Bar", "FooBar"), keywordEntry.getKeywords(',')); + } + + @Test + public void testAddKeywordHasChanged() { + keywordEntry.addKeyword("FooBar", ','); + assertTrue(keywordEntry.hasChanged()); + } + + @Test + public void testAddKeywordTwiceYiedsOnlyOne() { + keywordEntry.addKeyword("FooBar", ','); + keywordEntry.addKeyword("FooBar", ','); + assertEquals(new KeywordList("Foo", "Bar", "FooBar"), keywordEntry.getKeywords(',')); + } + + @Test + public void addKeywordIsCaseSensitive() { + keywordEntry.addKeyword("FOO", ','); + assertEquals(new KeywordList("Foo", "Bar", "FOO"), keywordEntry.getKeywords(',')); + } + + @Test + public void testAddKeywordWithDifferentCapitalizationChanges() { + keywordEntry.addKeyword("FOO", ','); + assertTrue(keywordEntry.hasChanged()); + } + + @Test + public void testAddKeywordEmptyKeywordIsNotAdded() { + keywordEntry.addKeyword("", ','); + assertEquals(new KeywordList("Foo", "Bar"), keywordEntry.getKeywords(',')); + } + + @Test + public void testAddKeywordEmptyKeywordNotChanged() { + keywordEntry.addKeyword("", ','); + assertFalse(keywordEntry.hasChanged()); + } + + @Test + public void texNewBibEntryHasNoKeywords() { + BibEntry entry = new BibEntry(); + assertTrue(entry.getKeywords(',').isEmpty()); + } + + @Test + public void texNewBibEntryHasNoKeywordsEvenAfterAddingEmptyKeyword() { + BibEntry entry = new BibEntry(); + entry.addKeyword("", ','); + assertTrue(entry.getKeywords(',').isEmpty()); + } + + @Test + public void texNewBibEntryAfterAddingEmptyKeywordNotChanged() { + BibEntry entry = new BibEntry(); + entry.addKeyword("", ','); + assertFalse(entry.hasChanged()); + } + + @Test + public void testAddKeywordsWorksAsExpected() { + BibEntry entry = new BibEntry(); + entry.addKeywords(Arrays.asList("Foo", "Bar"), ','); + assertEquals(new KeywordList("Foo", "Bar"), entry.getKeywords(',')); + } + + @Test + public void testPutKeywordsOverwritesOldKeywords() { + keywordEntry.putKeywords(Arrays.asList("Yin", "Yang"), ','); + assertEquals(new KeywordList("Yin", "Yang"), keywordEntry.getKeywords(',')); + } + + @Test + public void testPutKeywordsHasChanged() { + keywordEntry.putKeywords(Arrays.asList("Yin", "Yang"), ','); + assertTrue(keywordEntry.hasChanged()); + } + + @Test + public void testPutKeywordsPutEmpyListErasesPreviousKeywords() { + keywordEntry.putKeywords(Collections.emptyList(), ','); + assertTrue(keywordEntry.getKeywords(',').isEmpty()); + } + + @Test + public void testPutKeywordsPutEmpyListHasChanged() { + keywordEntry.putKeywords(Collections.emptyList(), ','); + assertTrue(keywordEntry.hasChanged()); + } + + @Test + public void testPutKeywordsPutEmpyListToEmptyBibentry() { + BibEntry entry = new BibEntry(); + entry.putKeywords(Collections.emptyList(), ','); + assertTrue(entry.getKeywords(',').isEmpty()); + } + + @Test + public void testPutKeywordsPutEmpyListToEmptyBibentryNotChanged() { + BibEntry entry = new BibEntry(); + entry.putKeywords(Collections.emptyList(), ','); + assertFalse(entry.hasChanged()); + } + + @Test + public void putKeywordsToEmptyReturnsNoChange() { + BibEntry entry = new BibEntry(); + Optional change = entry.putKeywords(Collections.emptyList(), ','); + assertEquals(Optional.empty(), change); + } + + @Test + public void clearKeywordsReturnsChange() { + Optional change = keywordEntry.putKeywords(Collections.emptyList(), ','); + assertEquals(Optional.of(new FieldChange(keywordEntry, StandardField.KEYWORDS, "Foo, Bar", null)), change); + } + + @Test + public void changeKeywordsReturnsChange() { + Optional change = keywordEntry.putKeywords(Arrays.asList("Test", "FooTest"), ','); + assertEquals(Optional.of(new FieldChange(keywordEntry, StandardField.KEYWORDS, "Foo, Bar", "Test, FooTest")), + change); + } + + @Test + public void putKeywordsToSameReturnsNoChange() { + Optional change = keywordEntry.putKeywords(Arrays.asList("Foo", "Bar"), ','); + assertEquals(Optional.empty(), change); + } + + @Test + public void getKeywordsReturnsParsedKeywordListFromKeywordsField() { + BibEntry entry = new BibEntry(); + entry.setField(StandardField.KEYWORDS, "w1, w2a w2b, w3"); + assertEquals(new KeywordList("w1", "w2a w2b", "w3"), entry.getKeywords(',')); + } + + @Test + public void removeKeywordsOnEntryWithoutKeywordsDoesNothing() { + BibEntry entry = new BibEntry(); + Optional change = entry.removeKeywords(SpecialField.RANKING.getKeyWords(), ','); + assertEquals(Optional.empty(), change); + } + + @Test + public void removeKeywordsWithEmptyListDoesNothing() { + keywordEntry.putKeywords(Arrays.asList("kw1", "kw2"), ','); + Optional change = keywordEntry.removeKeywords(new KeywordList(), ','); + assertEquals(Optional.empty(), change); + } + + @Test + public void removeKeywordsWithNonExistingKeywordsDoesNothing() { + keywordEntry.putKeywords(Arrays.asList("kw1", "kw2"), ','); + Optional change = keywordEntry.removeKeywords(KeywordList.parse("kw3, kw4", ','), ','); + assertEquals(Optional.empty(), change); + assertEquals(Sets.newHashSet("kw1", "kw2"), keywordEntry.getKeywords(',').toStringList()); + } + + @Test + public void removeKeywordsWithExistingKeywordsRemovesThem() { + keywordEntry.putKeywords(Arrays.asList("kw1", "kw2", "kw3"), ','); + Optional change = keywordEntry.removeKeywords(KeywordList.parse("kw1, kw2", ','), ','); + assertTrue(change.isPresent()); + assertEquals(KeywordList.parse("kw3", ','), keywordEntry.getKeywords(',')); + } + + @Test + public void keywordListCorrectlyConstructedForThreeKeywords() { + BibEntry entry = new BibEntry(); + entry.addKeyword("kw", ','); + entry.addKeyword("kw2", ','); + entry.addKeyword("kw3", ','); + KeywordList actual = entry.getKeywords(','); + assertEquals(new KeywordList(new Keyword("kw"), new Keyword("kw2"), new Keyword("kw3")), actual); + } + + @Test + public void testGetEmptyResolvedKeywords() { + BibDatabase database = new BibDatabase(); + BibEntry entry = new BibEntry(); + entry.setField(StandardField.CROSSREF, "entry2"); + database.insertEntry(entry); + + BibEntry entry2 = new BibEntry(); + entry2.setCiteKey("entry2"); + database.insertEntry(entry2); + + KeywordList actual = entry.getResolvedKeywords(',', database); + + assertEquals(new KeywordList(), actual); + } + + @Test + public void testGetSingleResolvedKeywords() { + BibDatabase database = new BibDatabase(); + BibEntry entry = new BibEntry(); + entry.setField(StandardField.CROSSREF, "entry2"); + + BibEntry entry2 = new BibEntry(); + entry2.setCiteKey("entry2"); + entry2.addKeyword("kw", ','); + + database.insertEntry(entry2); + database.insertEntry(entry); + + KeywordList actual = entry.getResolvedKeywords(',', database); + + assertEquals(new KeywordList(new Keyword("kw")), actual); + } + + @Test + public void testGetResolvedKeywords() { + BibDatabase database = new BibDatabase(); + BibEntry entry = new BibEntry(); + entry.setField(StandardField.CROSSREF, "entry2"); + + BibEntry entry2 = new BibEntry(); + entry2.setCiteKey("entry2"); + entry2.addKeyword("kw", ','); + entry2.addKeyword("kw2", ','); + entry2.addKeyword("kw3", ','); + + database.insertEntry(entry2); + database.insertEntry(entry); + + KeywordList actual = entry.getResolvedKeywords(',', database); + + assertEquals(new KeywordList(new Keyword("kw"), new Keyword("kw2"), new Keyword("kw3")), actual); + } +} diff --git a/src/test/java/org/jabref/model/entry/CanonicalBibEntryTest.java b/src/test/java/org/jabref/model/entry/CanonicalBibEntryTest.java index f4ce6967dfa..6d692112871 100644 --- a/src/test/java/org/jabref/model/entry/CanonicalBibEntryTest.java +++ b/src/test/java/org/jabref/model/entry/CanonicalBibEntryTest.java @@ -7,7 +7,16 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -public class CanonicalBibEntryTest { +class CanonicalBibEntryTest { + + @Test + void canonicalRepresentationIsCorrectForStringMonth() { + BibEntry entry = new BibEntry(); + entry.setMonth(Month.MAY); + assertEquals("@misc{,\n" + + " month = {#may#}\n" + + "}", CanonicalBibEntry.getCanonicalRepresentation(entry)); + } @Test public void simpleCanonicalRepresentation() { @@ -16,7 +25,7 @@ public void simpleCanonicalRepresentation() { e.setField(StandardField.AUTHOR, "abc"); e.setField(StandardField.TITLE, "def"); e.setField(StandardField.JOURNAL, "hij"); - String canonicalRepresentation = CanonicalBibtexEntry.getCanonicalRepresentation(e); + String canonicalRepresentation = CanonicalBibEntry.getCanonicalRepresentation(e); assertEquals("@article{key,\n author = {abc},\n journal = {hij},\n title = {def}\n}", canonicalRepresentation); } @@ -26,7 +35,7 @@ public void canonicalRepresentationWithNewlines() { BibEntry e = new BibEntry(StandardEntryType.Article); e.setCiteKey("key"); e.setField(StandardField.ABSTRACT, "line 1\nline 2"); - String canonicalRepresentation = CanonicalBibtexEntry.getCanonicalRepresentation(e); + String canonicalRepresentation = CanonicalBibEntry.getCanonicalRepresentation(e); assertEquals("@article{key,\n abstract = {line 1\nline 2}\n}", canonicalRepresentation); } } diff --git a/src/test/resources/testbib/saveactions2.bib b/src/test/resources/testbib/saveactions2.bib index 284697a6741..613eda350fe 100644 --- a/src/test/resources/testbib/saveactions2.bib +++ b/src/test/resources/testbib/saveactions2.bib @@ -7,7 +7,7 @@ @InProceedings{Pautasso2015TowardsWorkflowBenchmarking year = {2015}, pages = {1--20}, address = {Hamburg, Germany}, - month = mar + month = mar, file = {:Pautasso2015TowardsWorkflowBenchmarking.pdf:PDF}, keywords = {benchflow} } From 7c748869bbf7e52e581a99beae67851789ab7b39 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Wed, 13 Nov 2019 22:06:02 +0100 Subject: [PATCH 3/3] Merge all BibEntry test classes into one --- .../model/entry/BibEntryEqualityTest.java | 44 -- .../org/jabref/model/entry/BibEntryTest.java | 554 +++++++++++++++++- .../BibEntryWithDefaultConstructorTest.java | 272 --------- .../model/entry/BibEntryWithKeywordsTest.java | 289 --------- 4 files changed, 550 insertions(+), 609 deletions(-) delete mode 100644 src/test/java/org/jabref/model/entry/BibEntryEqualityTest.java delete mode 100644 src/test/java/org/jabref/model/entry/BibEntryWithDefaultConstructorTest.java delete mode 100644 src/test/java/org/jabref/model/entry/BibEntryWithKeywordsTest.java diff --git a/src/test/java/org/jabref/model/entry/BibEntryEqualityTest.java b/src/test/java/org/jabref/model/entry/BibEntryEqualityTest.java deleted file mode 100644 index d438d3412bb..00000000000 --- a/src/test/java/org/jabref/model/entry/BibEntryEqualityTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.jabref.model.entry; - -import org.jabref.model.entry.field.UnknownField; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class BibEntryEqualityTest { - @Test - public void identicObjectsareEqual() throws Exception { - BibEntry e1 = new BibEntry(); - BibEntry e2 = e1; - assertTrue(e1.equals(e2)); - } - - @Test - public void compareToNullObjectIsFalse() throws Exception { - BibEntry e1 = new BibEntry(); - assertFalse(e1.equals(null)); - } - - @Test - public void compareToDifferentClassIsFalse() throws Exception { - BibEntry e1 = new BibEntry(); - Object e2 = new Object(); - assertFalse(e1.equals(e2)); - } - - @Test - public void compareIsTrueWhenIdAndFieldsAreEqual() throws Exception { - BibEntry e1 = new BibEntry(); - e1.setId("1"); - e1.setField(new UnknownField("key"), "value"); - BibEntry e2 = new BibEntry(); - e2.setId("1"); - assertNotEquals(e1, e2); - e2.setField(new UnknownField("key"), "value"); - assertEquals(e1, e2); - } -} diff --git a/src/test/java/org/jabref/model/entry/BibEntryTest.java b/src/test/java/org/jabref/model/entry/BibEntryTest.java index 65bfeb66abd..ddfe5dab35c 100644 --- a/src/test/java/org/jabref/model/entry/BibEntryTest.java +++ b/src/test/java/org/jabref/model/entry/BibEntryTest.java @@ -1,24 +1,279 @@ package org.jabref.model.entry; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.Optional; +import org.jabref.model.FieldChange; +import org.jabref.model.database.BibDatabase; +import org.jabref.model.entry.field.BibField; +import org.jabref.model.entry.field.FieldPriority; import org.jabref.model.entry.field.InternalField; import org.jabref.model.entry.field.OrFields; +import org.jabref.model.entry.field.SpecialField; import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.field.UnknownField; import org.jabref.model.entry.types.StandardEntryType; +import com.google.common.collect.Sets; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -/** - * Contains misc tests for BibEntry especially not using the default constructor: {@link - * BibEntryWithDefaultConstructorTest} - */ class BibEntryTest { + private BibEntry entry; + + @BeforeEach + public void setUp() { + entry = new BibEntry(); + } + + @AfterEach + public void tearDown() { + entry = null; + } + + @Test + public void testDefaultConstructor() { + assertEquals(StandardEntryType.Misc, entry.getType()); + assertNotNull(entry.getId()); + assertFalse(entry.getField(StandardField.AUTHOR).isPresent()); + } + + @Test + public void settingTypeToNullThrowsException() { + assertThrows(NullPointerException.class, () -> entry.setType(null)); + } + + @Test + public void setNullFieldThrowsNPE() { + assertThrows(NullPointerException.class, () -> entry.setField(null)); + } + + @Test + public void getFieldIsCaseInsensitive() throws Exception { + entry.setField(new UnknownField("TeSt"), "value"); + assertEquals(Optional.of("value"), entry.getField(new UnknownField("tEsT"))); + } + + @Test + public void getFieldWorksWithBibFieldAsWell() throws Exception { + entry.setField(StandardField.AUTHOR, "value"); + assertEquals(Optional.of("value"), entry.getField(new BibField(StandardField.AUTHOR, FieldPriority.IMPORTANT).getField())); + } + + @Test + public void setFieldWorksWithBibFieldAsWell() throws Exception { + entry.setField(new BibField(StandardField.AUTHOR, FieldPriority.IMPORTANT).getField(), "value"); + assertEquals(Optional.of("value"), entry.getField(StandardField.AUTHOR)); + } + + @Test + public void clonedBibEntryHasUniqueID() throws Exception { + BibEntry entryClone = (BibEntry) entry.clone(); + assertNotEquals(entry.getId(), entryClone.getId()); + } + + @Test + public void setAndGetAreConsistentForMonth() throws Exception { + entry.setField(StandardField.MONTH, "may"); + assertEquals(Optional.of("may"), entry.getField(StandardField.MONTH)); + } + + @Test + public void setAndGetAreConsistentForCapitalizedMonth() throws Exception { + entry.setField(StandardField.MONTH, "May"); + assertEquals(Optional.of("May"), entry.getField(StandardField.MONTH)); + } + + @Test + public void setAndGetAreConsistentForMonthString() throws Exception { + entry.setField(StandardField.MONTH, "#may#"); + assertEquals(Optional.of("#may#"), entry.getField(StandardField.MONTH)); + } + + @Test + public void monthCorrectlyReturnedForMonth() throws Exception { + entry.setField(StandardField.MONTH, "may"); + assertEquals(Optional.of(Month.MAY), entry.getMonth()); + } + + @Test + public void monthCorrectlyReturnedForCapitalizedMonth() throws Exception { + entry.setField(StandardField.MONTH, "May"); + assertEquals(Optional.of(Month.MAY), entry.getMonth()); + } + + @Test + public void monthCorrectlyReturnedForMonthString() throws Exception { + entry.setField(StandardField.MONTH, "#may#"); + assertEquals(Optional.of(Month.MAY), entry.getMonth()); + } + + @Test + public void monthCorrectlyReturnedForMonthMay() throws Exception { + entry.setMonth(Month.MAY); + assertEquals(Optional.of(Month.MAY), entry.getMonth()); + } + + @Test + public void monthFieldCorrectlyReturnedForMonthMay() throws Exception { + entry.setMonth(Month.MAY); + assertEquals(Optional.of("#may#"), entry.getField(StandardField.MONTH)); + } + + @Test + public void getFieldOrAliasDateWithYearNumericalMonthString() { + entry.setField(StandardField.YEAR, "2003"); + entry.setField(StandardField.MONTH, "3"); + assertEquals(Optional.of("2003-03"), entry.getFieldOrAlias(StandardField.DATE)); + } + + @Test + public void getFieldOrAliasDateWithYearAbbreviatedMonth() { + entry.setField(StandardField.YEAR, "2003"); + entry.setField(StandardField.MONTH, "#mar#"); + assertEquals(Optional.of("2003-03"), entry.getFieldOrAlias(StandardField.DATE)); + } + + @Test + public void getFieldOrAliasDateWithYearAbbreviatedMonthString() { + entry.setField(StandardField.YEAR, "2003"); + entry.setField(StandardField.MONTH, "mar"); + assertEquals(Optional.of("2003-03"), entry.getFieldOrAlias(StandardField.DATE)); + } + + @Test + public void getFieldOrAliasDateWithOnlyYear() { + entry.setField(StandardField.YEAR, "2003"); + assertEquals(Optional.of("2003"), entry.getFieldOrAlias(StandardField.DATE)); + } + + @Test + public void getFieldOrAliasYearWithDateYYYY() { + entry.setField(StandardField.DATE, "2003"); + assertEquals(Optional.of("2003"), entry.getFieldOrAlias(StandardField.YEAR)); + } + + @Test + public void getFieldOrAliasYearWithDateYYYYMM() { + entry.setField(StandardField.DATE, "2003-03"); + assertEquals(Optional.of("2003"), entry.getFieldOrAlias(StandardField.YEAR)); + } + + @Test + public void getFieldOrAliasYearWithDateYYYYMMDD() { + entry.setField(StandardField.DATE, "2003-03-30"); + assertEquals(Optional.of("2003"), entry.getFieldOrAlias(StandardField.YEAR)); + } + + @Test + public void getFieldOrAliasMonthWithDateYYYYReturnsNull() { + entry.setField(StandardField.DATE, "2003"); + assertEquals(Optional.empty(), entry.getFieldOrAlias(StandardField.MONTH)); + } + + @Test + public void getFieldOrAliasMonthWithDateYYYYMM() { + entry.setField(StandardField.DATE, "2003-03"); + assertEquals(Optional.of("#mar#"), entry.getFieldOrAlias(StandardField.MONTH)); + } + + @Test + public void getFieldOrAliasMonthWithDateYYYYMMDD() { + entry.setField(StandardField.DATE, "2003-03-30"); + assertEquals(Optional.of("#mar#"), entry.getFieldOrAlias(StandardField.MONTH)); + } + + @Test + public void getFieldOrAliasLatexFreeAlreadyFreeValueIsUnchanged() { + entry.setField(StandardField.TITLE, "A Title Without any LaTeX commands"); + assertEquals(Optional.of("A Title Without any LaTeX commands"), entry.getFieldOrAliasLatexFree(StandardField.TITLE)); + } + + @Test + public void getFieldOrAliasLatexFreeAlreadyFreeAliasValueIsUnchanged() { + entry.setField(StandardField.JOURNAL, "A Title Without any LaTeX commands"); + assertEquals(Optional.of("A Title Without any LaTeX commands"), entry.getFieldOrAliasLatexFree(StandardField.JOURNALTITLE)); + } + + @Test + public void getFieldOrAliasLatexFreeBracesAreRemoved() { + entry.setField(StandardField.TITLE, "{A Title with some {B}ra{C}es}"); + assertEquals(Optional.of("A Title with some BraCes"), entry.getFieldOrAliasLatexFree(StandardField.TITLE)); + } + + @Test + public void getFieldOrAliasLatexFreeBracesAreRemovedFromAlias() { + entry.setField(StandardField.JOURNAL, "{A Title with some {B}ra{C}es}"); + assertEquals(Optional.of("A Title with some BraCes"), entry.getFieldOrAliasLatexFree(StandardField.JOURNALTITLE)); + } + + @Test + public void getFieldOrAliasLatexFreeComplexConversionInAlias() { + entry.setField(StandardField.JOURNAL, "A 32~{mA} {$\\Sigma\\Delta$}-modulator"); + assertEquals(Optional.of("A 32 mA ΣΔ-modulator"), entry.getFieldOrAliasLatexFree(StandardField.JOURNALTITLE)); + } + + @Test + public void testGetAndAddToLinkedFileList() { + List files = entry.getFiles(); + files.add(new LinkedFile("", "", "")); + entry.setFiles(files); + assertEquals(Arrays.asList(new LinkedFile("", "", "")), entry.getFiles()); + } + + @Test + public void testGetEmptyKeywords() { + KeywordList actual = entry.getKeywords(','); + + assertEquals(new KeywordList(), actual); + } + + @Test + public void testGetSingleKeywords() { + entry.addKeyword("kw", ','); + KeywordList actual = entry.getKeywords(','); + + assertEquals(new KeywordList(new Keyword("kw")), actual); + } + + @Test + public void settingCiteKeyLeadsToCorrectCiteKey() { + assertFalse(entry.hasCiteKey()); + entry.setCiteKey("Einstein1931"); + assertEquals(Optional.of("Einstein1931"), entry.getCiteKeyOptional()); + } + + @Test + public void settingCiteKeyLeadsToHasCiteKy() { + assertFalse(entry.hasCiteKey()); + entry.setCiteKey("Einstein1931"); + assertTrue(entry.hasCiteKey()); + } + + @Test + public void clearFieldWorksForAuthor() { + entry.setField(StandardField.AUTHOR, "Albert Einstein"); + entry.clearField(StandardField.AUTHOR); + assertEquals(Optional.empty(), entry.getField(StandardField.AUTHOR)); + } + + @Test + public void setFieldWorksForAuthor() { + entry.setField(StandardField.AUTHOR, "Albert Einstein"); + assertEquals(Optional.of("Albert Einstein"), entry.getField(StandardField.AUTHOR)); + } + @Test public void allFieldsPresentDefault() { BibEntry e = new BibEntry(StandardEntryType.Article); @@ -70,4 +325,295 @@ public void isEmptyCiteKey() { e.clearField(InternalField.KEY_FIELD); assertFalse(e.hasCiteKey()); } + + @Test + public void identicObjectsareEqual() throws Exception { + BibEntry otherEntry = entry; + assertTrue(entry.equals(otherEntry)); + } + + @Test + public void compareToNullObjectIsFalse() throws Exception { + assertFalse(entry.equals(null)); + } + + @Test + public void compareToDifferentClassIsFalse() throws Exception { + assertFalse(entry.equals(new Object())); + } + + @Test + public void compareIsTrueWhenIdAndFieldsAreEqual() throws Exception { + entry.setId("1"); + entry.setField(new UnknownField("key"), "value"); + BibEntry otherEntry = new BibEntry(); + otherEntry.setId("1"); + assertNotEquals(entry, otherEntry); + otherEntry.setField(new UnknownField("key"), "value"); + assertEquals(entry, otherEntry); + } + + @Test + public void addNullKeywordThrowsNPE() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + assertThrows(NullPointerException.class, () -> entry.addKeyword((Keyword) null, ',')); + } + + @Test + public void putNullKeywordListThrowsNPE() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + assertThrows(NullPointerException.class, () -> entry.putKeywords((KeywordList) null, ',')); + } + + @Test + public void putNullKeywordSeparatorThrowsNPE() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + assertThrows(NullPointerException.class, () -> entry.putKeywords(Arrays.asList("A", "B"), null)); + } + + @Test + public void testGetSeparatedKeywordsAreCorrect() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + assertEquals(new KeywordList("Foo", "Bar"), entry.getKeywords(',')); + } + + @Test + public void testAddKeywordIsCorrect() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + entry.addKeyword("FooBar", ','); + assertEquals(new KeywordList("Foo", "Bar", "FooBar"), entry.getKeywords(',')); + } + + @Test + public void testAddKeywordHasChanged() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + entry.addKeyword("FooBar", ','); + assertTrue(entry.hasChanged()); + } + + @Test + public void testAddKeywordTwiceYiedsOnlyOne() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + entry.addKeyword("FooBar", ','); + entry.addKeyword("FooBar", ','); + assertEquals(new KeywordList("Foo", "Bar", "FooBar"), entry.getKeywords(',')); + } + + @Test + public void addKeywordIsCaseSensitive() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + entry.addKeyword("FOO", ','); + assertEquals(new KeywordList("Foo", "Bar", "FOO"), entry.getKeywords(',')); + } + + @Test + public void testAddKeywordWithDifferentCapitalizationChanges() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + entry.addKeyword("FOO", ','); + assertTrue(entry.hasChanged()); + } + + @Test + public void testAddKeywordEmptyKeywordIsNotAdded() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + entry.addKeyword("", ','); + assertEquals(new KeywordList("Foo", "Bar"), entry.getKeywords(',')); + } + + @Test + public void testAddKeywordEmptyKeywordNotChanged() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + entry.setChanged(false); + entry.addKeyword("", ','); + assertFalse(entry.hasChanged()); + } + + @Test + public void texNewBibEntryHasNoKeywords() { + assertTrue(entry.getKeywords(',').isEmpty()); + } + + @Test + public void texNewBibEntryHasNoKeywordsEvenAfterAddingEmptyKeyword() { + entry.addKeyword("", ','); + assertTrue(entry.getKeywords(',').isEmpty()); + } + + @Test + public void texNewBibEntryAfterAddingEmptyKeywordNotChanged() { + entry.addKeyword("", ','); + assertFalse(entry.hasChanged()); + } + + @Test + public void testAddKeywordsWorksAsExpected() { + entry.addKeywords(Arrays.asList("Foo", "Bar"), ','); + assertEquals(new KeywordList("Foo", "Bar"), entry.getKeywords(',')); + } + + @Test + public void testPutKeywordsOverwritesOldKeywords() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + entry.putKeywords(Arrays.asList("Yin", "Yang"), ','); + assertEquals(new KeywordList("Yin", "Yang"), entry.getKeywords(',')); + } + + @Test + public void testPutKeywordsHasChanged() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + entry.putKeywords(Arrays.asList("Yin", "Yang"), ','); + assertTrue(entry.hasChanged()); + } + + @Test + public void testPutKeywordsPutEmpyListErasesPreviousKeywords() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + entry.putKeywords(Collections.emptyList(), ','); + assertTrue(entry.getKeywords(',').isEmpty()); + } + + @Test + public void testPutKeywordsPutEmpyListHasChanged() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + entry.putKeywords(Collections.emptyList(), ','); + assertTrue(entry.hasChanged()); + } + + @Test + public void testPutKeywordsPutEmpyListToEmptyBibentry() { + entry.putKeywords(Collections.emptyList(), ','); + assertTrue(entry.getKeywords(',').isEmpty()); + } + + @Test + public void testPutKeywordsPutEmpyListToEmptyBibentryNotChanged() { + entry.putKeywords(Collections.emptyList(), ','); + assertFalse(entry.hasChanged()); + } + + @Test + public void putKeywordsToEmptyReturnsNoChange() { + Optional change = entry.putKeywords(Collections.emptyList(), ','); + assertEquals(Optional.empty(), change); + } + + @Test + public void clearKeywordsReturnsChange() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + Optional change = entry.putKeywords(Collections.emptyList(), ','); + assertEquals(Optional.of(new FieldChange(entry, StandardField.KEYWORDS, "Foo, Bar", null)), change); + } + + @Test + public void changeKeywordsReturnsChange() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + Optional change = entry.putKeywords(Arrays.asList("Test", "FooTest"), ','); + assertEquals(Optional.of(new FieldChange(entry, StandardField.KEYWORDS, "Foo, Bar", "Test, FooTest")), + change); + } + + @Test + public void putKeywordsToSameReturnsNoChange() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + Optional change = entry.putKeywords(Arrays.asList("Foo", "Bar"), ','); + assertEquals(Optional.empty(), change); + } + + @Test + public void getKeywordsReturnsParsedKeywordListFromKeywordsField() { + entry.setField(StandardField.KEYWORDS, "w1, w2a w2b, w3"); + assertEquals(new KeywordList("w1", "w2a w2b", "w3"), entry.getKeywords(',')); + } + + @Test + public void removeKeywordsOnEntryWithoutKeywordsDoesNothing() { + Optional change = entry.removeKeywords(SpecialField.RANKING.getKeyWords(), ','); + assertEquals(Optional.empty(), change); + } + + @Test + public void removeKeywordsWithEmptyListDoesNothing() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + entry.putKeywords(Arrays.asList("kw1", "kw2"), ','); + Optional change = entry.removeKeywords(new KeywordList(), ','); + assertEquals(Optional.empty(), change); + } + + @Test + public void removeKeywordsWithNonExistingKeywordsDoesNothing() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + entry.putKeywords(Arrays.asList("kw1", "kw2"), ','); + Optional change = entry.removeKeywords(KeywordList.parse("kw3, kw4", ','), ','); + assertEquals(Optional.empty(), change); + assertEquals(Sets.newHashSet("kw1", "kw2"), entry.getKeywords(',').toStringList()); + } + + @Test + public void removeKeywordsWithExistingKeywordsRemovesThem() { + entry.setField(StandardField.KEYWORDS, "Foo, Bar"); + entry.putKeywords(Arrays.asList("kw1", "kw2", "kw3"), ','); + Optional change = entry.removeKeywords(KeywordList.parse("kw1, kw2", ','), ','); + assertTrue(change.isPresent()); + assertEquals(KeywordList.parse("kw3", ','), entry.getKeywords(',')); + } + + @Test + public void keywordListCorrectlyConstructedForThreeKeywords() { + entry.addKeyword("kw", ','); + entry.addKeyword("kw2", ','); + entry.addKeyword("kw3", ','); + KeywordList actual = entry.getKeywords(','); + assertEquals(new KeywordList(new Keyword("kw"), new Keyword("kw2"), new Keyword("kw3")), actual); + } + + @Test + public void testGetEmptyResolvedKeywords() { + BibDatabase database = new BibDatabase(); + entry.setField(StandardField.CROSSREF, "entry2"); + database.insertEntry(entry); + + BibEntry entry2 = new BibEntry(); + entry2.setCiteKey("entry2"); + database.insertEntry(entry2); + + KeywordList actual = entry.getResolvedKeywords(',', database); + + assertEquals(new KeywordList(), actual); + } + + @Test + public void testGetSingleResolvedKeywords() { + BibDatabase database = new BibDatabase(); + entry.setField(StandardField.CROSSREF, "entry2"); + + BibEntry entry2 = new BibEntry(); + entry2.setCiteKey("entry2"); + entry2.addKeyword("kw", ','); + + database.insertEntry(entry2); + database.insertEntry(entry); + + KeywordList actual = entry.getResolvedKeywords(',', database); + + assertEquals(new KeywordList(new Keyword("kw")), actual); + } + + @Test + public void testGetResolvedKeywords() { + BibDatabase database = new BibDatabase(); + entry.setField(StandardField.CROSSREF, "entry2"); + + BibEntry entry2 = new BibEntry(); + entry2.setCiteKey("entry2"); + entry2.addKeyword("kw", ','); + entry2.addKeyword("kw2", ','); + entry2.addKeyword("kw3", ','); + + database.insertEntry(entry2); + database.insertEntry(entry); + + KeywordList actual = entry.getResolvedKeywords(',', database); + + assertEquals(new KeywordList(new Keyword("kw"), new Keyword("kw2"), new Keyword("kw3")), actual); + } } diff --git a/src/test/java/org/jabref/model/entry/BibEntryWithDefaultConstructorTest.java b/src/test/java/org/jabref/model/entry/BibEntryWithDefaultConstructorTest.java deleted file mode 100644 index 19f7fb035c3..00000000000 --- a/src/test/java/org/jabref/model/entry/BibEntryWithDefaultConstructorTest.java +++ /dev/null @@ -1,272 +0,0 @@ -package org.jabref.model.entry; - -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -import org.jabref.model.entry.field.BibField; -import org.jabref.model.entry.field.FieldPriority; -import org.jabref.model.entry.field.StandardField; -import org.jabref.model.entry.field.UnknownField; -import org.jabref.model.entry.types.StandardEntryType; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * Simple tests for a BibEntry. There are more test classes testing special features. - */ -public class BibEntryWithDefaultConstructorTest { - - private BibEntry entry; - - @BeforeEach - public void setUp() { - entry = new BibEntry(); - } - - @AfterEach - public void tearDown() { - entry = null; - } - - @Test - public void testDefaultConstructor() { - assertEquals(StandardEntryType.Misc, entry.getType()); - assertNotNull(entry.getId()); - assertFalse(entry.getField(StandardField.AUTHOR).isPresent()); - } - - @Test - public void settingTypeToNullThrowsException() { - assertThrows(NullPointerException.class, () -> entry.setType(null)); - } - - @Test - public void setNullFieldThrowsNPE() { - assertThrows(NullPointerException.class, () -> entry.setField(null)); - } - - @Test - public void getFieldIsCaseInsensitive() throws Exception { - entry.setField(new UnknownField("TeSt"), "value"); - assertEquals(Optional.of("value"), entry.getField(new UnknownField("tEsT"))); - } - - @Test - public void getFieldWorksWithBibFieldAsWell() throws Exception { - entry.setField(StandardField.AUTHOR, "value"); - assertEquals(Optional.of("value"), entry.getField(new BibField(StandardField.AUTHOR, FieldPriority.IMPORTANT).getField())); - } - - @Test - public void setFieldWorksWithBibFieldAsWell() throws Exception { - entry.setField(new BibField(StandardField.AUTHOR, FieldPriority.IMPORTANT).getField(), "value"); - assertEquals(Optional.of("value"), entry.getField(StandardField.AUTHOR)); - } - - @Test - public void clonedBibEntryHasUniqueID() throws Exception { - BibEntry entryClone = (BibEntry) entry.clone(); - assertNotEquals(entry.getId(), entryClone.getId()); - } - - @Test - public void setAndGetAreConsistentForMonth() throws Exception { - entry.setField(StandardField.MONTH, "may"); - assertEquals(Optional.of("may"), entry.getField(StandardField.MONTH)); - } - - @Test - public void setAndGetAreConsistentForCapitalizedMonth() throws Exception { - entry.setField(StandardField.MONTH, "May"); - assertEquals(Optional.of("May"), entry.getField(StandardField.MONTH)); - } - - @Test - public void setAndGetAreConsistentForMonthString() throws Exception { - entry.setField(StandardField.MONTH, "#may#"); - assertEquals(Optional.of("#may#"), entry.getField(StandardField.MONTH)); - } - - @Test - public void monthCorrectlyReturnedForMonth() throws Exception { - entry.setField(StandardField.MONTH, "may"); - assertEquals(Optional.of(Month.MAY), entry.getMonth()); - } - - @Test - public void monthCorrectlyReturnedForCapitalizedMonth() throws Exception { - entry.setField(StandardField.MONTH, "May"); - assertEquals(Optional.of(Month.MAY), entry.getMonth()); - } - - @Test - public void monthCorrectlyReturnedForMonthString() throws Exception { - entry.setField(StandardField.MONTH, "#may#"); - assertEquals(Optional.of(Month.MAY), entry.getMonth()); - } - - @Test - public void monthCorrectlyReturnedForMonthMay() throws Exception { - entry.setMonth(Month.MAY); - assertEquals(Optional.of(Month.MAY), entry.getMonth()); - } - - @Test - public void monthFieldCorrectlyReturnedForMonthMay() throws Exception { - entry.setMonth(Month.MAY); - assertEquals(Optional.of("#may#"), entry.getField(StandardField.MONTH)); - } - - @Test - public void getFieldOrAliasDateWithYearNumericalMonthString() { - entry.setField(StandardField.YEAR, "2003"); - entry.setField(StandardField.MONTH, "3"); - assertEquals(Optional.of("2003-03"), entry.getFieldOrAlias(StandardField.DATE)); - } - - @Test - public void getFieldOrAliasDateWithYearAbbreviatedMonth() { - entry.setField(StandardField.YEAR, "2003"); - entry.setField(StandardField.MONTH, "#mar#"); - assertEquals(Optional.of("2003-03"), entry.getFieldOrAlias(StandardField.DATE)); - } - - @Test - public void getFieldOrAliasDateWithYearAbbreviatedMonthString() { - entry.setField(StandardField.YEAR, "2003"); - entry.setField(StandardField.MONTH, "mar"); - assertEquals(Optional.of("2003-03"), entry.getFieldOrAlias(StandardField.DATE)); - } - - @Test - public void getFieldOrAliasDateWithOnlyYear() { - entry.setField(StandardField.YEAR, "2003"); - assertEquals(Optional.of("2003"), entry.getFieldOrAlias(StandardField.DATE)); - } - - @Test - public void getFieldOrAliasYearWithDateYYYY() { - entry.setField(StandardField.DATE, "2003"); - assertEquals(Optional.of("2003"), entry.getFieldOrAlias(StandardField.YEAR)); - } - - @Test - public void getFieldOrAliasYearWithDateYYYYMM() { - entry.setField(StandardField.DATE, "2003-03"); - assertEquals(Optional.of("2003"), entry.getFieldOrAlias(StandardField.YEAR)); - } - - @Test - public void getFieldOrAliasYearWithDateYYYYMMDD() { - entry.setField(StandardField.DATE, "2003-03-30"); - assertEquals(Optional.of("2003"), entry.getFieldOrAlias(StandardField.YEAR)); - } - - @Test - public void getFieldOrAliasMonthWithDateYYYYReturnsNull() { - entry.setField(StandardField.DATE, "2003"); - assertEquals(Optional.empty(), entry.getFieldOrAlias(StandardField.MONTH)); - } - - @Test - public void getFieldOrAliasMonthWithDateYYYYMM() { - entry.setField(StandardField.DATE, "2003-03"); - assertEquals(Optional.of("#mar#"), entry.getFieldOrAlias(StandardField.MONTH)); - } - - @Test - public void getFieldOrAliasMonthWithDateYYYYMMDD() { - entry.setField(StandardField.DATE, "2003-03-30"); - assertEquals(Optional.of("#mar#"), entry.getFieldOrAlias(StandardField.MONTH)); - } - - @Test - public void getFieldOrAliasLatexFreeAlreadyFreeValueIsUnchanged() { - entry.setField(StandardField.TITLE, "A Title Without any LaTeX commands"); - assertEquals(Optional.of("A Title Without any LaTeX commands"), entry.getFieldOrAliasLatexFree(StandardField.TITLE)); - } - - @Test - public void getFieldOrAliasLatexFreeAlreadyFreeAliasValueIsUnchanged() { - entry.setField(StandardField.JOURNAL, "A Title Without any LaTeX commands"); - assertEquals(Optional.of("A Title Without any LaTeX commands"), entry.getFieldOrAliasLatexFree(StandardField.JOURNALTITLE)); - } - - @Test - public void getFieldOrAliasLatexFreeBracesAreRemoved() { - entry.setField(StandardField.TITLE, "{A Title with some {B}ra{C}es}"); - assertEquals(Optional.of("A Title with some BraCes"), entry.getFieldOrAliasLatexFree(StandardField.TITLE)); - } - - @Test - public void getFieldOrAliasLatexFreeBracesAreRemovedFromAlias() { - entry.setField(StandardField.JOURNAL, "{A Title with some {B}ra{C}es}"); - assertEquals(Optional.of("A Title with some BraCes"), entry.getFieldOrAliasLatexFree(StandardField.JOURNALTITLE)); - } - - @Test - public void getFieldOrAliasLatexFreeComplexConversionInAlias() { - entry.setField(StandardField.JOURNAL, "A 32~{mA} {$\\Sigma\\Delta$}-modulator"); - assertEquals(Optional.of("A 32 mA ΣΔ-modulator"), entry.getFieldOrAliasLatexFree(StandardField.JOURNALTITLE)); - } - - @Test - public void testGetAndAddToLinkedFileList() { - List files = entry.getFiles(); - files.add(new LinkedFile("", "", "")); - entry.setFiles(files); - assertEquals(Arrays.asList(new LinkedFile("", "", "")), entry.getFiles()); - } - - @Test - public void testGetEmptyKeywords() { - KeywordList actual = entry.getKeywords(','); - - assertEquals(new KeywordList(), actual); - } - - @Test - public void testGetSingleKeywords() { - entry.addKeyword("kw", ','); - KeywordList actual = entry.getKeywords(','); - - assertEquals(new KeywordList(new Keyword("kw")), actual); - } - - @Test - public void settingCiteKeyLeadsToCorrectCiteKey() { - assertFalse(entry.hasCiteKey()); - entry.setCiteKey("Einstein1931"); - assertEquals(Optional.of("Einstein1931"), entry.getCiteKeyOptional()); - } - - @Test - public void settingCiteKeyLeadsToHasCiteKy() { - assertFalse(entry.hasCiteKey()); - entry.setCiteKey("Einstein1931"); - assertTrue(entry.hasCiteKey()); - } - - @Test - public void clearFieldWorksForAuthor() { - entry.setField(StandardField.AUTHOR, "Albert Einstein"); - entry.clearField(StandardField.AUTHOR); - assertEquals(Optional.empty(), entry.getField(StandardField.AUTHOR)); - } - - @Test - public void setFieldWorksForAuthor() { - entry.setField(StandardField.AUTHOR, "Albert Einstein"); - assertEquals(Optional.of("Albert Einstein"), entry.getField(StandardField.AUTHOR)); - } -} diff --git a/src/test/java/org/jabref/model/entry/BibEntryWithKeywordsTest.java b/src/test/java/org/jabref/model/entry/BibEntryWithKeywordsTest.java deleted file mode 100644 index 2ad3d867ba3..00000000000 --- a/src/test/java/org/jabref/model/entry/BibEntryWithKeywordsTest.java +++ /dev/null @@ -1,289 +0,0 @@ -package org.jabref.model.entry; - -import java.util.Arrays; -import java.util.Collections; -import java.util.Optional; - -import org.jabref.model.FieldChange; -import org.jabref.model.database.BibDatabase; -import org.jabref.model.entry.field.SpecialField; -import org.jabref.model.entry.field.StandardField; -import org.jabref.model.entry.types.StandardEntryType; - -import com.google.common.collect.Sets; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class BibEntryWithKeywordsTest { - - private BibEntry keywordEntry; - - @BeforeEach - public void setUp() { - // Default entry for most keyword and some type tests - keywordEntry = new BibEntry(); - keywordEntry.setType(StandardEntryType.Article); - keywordEntry.setField(StandardField.KEYWORDS, "Foo, Bar"); - keywordEntry.setChanged(false); - } - - @Test - public void addNullKeywordThrowsNPE() { - assertThrows(NullPointerException.class, () -> keywordEntry.addKeyword((Keyword) null, ',')); - } - - @Test - public void putNullKeywordListThrowsNPE() { - assertThrows(NullPointerException.class, () -> keywordEntry.putKeywords((KeywordList) null, ',')); - } - - @Test - public void putNullKeywordSeparatorThrowsNPE() { - assertThrows(NullPointerException.class, () -> keywordEntry.putKeywords(Arrays.asList("A", "B"), null)); - } - - @Test - public void testGetSeparatedKeywordsAreCorrect() { - assertEquals(new KeywordList("Foo", "Bar"), keywordEntry.getKeywords(',')); - } - - @Test - public void testAddKeywordIsCorrect() { - keywordEntry.addKeyword("FooBar", ','); - assertEquals(new KeywordList("Foo", "Bar", "FooBar"), keywordEntry.getKeywords(',')); - } - - @Test - public void testAddKeywordHasChanged() { - keywordEntry.addKeyword("FooBar", ','); - assertTrue(keywordEntry.hasChanged()); - } - - @Test - public void testAddKeywordTwiceYiedsOnlyOne() { - keywordEntry.addKeyword("FooBar", ','); - keywordEntry.addKeyword("FooBar", ','); - assertEquals(new KeywordList("Foo", "Bar", "FooBar"), keywordEntry.getKeywords(',')); - } - - @Test - public void addKeywordIsCaseSensitive() { - keywordEntry.addKeyword("FOO", ','); - assertEquals(new KeywordList("Foo", "Bar", "FOO"), keywordEntry.getKeywords(',')); - } - - @Test - public void testAddKeywordWithDifferentCapitalizationChanges() { - keywordEntry.addKeyword("FOO", ','); - assertTrue(keywordEntry.hasChanged()); - } - - @Test - public void testAddKeywordEmptyKeywordIsNotAdded() { - keywordEntry.addKeyword("", ','); - assertEquals(new KeywordList("Foo", "Bar"), keywordEntry.getKeywords(',')); - } - - @Test - public void testAddKeywordEmptyKeywordNotChanged() { - keywordEntry.addKeyword("", ','); - assertFalse(keywordEntry.hasChanged()); - } - - @Test - public void texNewBibEntryHasNoKeywords() { - BibEntry entry = new BibEntry(); - assertTrue(entry.getKeywords(',').isEmpty()); - } - - @Test - public void texNewBibEntryHasNoKeywordsEvenAfterAddingEmptyKeyword() { - BibEntry entry = new BibEntry(); - entry.addKeyword("", ','); - assertTrue(entry.getKeywords(',').isEmpty()); - } - - @Test - public void texNewBibEntryAfterAddingEmptyKeywordNotChanged() { - BibEntry entry = new BibEntry(); - entry.addKeyword("", ','); - assertFalse(entry.hasChanged()); - } - - @Test - public void testAddKeywordsWorksAsExpected() { - BibEntry entry = new BibEntry(); - entry.addKeywords(Arrays.asList("Foo", "Bar"), ','); - assertEquals(new KeywordList("Foo", "Bar"), entry.getKeywords(',')); - } - - @Test - public void testPutKeywordsOverwritesOldKeywords() { - keywordEntry.putKeywords(Arrays.asList("Yin", "Yang"), ','); - assertEquals(new KeywordList("Yin", "Yang"), keywordEntry.getKeywords(',')); - } - - @Test - public void testPutKeywordsHasChanged() { - keywordEntry.putKeywords(Arrays.asList("Yin", "Yang"), ','); - assertTrue(keywordEntry.hasChanged()); - } - - @Test - public void testPutKeywordsPutEmpyListErasesPreviousKeywords() { - keywordEntry.putKeywords(Collections.emptyList(), ','); - assertTrue(keywordEntry.getKeywords(',').isEmpty()); - } - - @Test - public void testPutKeywordsPutEmpyListHasChanged() { - keywordEntry.putKeywords(Collections.emptyList(), ','); - assertTrue(keywordEntry.hasChanged()); - } - - @Test - public void testPutKeywordsPutEmpyListToEmptyBibentry() { - BibEntry entry = new BibEntry(); - entry.putKeywords(Collections.emptyList(), ','); - assertTrue(entry.getKeywords(',').isEmpty()); - } - - @Test - public void testPutKeywordsPutEmpyListToEmptyBibentryNotChanged() { - BibEntry entry = new BibEntry(); - entry.putKeywords(Collections.emptyList(), ','); - assertFalse(entry.hasChanged()); - } - - @Test - public void putKeywordsToEmptyReturnsNoChange() { - BibEntry entry = new BibEntry(); - Optional change = entry.putKeywords(Collections.emptyList(), ','); - assertEquals(Optional.empty(), change); - } - - @Test - public void clearKeywordsReturnsChange() { - Optional change = keywordEntry.putKeywords(Collections.emptyList(), ','); - assertEquals(Optional.of(new FieldChange(keywordEntry, StandardField.KEYWORDS, "Foo, Bar", null)), change); - } - - @Test - public void changeKeywordsReturnsChange() { - Optional change = keywordEntry.putKeywords(Arrays.asList("Test", "FooTest"), ','); - assertEquals(Optional.of(new FieldChange(keywordEntry, StandardField.KEYWORDS, "Foo, Bar", "Test, FooTest")), - change); - } - - @Test - public void putKeywordsToSameReturnsNoChange() { - Optional change = keywordEntry.putKeywords(Arrays.asList("Foo", "Bar"), ','); - assertEquals(Optional.empty(), change); - } - - @Test - public void getKeywordsReturnsParsedKeywordListFromKeywordsField() { - BibEntry entry = new BibEntry(); - entry.setField(StandardField.KEYWORDS, "w1, w2a w2b, w3"); - assertEquals(new KeywordList("w1", "w2a w2b", "w3"), entry.getKeywords(',')); - } - - @Test - public void removeKeywordsOnEntryWithoutKeywordsDoesNothing() { - BibEntry entry = new BibEntry(); - Optional change = entry.removeKeywords(SpecialField.RANKING.getKeyWords(), ','); - assertEquals(Optional.empty(), change); - } - - @Test - public void removeKeywordsWithEmptyListDoesNothing() { - keywordEntry.putKeywords(Arrays.asList("kw1", "kw2"), ','); - Optional change = keywordEntry.removeKeywords(new KeywordList(), ','); - assertEquals(Optional.empty(), change); - } - - @Test - public void removeKeywordsWithNonExistingKeywordsDoesNothing() { - keywordEntry.putKeywords(Arrays.asList("kw1", "kw2"), ','); - Optional change = keywordEntry.removeKeywords(KeywordList.parse("kw3, kw4", ','), ','); - assertEquals(Optional.empty(), change); - assertEquals(Sets.newHashSet("kw1", "kw2"), keywordEntry.getKeywords(',').toStringList()); - } - - @Test - public void removeKeywordsWithExistingKeywordsRemovesThem() { - keywordEntry.putKeywords(Arrays.asList("kw1", "kw2", "kw3"), ','); - Optional change = keywordEntry.removeKeywords(KeywordList.parse("kw1, kw2", ','), ','); - assertTrue(change.isPresent()); - assertEquals(KeywordList.parse("kw3", ','), keywordEntry.getKeywords(',')); - } - - @Test - public void keywordListCorrectlyConstructedForThreeKeywords() { - BibEntry entry = new BibEntry(); - entry.addKeyword("kw", ','); - entry.addKeyword("kw2", ','); - entry.addKeyword("kw3", ','); - KeywordList actual = entry.getKeywords(','); - assertEquals(new KeywordList(new Keyword("kw"), new Keyword("kw2"), new Keyword("kw3")), actual); - } - - @Test - public void testGetEmptyResolvedKeywords() { - BibDatabase database = new BibDatabase(); - BibEntry entry = new BibEntry(); - entry.setField(StandardField.CROSSREF, "entry2"); - database.insertEntry(entry); - - BibEntry entry2 = new BibEntry(); - entry2.setCiteKey("entry2"); - database.insertEntry(entry2); - - KeywordList actual = entry.getResolvedKeywords(',', database); - - assertEquals(new KeywordList(), actual); - } - - @Test - public void testGetSingleResolvedKeywords() { - BibDatabase database = new BibDatabase(); - BibEntry entry = new BibEntry(); - entry.setField(StandardField.CROSSREF, "entry2"); - - BibEntry entry2 = new BibEntry(); - entry2.setCiteKey("entry2"); - entry2.addKeyword("kw", ','); - - database.insertEntry(entry2); - database.insertEntry(entry); - - KeywordList actual = entry.getResolvedKeywords(',', database); - - assertEquals(new KeywordList(new Keyword("kw")), actual); - } - - @Test - public void testGetResolvedKeywords() { - BibDatabase database = new BibDatabase(); - BibEntry entry = new BibEntry(); - entry.setField(StandardField.CROSSREF, "entry2"); - - BibEntry entry2 = new BibEntry(); - entry2.setCiteKey("entry2"); - entry2.addKeyword("kw", ','); - entry2.addKeyword("kw2", ','); - entry2.addKeyword("kw3", ','); - - database.insertEntry(entry2); - database.insertEntry(entry); - - KeywordList actual = entry.getResolvedKeywords(',', database); - - assertEquals(new KeywordList(new Keyword("kw"), new Keyword("kw2"), new Keyword("kw3")), actual); - } -}