From ed40cc2602ca1f96d2d210a7caffe8980cbab523 Mon Sep 17 00:00:00 2001 From: Akshat Jain Date: Fri, 14 Oct 2022 15:37:41 +1100 Subject: [PATCH 01/12] Added Naive Ampersand Formatter, see last point in #8948 to-do --- .../org/jabref/logic/exporter/BibWriter.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/logic/exporter/BibWriter.java b/src/main/java/org/jabref/logic/exporter/BibWriter.java index fd03941cf74..107fb16f193 100644 --- a/src/main/java/org/jabref/logic/exporter/BibWriter.java +++ b/src/main/java/org/jabref/logic/exporter/BibWriter.java @@ -1,10 +1,10 @@ package org.jabref.logic.exporter; +import org.jabref.model.strings.StringUtil; + import java.io.IOException; import java.io.Writer; -import org.jabref.model.strings.StringUtil; - /** * Class to write to a .bib file. Used by {@link BibtexDatabaseWriter} */ @@ -29,6 +29,19 @@ public BibWriter(Writer writer, String newLineSeparator) { * Writes the given string. The newlines of the given string are converted to the newline set for this clas */ public void write(String string) throws IOException { + StringBuilder temp = new StringBuilder(); + + for (int i = 0; i < string.length(); i++) { + if (string.charAt(i) == '&') { + temp.append("\\&"); + } else { + temp.append(string.charAt(i)); + } + } + + string = temp.toString(); + + if (precedingNewLineRequired) { writer.write(newLineSeparator); precedingNewLineRequired = false; From 3dc87aeb1e0b16b9369265161c032b70b9804209 Mon Sep 17 00:00:00 2001 From: u7312578 Date: Sat, 15 Oct 2022 14:45:39 +1100 Subject: [PATCH 02/12] Rudimentary attempt at allow \& in the journal abbreviation. However, this may not be the correct understanding of how to fix the issue. --- .../logic/journals/JournalAbbreviationRepository.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java index 523e1323be1..1589329abd4 100644 --- a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java +++ b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java @@ -7,6 +7,7 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.regex.Matcher; import java.util.stream.Collectors; import org.h2.mvstore.MVMap; @@ -48,7 +49,8 @@ private static boolean isMatchedAbbreviated(String name, Abbreviation abbreviati * Letters) or its abbreviated form (e.g. Phys. Rev. Lett.). */ public boolean isKnownName(String journalName) { - String journal = journalName.trim(); + // Trims the String and also replaces any instances of "\&" with "&" for abbreviation search purposes + String journal = journalName.trim().replaceAll(Matcher.quoteReplacement("\\&"), "&"); boolean isKnown = customAbbreviations.stream().anyMatch(abbreviation -> isMatched(journal, abbreviation)); if (isKnown) { @@ -63,7 +65,8 @@ public boolean isKnownName(String journalName) { * i.e. journals whose abbreviation is the same as the full name are not considered */ public boolean isAbbreviatedName(String journalName) { - String journal = journalName.trim(); + // Trims the String and also replaces any instances of "\&" with "&" for abbreviation search purposes + String journal = journalName.trim().replaceAll(Matcher.quoteReplacement("\\&"), "&"); return customAbbreviations.stream().anyMatch(abbreviation -> isMatchedAbbreviated(journal, abbreviation)) || abbreviationToFull.containsKey(journal); @@ -75,7 +78,8 @@ public boolean isAbbreviatedName(String journalName) { * @param input The journal name (either abbreviated or full name). */ public Optional get(String input) { - String journal = input.trim(); + // Trims the String and also replaces any instances of "\&" with "&" for abbreviation search purposes + String journal = input.trim().replaceAll(Matcher.quoteReplacement("\\&"), "&"); Optional customAbbreviation = customAbbreviations.stream() .filter(abbreviation -> isMatched(journal, abbreviation)) From e56af9e39257b6765cc63f85f38aa96385ddfa7f Mon Sep 17 00:00:00 2001 From: u7312578 Date: Thu, 20 Oct 2022 23:24:12 +1100 Subject: [PATCH 03/12] Remove unnecessary code in BibWriter.java and unnecessary replacement of \& when checking if journal name is abbreviated. --- .../org/jabref/logic/exporter/BibWriter.java | 16 ++-------------- .../journals/JournalAbbreviationRepository.java | 3 +-- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/jabref/logic/exporter/BibWriter.java b/src/main/java/org/jabref/logic/exporter/BibWriter.java index 107fb16f193..c2b08a833ef 100644 --- a/src/main/java/org/jabref/logic/exporter/BibWriter.java +++ b/src/main/java/org/jabref/logic/exporter/BibWriter.java @@ -1,10 +1,10 @@ package org.jabref.logic.exporter; -import org.jabref.model.strings.StringUtil; - import java.io.IOException; import java.io.Writer; +import org.jabref.model.strings.StringUtil; + /** * Class to write to a .bib file. Used by {@link BibtexDatabaseWriter} */ @@ -29,18 +29,6 @@ public BibWriter(Writer writer, String newLineSeparator) { * Writes the given string. The newlines of the given string are converted to the newline set for this clas */ public void write(String string) throws IOException { - StringBuilder temp = new StringBuilder(); - - for (int i = 0; i < string.length(); i++) { - if (string.charAt(i) == '&') { - temp.append("\\&"); - } else { - temp.append(string.charAt(i)); - } - } - - string = temp.toString(); - if (precedingNewLineRequired) { writer.write(newLineSeparator); diff --git a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java index 1589329abd4..4ceac67bee4 100644 --- a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java +++ b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java @@ -65,8 +65,7 @@ public boolean isKnownName(String journalName) { * i.e. journals whose abbreviation is the same as the full name are not considered */ public boolean isAbbreviatedName(String journalName) { - // Trims the String and also replaces any instances of "\&" with "&" for abbreviation search purposes - String journal = journalName.trim().replaceAll(Matcher.quoteReplacement("\\&"), "&"); + String journal = journalName.trim(); return customAbbreviations.stream().anyMatch(abbreviation -> isMatchedAbbreviated(journal, abbreviation)) || abbreviationToFull.containsKey(journal); From 26b6527b7b6cc7753f8bfb255785587f3bcba23c Mon Sep 17 00:00:00 2001 From: u7312578 Date: Sun, 23 Oct 2022 10:28:22 +1100 Subject: [PATCH 04/12] Remove linebreak for checkstyle --- src/main/java/org/jabref/logic/exporter/BibWriter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/jabref/logic/exporter/BibWriter.java b/src/main/java/org/jabref/logic/exporter/BibWriter.java index c2b08a833ef..fd03941cf74 100644 --- a/src/main/java/org/jabref/logic/exporter/BibWriter.java +++ b/src/main/java/org/jabref/logic/exporter/BibWriter.java @@ -29,7 +29,6 @@ public BibWriter(Writer writer, String newLineSeparator) { * Writes the given string. The newlines of the given string are converted to the newline set for this clas */ public void write(String string) throws IOException { - if (precedingNewLineRequired) { writer.write(newLineSeparator); precedingNewLineRequired = false; From 97fdb55bf9590554afdb27a2a4af6700af7db737 Mon Sep 17 00:00:00 2001 From: u7312578 Date: Sun, 23 Oct 2022 10:51:07 +1100 Subject: [PATCH 05/12] Updated CHANGELOG.md to reflect the changes made --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ed74a68e2c..57b06ce5a93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where hitting enter on the search field within the preferences dialog closed the dialog. [koppor#630](https://github.com/koppor/jabref/issues/630) - We fixed a typo within a connection error message. [koppor#625](https://github.com/koppor/jabref/issues/625) - We fixed an issue where the 'close dialog' key binding was not closing the Preferences dialog. [#8888](https://github.com/jabref/jabref/issues/8888) +- We fixed an issue where journal abbreviations would not abbreviate journal titles with escaped ampersands (\\&) which are written in accordance with Latex format. [#8948](https://github.com/JabRef/jabref/issues/8948) ### Removed From d34b5cdfb58e4cf012a3dc8595618745eab22fba Mon Sep 17 00:00:00 2001 From: u7312578 Date: Sun, 23 Oct 2022 11:46:27 +1100 Subject: [PATCH 06/12] Create tests for escaped ampersand in abbreviation --- .../journals/JournalAbbreviationRepositoryTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/org/jabref/logic/journals/JournalAbbreviationRepositoryTest.java b/src/test/java/org/jabref/logic/journals/JournalAbbreviationRepositoryTest.java index 68071fe0089..1a1a426d7bb 100644 --- a/src/test/java/org/jabref/logic/journals/JournalAbbreviationRepositoryTest.java +++ b/src/test/java/org/jabref/logic/journals/JournalAbbreviationRepositoryTest.java @@ -134,4 +134,16 @@ void getFromFullName() { void getFromAbbreviatedName() { assertEquals(new Abbreviation("American Journal of Public Health", "Am. J. Public Health"), repository.get("Am. J. Public Health").get()); } + + @Test + void testAbbreviationsWithEscapedAmpersand() { + assertEquals(new Abbreviation("ACS Applied Materials & Interfaces", "ACS Appl. Mater. Interfaces"), repository.get("ACS Applied Materials & Interfaces").get()); + assertEquals(new Abbreviation("ACS Applied Materials & Interfaces", "ACS Appl. Mater. Interfaces"), repository.get("ACS Applied Materials \\& Interfaces").get()); + assertEquals(new Abbreviation("Antioxidants & Redox Signaling", "Antioxid. Redox Signaling"), repository.get("Antioxidants & Redox Signaling").get()); + assertEquals(new Abbreviation("Antioxidants & Redox Signaling", "Antioxid. Redox Signaling"), repository.get("Antioxidants \\& Redox Signaling").get()); + + repository.addCustomAbbreviation(new Abbreviation("Long & Name", "L. N.", "LN")); + assertEquals(new Abbreviation("Long & Name", "L. N.", "LN"), repository.get("Long & Name").get()); + assertEquals(new Abbreviation("Long & Name", "L. N.", "LN"), repository.get("Long \\& Name").get()); + } } From 5426806ff0dbe2d63882db321f7cced7e69eb6eb Mon Sep 17 00:00:00 2001 From: u7312578 Date: Tue, 25 Oct 2022 16:10:38 +1100 Subject: [PATCH 07/12] Remove unnecessary comments --- .../jabref/logic/journals/JournalAbbreviationRepository.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java index 4ceac67bee4..825bd706e27 100644 --- a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java +++ b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java @@ -49,7 +49,6 @@ private static boolean isMatchedAbbreviated(String name, Abbreviation abbreviati * Letters) or its abbreviated form (e.g. Phys. Rev. Lett.). */ public boolean isKnownName(String journalName) { - // Trims the String and also replaces any instances of "\&" with "&" for abbreviation search purposes String journal = journalName.trim().replaceAll(Matcher.quoteReplacement("\\&"), "&"); boolean isKnown = customAbbreviations.stream().anyMatch(abbreviation -> isMatched(journal, abbreviation)); @@ -77,7 +76,6 @@ public boolean isAbbreviatedName(String journalName) { * @param input The journal name (either abbreviated or full name). */ public Optional get(String input) { - // Trims the String and also replaces any instances of "\&" with "&" for abbreviation search purposes String journal = input.trim().replaceAll(Matcher.quoteReplacement("\\&"), "&"); Optional customAbbreviation = customAbbreviations.stream() From 0ed991b5fec26a88d4a6d6cd327b01a41868871e Mon Sep 17 00:00:00 2001 From: u7312578 Date: Wed, 26 Oct 2022 18:39:39 +1100 Subject: [PATCH 08/12] Convert to using getResolvedFieldOrAliasLatexFree instead of replace() --- .../journals/JournalAbbreviationRepository.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java index 825bd706e27..8f9ca13d463 100644 --- a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java +++ b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java @@ -7,9 +7,11 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.regex.Matcher; import java.util.stream.Collectors; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.field.StandardField; + import org.h2.mvstore.MVMap; import org.h2.mvstore.MVStore; @@ -49,7 +51,7 @@ private static boolean isMatchedAbbreviated(String name, Abbreviation abbreviati * Letters) or its abbreviated form (e.g. Phys. Rev. Lett.). */ public boolean isKnownName(String journalName) { - String journal = journalName.trim().replaceAll(Matcher.quoteReplacement("\\&"), "&"); + String journal = getLatexFreeJournal(journalName.trim()); boolean isKnown = customAbbreviations.stream().anyMatch(abbreviation -> isMatched(journal, abbreviation)); if (isKnown) { @@ -59,6 +61,15 @@ public boolean isKnownName(String journalName) { return fullToAbbreviation.containsKey(journal) || abbreviationToFull.containsKey(journal); } + private String getLatexFreeJournal(String journal) { + BibEntry entry = new BibEntry(); + entry.setField(StandardField.JOURNAL, journal); + if (entry.getResolvedFieldOrAliasLatexFree(StandardField.JOURNAL, null).isPresent()) { + journal = entry.getResolvedFieldOrAliasLatexFree(StandardField.JOURNAL, null).get(); + } + return journal; + } + /** * Returns true if the given journal name is in its abbreviated form (e.g. Phys. Rev. Lett.). The test is strict, * i.e. journals whose abbreviation is the same as the full name are not considered @@ -76,7 +87,7 @@ public boolean isAbbreviatedName(String journalName) { * @param input The journal name (either abbreviated or full name). */ public Optional get(String input) { - String journal = input.trim().replaceAll(Matcher.quoteReplacement("\\&"), "&"); + String journal = getLatexFreeJournal(input.trim()); Optional customAbbreviation = customAbbreviations.stream() .filter(abbreviation -> isMatched(journal, abbreviation)) From d8a69c8a0e2b53145566364bcd5941b5391fc4b6 Mon Sep 17 00:00:00 2001 From: u7312578 Date: Wed, 26 Oct 2022 18:42:49 +1100 Subject: [PATCH 09/12] Added a javadoc to explain the function created --- .../logic/journals/JournalAbbreviationRepository.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java index 8f9ca13d463..09b98f6dc92 100644 --- a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java +++ b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java @@ -61,6 +61,13 @@ public boolean isKnownName(String journalName) { return fullToAbbreviation.containsKey(journal) || abbreviationToFull.containsKey(journal); } + /** + * Returns the LaTeX free version of a journal (e.g., IEEE Design \& Test would be returned as IEEE Design & Test) + * i.e., the journal name should not contain any unnecessary LaTeX syntax such as escaped ampersands + * + * @param journal The journal name + * @return The LaTeX free version of the journal name + */ private String getLatexFreeJournal(String journal) { BibEntry entry = new BibEntry(); entry.setField(StandardField.JOURNAL, journal); From e18c7923b89dadbb4de986cead6fe8227b1bbbd0 Mon Sep 17 00:00:00 2001 From: u7312578 Date: Fri, 28 Oct 2022 15:04:05 +1100 Subject: [PATCH 10/12] Added 3 tests to BibEntryWriterTest which test abbreviating journal entries --- .../logic/bibtex/BibEntryWriterTest.java | 78 ++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java b/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java index ad5f8f70ecb..216285df1b0 100644 --- a/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java +++ b/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java @@ -9,11 +9,19 @@ import java.util.Set; import java.util.stream.Stream; +import javax.swing.undo.CompoundEdit; + +import org.jabref.gui.journals.AbbreviationType; +import org.jabref.gui.journals.UndoableAbbreviator; +import org.jabref.gui.journals.UndoableUnabbreviator; import org.jabref.logic.exporter.BibWriter; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.importer.fileformat.BibtexParser; +import org.jabref.logic.journals.JournalAbbreviationLoader; +import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.util.OS; +import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibEntryTypesManager; @@ -852,11 +860,77 @@ static Stream testGetFormattedFieldNameData() { ); } + @Test + void testJournalAbbreviationWithEscapedAmpersand() throws IOException { + BibDatabase bibDatabase = new BibDatabase(); + JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository(); + UndoableAbbreviator undoableAbbreviator = new UndoableAbbreviator(journalAbbreviationRepository, AbbreviationType.DEFAULT); + + BibEntry entryWithEscapedAmpersandInJournal = new BibEntry(StandardEntryType.Article); + entryWithEscapedAmpersandInJournal.setField(StandardField.JOURNAL, "ACS Applied Materials \\& Interfaces"); + + // @formatter:off + String expectedAbbreviatedJournalEntry = """ + @Article{, + journal = {ACS Appl. Mater. Interfaces}, + } + """.replaceAll("\n", OS.NEWLINE); + // @formatter:on + + undoableAbbreviator.abbreviate(bibDatabase, entryWithEscapedAmpersandInJournal, StandardField.JOURNAL, new CompoundEdit()); + bibEntryWriter.write(entryWithEscapedAmpersandInJournal, bibWriter, BibDatabaseMode.BIBLATEX); + assertEquals(expectedAbbreviatedJournalEntry, stringWriter.toString()); + } + + @Test + void testJournalUnabbreviate() throws IOException { + BibDatabase bibDatabase = new BibDatabase(); + JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository(); + UndoableUnabbreviator undoableUnabbreviator = new UndoableUnabbreviator(journalAbbreviationRepository); + + BibEntry abbreviatedJournalEntry = new BibEntry(StandardEntryType.Article); + abbreviatedJournalEntry.setField(StandardField.JOURNAL, "ACS Appl. Mater. Interfaces"); + + // @formatter:off + String expectedUnabbreviatedJournalEntry = """ + @Article{, + journal = {ACS Applied Materials & Interfaces}, + } + """.replaceAll("\n", OS.NEWLINE); + // @formatter:on + + undoableUnabbreviator.unabbreviate(bibDatabase, abbreviatedJournalEntry, StandardField.JOURNAL, new CompoundEdit()); + bibEntryWriter.write(abbreviatedJournalEntry, bibWriter, BibDatabaseMode.BIBLATEX); + assertEquals(expectedUnabbreviatedJournalEntry, stringWriter.toString()); + } + + @Test + void testJournalAbbreviateWithoutEscapedAmpersand() throws IOException { + BibDatabase bibDatabase = new BibDatabase(); + JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository(); + UndoableAbbreviator undoableAbbreviator = new UndoableAbbreviator(journalAbbreviationRepository, AbbreviationType.DEFAULT); + + BibEntry entryWithoutEscapedAmpersandInJournal = new BibEntry(StandardEntryType.Article); + entryWithoutEscapedAmpersandInJournal.setField(StandardField.JOURNAL, "ACS Applied Materials & Interfaces"); + + // @formatter:off + String expectedAbbreviatedJournalEntry = """ + @Article{, + journal = {ACS Appl. Mater. Interfaces}, + } + """.replaceAll("\n", OS.NEWLINE); + // @formatter:on + + undoableAbbreviator.abbreviate(bibDatabase, entryWithoutEscapedAmpersandInJournal, StandardField.JOURNAL, new CompoundEdit()); + bibEntryWriter.write(entryWithoutEscapedAmpersandInJournal, bibWriter, BibDatabaseMode.BIBLATEX); + assertEquals(expectedAbbreviatedJournalEntry, stringWriter.toString()); + } + @ParameterizedTest @MethodSource("testGetFormattedFieldNameData") void testGetFormattedFieldName(String expected, String fieldName, int indent) { Field field = FieldFactory.parseField(fieldName); - assertEquals(expected, bibEntryWriter.getFormattedFieldName(field, indent)); + assertEquals(expected, BibEntryWriter.getFormattedFieldName(field, indent)); } static Stream testGetLengthOfLongestFieldNameData() { @@ -871,6 +945,6 @@ static Stream testGetLengthOfLongestFieldNameData() { @ParameterizedTest @MethodSource("testGetLengthOfLongestFieldNameData") void testGetLengthOfLongestFieldName(int expected, BibEntry entry) { - assertEquals(expected, bibEntryWriter.getLengthOfLongestFieldName(entry)); + assertEquals(expected, BibEntryWriter.getLengthOfLongestFieldName(entry)); } } From 7815ba0bff5dbfe1ecfdb78bb9c1b753ec02cb58 Mon Sep 17 00:00:00 2001 From: u7312578 Date: Sat, 29 Oct 2022 01:38:00 +1100 Subject: [PATCH 11/12] Move journal abbreviation tests from BibEntryWriterTest to JournalAbbreviationRepositoryTest --- .../logic/bibtex/BibEntryWriterTest.java | 74 ------------- .../JournalAbbreviationRepositoryTest.java | 103 ++++++++++++++++++ 2 files changed, 103 insertions(+), 74 deletions(-) diff --git a/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java b/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java index 216285df1b0..9c1dc3f3aa9 100644 --- a/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java +++ b/src/test/java/org/jabref/logic/bibtex/BibEntryWriterTest.java @@ -9,19 +9,11 @@ import java.util.Set; import java.util.stream.Stream; -import javax.swing.undo.CompoundEdit; - -import org.jabref.gui.journals.AbbreviationType; -import org.jabref.gui.journals.UndoableAbbreviator; -import org.jabref.gui.journals.UndoableUnabbreviator; import org.jabref.logic.exporter.BibWriter; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.importer.fileformat.BibtexParser; -import org.jabref.logic.journals.JournalAbbreviationLoader; -import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.util.OS; -import org.jabref.model.database.BibDatabase; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.BibEntryTypesManager; @@ -860,72 +852,6 @@ static Stream testGetFormattedFieldNameData() { ); } - @Test - void testJournalAbbreviationWithEscapedAmpersand() throws IOException { - BibDatabase bibDatabase = new BibDatabase(); - JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository(); - UndoableAbbreviator undoableAbbreviator = new UndoableAbbreviator(journalAbbreviationRepository, AbbreviationType.DEFAULT); - - BibEntry entryWithEscapedAmpersandInJournal = new BibEntry(StandardEntryType.Article); - entryWithEscapedAmpersandInJournal.setField(StandardField.JOURNAL, "ACS Applied Materials \\& Interfaces"); - - // @formatter:off - String expectedAbbreviatedJournalEntry = """ - @Article{, - journal = {ACS Appl. Mater. Interfaces}, - } - """.replaceAll("\n", OS.NEWLINE); - // @formatter:on - - undoableAbbreviator.abbreviate(bibDatabase, entryWithEscapedAmpersandInJournal, StandardField.JOURNAL, new CompoundEdit()); - bibEntryWriter.write(entryWithEscapedAmpersandInJournal, bibWriter, BibDatabaseMode.BIBLATEX); - assertEquals(expectedAbbreviatedJournalEntry, stringWriter.toString()); - } - - @Test - void testJournalUnabbreviate() throws IOException { - BibDatabase bibDatabase = new BibDatabase(); - JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository(); - UndoableUnabbreviator undoableUnabbreviator = new UndoableUnabbreviator(journalAbbreviationRepository); - - BibEntry abbreviatedJournalEntry = new BibEntry(StandardEntryType.Article); - abbreviatedJournalEntry.setField(StandardField.JOURNAL, "ACS Appl. Mater. Interfaces"); - - // @formatter:off - String expectedUnabbreviatedJournalEntry = """ - @Article{, - journal = {ACS Applied Materials & Interfaces}, - } - """.replaceAll("\n", OS.NEWLINE); - // @formatter:on - - undoableUnabbreviator.unabbreviate(bibDatabase, abbreviatedJournalEntry, StandardField.JOURNAL, new CompoundEdit()); - bibEntryWriter.write(abbreviatedJournalEntry, bibWriter, BibDatabaseMode.BIBLATEX); - assertEquals(expectedUnabbreviatedJournalEntry, stringWriter.toString()); - } - - @Test - void testJournalAbbreviateWithoutEscapedAmpersand() throws IOException { - BibDatabase bibDatabase = new BibDatabase(); - JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository(); - UndoableAbbreviator undoableAbbreviator = new UndoableAbbreviator(journalAbbreviationRepository, AbbreviationType.DEFAULT); - - BibEntry entryWithoutEscapedAmpersandInJournal = new BibEntry(StandardEntryType.Article); - entryWithoutEscapedAmpersandInJournal.setField(StandardField.JOURNAL, "ACS Applied Materials & Interfaces"); - - // @formatter:off - String expectedAbbreviatedJournalEntry = """ - @Article{, - journal = {ACS Appl. Mater. Interfaces}, - } - """.replaceAll("\n", OS.NEWLINE); - // @formatter:on - - undoableAbbreviator.abbreviate(bibDatabase, entryWithoutEscapedAmpersandInJournal, StandardField.JOURNAL, new CompoundEdit()); - bibEntryWriter.write(entryWithoutEscapedAmpersandInJournal, bibWriter, BibDatabaseMode.BIBLATEX); - assertEquals(expectedAbbreviatedJournalEntry, stringWriter.toString()); - } - @ParameterizedTest @MethodSource("testGetFormattedFieldNameData") void testGetFormattedFieldName(String expected, String fieldName, int indent) { diff --git a/src/test/java/org/jabref/logic/journals/JournalAbbreviationRepositoryTest.java b/src/test/java/org/jabref/logic/journals/JournalAbbreviationRepositoryTest.java index 1a1a426d7bb..477a153ed87 100644 --- a/src/test/java/org/jabref/logic/journals/JournalAbbreviationRepositoryTest.java +++ b/src/test/java/org/jabref/logic/journals/JournalAbbreviationRepositoryTest.java @@ -1,5 +1,27 @@ package org.jabref.logic.journals; +import java.io.IOException; +import java.io.StringWriter; +import java.util.List; + +import javax.swing.undo.CompoundEdit; + +import org.jabref.gui.journals.AbbreviationType; +import org.jabref.gui.journals.UndoableAbbreviator; +import org.jabref.gui.journals.UndoableUnabbreviator; +import org.jabref.logic.bibtex.BibEntryWriter; +import org.jabref.logic.bibtex.FieldContentFormatterPreferences; +import org.jabref.logic.bibtex.FieldWriter; +import org.jabref.logic.bibtex.FieldWriterPreferences; +import org.jabref.logic.exporter.BibWriter; +import org.jabref.logic.util.OS; +import org.jabref.model.database.BibDatabase; +import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.entry.BibEntryTypesManager; +import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.types.StandardEntryType; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -146,4 +168,85 @@ void testAbbreviationsWithEscapedAmpersand() { assertEquals(new Abbreviation("Long & Name", "L. N.", "LN"), repository.get("Long & Name").get()); assertEquals(new Abbreviation("Long & Name", "L. N.", "LN"), repository.get("Long \\& Name").get()); } + + @Test + void testJournalAbbreviationWithEscapedAmpersand() throws IOException { + FieldWriterPreferences fieldWriterPreferences = new FieldWriterPreferences(true, List.of(StandardField.MONTH), new FieldContentFormatterPreferences()); + BibEntryWriter bibEntryWriter = new BibEntryWriter(new FieldWriter(fieldWriterPreferences), new BibEntryTypesManager()); + StringWriter stringWriter = new StringWriter(); + BibWriter bibWriter = new BibWriter(stringWriter, OS.NEWLINE); + + BibDatabase bibDatabase = new BibDatabase(); + JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository(); + UndoableAbbreviator undoableAbbreviator = new UndoableAbbreviator(journalAbbreviationRepository, AbbreviationType.DEFAULT); + + BibEntry entryWithEscapedAmpersandInJournal = new BibEntry(StandardEntryType.Article); + entryWithEscapedAmpersandInJournal.setField(StandardField.JOURNAL, "ACS Applied Materials \\& Interfaces"); + + // @formatter:off + String expectedAbbreviatedJournalEntry = """ + @Article{, + journal = {ACS Appl. Mater. Interfaces}, + } + """.replaceAll("\n", OS.NEWLINE); + // @formatter:on + + undoableAbbreviator.abbreviate(bibDatabase, entryWithEscapedAmpersandInJournal, StandardField.JOURNAL, new CompoundEdit()); + bibEntryWriter.write(entryWithEscapedAmpersandInJournal, bibWriter, BibDatabaseMode.BIBLATEX); + assertEquals(expectedAbbreviatedJournalEntry, stringWriter.toString()); + } + + @Test + void testJournalUnabbreviate() throws IOException { + FieldWriterPreferences fieldWriterPreferences = new FieldWriterPreferences(true, List.of(StandardField.MONTH), new FieldContentFormatterPreferences()); + BibEntryWriter bibEntryWriter = new BibEntryWriter(new FieldWriter(fieldWriterPreferences), new BibEntryTypesManager()); + StringWriter stringWriter = new StringWriter(); + BibWriter bibWriter = new BibWriter(stringWriter, OS.NEWLINE); + + BibDatabase bibDatabase = new BibDatabase(); + JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository(); + UndoableUnabbreviator undoableUnabbreviator = new UndoableUnabbreviator(journalAbbreviationRepository); + + BibEntry abbreviatedJournalEntry = new BibEntry(StandardEntryType.Article); + abbreviatedJournalEntry.setField(StandardField.JOURNAL, "ACS Appl. Mater. Interfaces"); + + // @formatter:off + String expectedUnabbreviatedJournalEntry = """ + @Article{, + journal = {ACS Applied Materials & Interfaces}, + } + """.replaceAll("\n", OS.NEWLINE); + // @formatter:on + + undoableUnabbreviator.unabbreviate(bibDatabase, abbreviatedJournalEntry, StandardField.JOURNAL, new CompoundEdit()); + bibEntryWriter.write(abbreviatedJournalEntry, bibWriter, BibDatabaseMode.BIBLATEX); + assertEquals(expectedUnabbreviatedJournalEntry, stringWriter.toString()); + } + + @Test + void testJournalAbbreviateWithoutEscapedAmpersand() throws IOException { + FieldWriterPreferences fieldWriterPreferences = new FieldWriterPreferences(true, List.of(StandardField.MONTH), new FieldContentFormatterPreferences()); + BibEntryWriter bibEntryWriter = new BibEntryWriter(new FieldWriter(fieldWriterPreferences), new BibEntryTypesManager()); + StringWriter stringWriter = new StringWriter(); + BibWriter bibWriter = new BibWriter(stringWriter, OS.NEWLINE); + + BibDatabase bibDatabase = new BibDatabase(); + JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository(); + UndoableAbbreviator undoableAbbreviator = new UndoableAbbreviator(journalAbbreviationRepository, AbbreviationType.DEFAULT); + + BibEntry entryWithoutEscapedAmpersandInJournal = new BibEntry(StandardEntryType.Article); + entryWithoutEscapedAmpersandInJournal.setField(StandardField.JOURNAL, "ACS Applied Materials & Interfaces"); + + // @formatter:off + String expectedAbbreviatedJournalEntry = """ + @Article{, + journal = {ACS Appl. Mater. Interfaces}, + } + """.replaceAll("\n", OS.NEWLINE); + // @formatter:on + + undoableAbbreviator.abbreviate(bibDatabase, entryWithoutEscapedAmpersandInJournal, StandardField.JOURNAL, new CompoundEdit()); + bibEntryWriter.write(entryWithoutEscapedAmpersandInJournal, bibWriter, BibDatabaseMode.BIBLATEX); + assertEquals(expectedAbbreviatedJournalEntry, stringWriter.toString()); + } } From fc0907bc483d495909b99ff508c9288b1c98a04f Mon Sep 17 00:00:00 2001 From: u7312578 Date: Sat, 29 Oct 2022 16:05:32 +1100 Subject: [PATCH 12/12] CHANGELOG.md changed to remove unnecessary information. restrictUsagesInLogic test changed to allow classes annotated with @AllowedToUseString. Test cases and escaped ampersand replacement in abbreviation changed. --- CHANGELOG.md | 2 +- .../JournalAbbreviationRepository.java | 24 +----- .../architecture/MainArchitectureTests.java | 1 + .../JournalAbbreviationRepositoryTest.java | 74 ++++--------------- 4 files changed, 19 insertions(+), 82 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f285366be24..85ca65c12f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,7 +74,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where hitting enter on the search field within the preferences dialog closed the dialog. [koppor#630](https://github.com/koppor/jabref/issues/630) - We fixed a typo within a connection error message. [koppor#625](https://github.com/koppor/jabref/issues/625) - We fixed an issue where the 'close dialog' key binding was not closing the Preferences dialog. [#8888](https://github.com/jabref/jabref/issues/8888) -- We fixed an issue where journal abbreviations would not abbreviate journal titles with escaped ampersands (\\&) which are written in accordance with Latex format. [#8948](https://github.com/JabRef/jabref/issues/8948) +- We fixed an issue where journal abbreviations would not abbreviate journal titles with escaped ampersands (\\&). [#8948](https://github.com/JabRef/jabref/issues/8948) ### Removed diff --git a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java index 09b98f6dc92..825bd706e27 100644 --- a/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java +++ b/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java @@ -7,11 +7,9 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.regex.Matcher; import java.util.stream.Collectors; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.field.StandardField; - import org.h2.mvstore.MVMap; import org.h2.mvstore.MVStore; @@ -51,7 +49,7 @@ private static boolean isMatchedAbbreviated(String name, Abbreviation abbreviati * Letters) or its abbreviated form (e.g. Phys. Rev. Lett.). */ public boolean isKnownName(String journalName) { - String journal = getLatexFreeJournal(journalName.trim()); + String journal = journalName.trim().replaceAll(Matcher.quoteReplacement("\\&"), "&"); boolean isKnown = customAbbreviations.stream().anyMatch(abbreviation -> isMatched(journal, abbreviation)); if (isKnown) { @@ -61,22 +59,6 @@ public boolean isKnownName(String journalName) { return fullToAbbreviation.containsKey(journal) || abbreviationToFull.containsKey(journal); } - /** - * Returns the LaTeX free version of a journal (e.g., IEEE Design \& Test would be returned as IEEE Design & Test) - * i.e., the journal name should not contain any unnecessary LaTeX syntax such as escaped ampersands - * - * @param journal The journal name - * @return The LaTeX free version of the journal name - */ - private String getLatexFreeJournal(String journal) { - BibEntry entry = new BibEntry(); - entry.setField(StandardField.JOURNAL, journal); - if (entry.getResolvedFieldOrAliasLatexFree(StandardField.JOURNAL, null).isPresent()) { - journal = entry.getResolvedFieldOrAliasLatexFree(StandardField.JOURNAL, null).get(); - } - return journal; - } - /** * Returns true if the given journal name is in its abbreviated form (e.g. Phys. Rev. Lett.). The test is strict, * i.e. journals whose abbreviation is the same as the full name are not considered @@ -94,7 +76,7 @@ public boolean isAbbreviatedName(String journalName) { * @param input The journal name (either abbreviated or full name). */ public Optional get(String input) { - String journal = getLatexFreeJournal(input.trim()); + String journal = input.trim().replaceAll(Matcher.quoteReplacement("\\&"), "&"); Optional customAbbreviation = customAbbreviations.stream() .filter(abbreviation -> isMatched(journal, abbreviation)) diff --git a/src/test/java/org/jabref/architecture/MainArchitectureTests.java b/src/test/java/org/jabref/architecture/MainArchitectureTests.java index 25b60cea46c..86335032845 100644 --- a/src/test/java/org/jabref/architecture/MainArchitectureTests.java +++ b/src/test/java/org/jabref/architecture/MainArchitectureTests.java @@ -115,6 +115,7 @@ public static void restrictUsagesInModel(JavaClasses classes) { @ArchTest public static void restrictUsagesInLogic(JavaClasses classes) { noClasses().that().resideInAPackage(PACKAGE_ORG_JABREF_LOGIC) + .and().areNotAnnotatedWith(AllowedToUseSwing.class) .should().dependOnClassesThat().resideInAPackage(PACKAGE_JAVAX_SWING) .orShould().dependOnClassesThat().haveFullyQualifiedName(CLASS_ORG_JABREF_GLOBALS) .check(classes); diff --git a/src/test/java/org/jabref/logic/journals/JournalAbbreviationRepositoryTest.java b/src/test/java/org/jabref/logic/journals/JournalAbbreviationRepositoryTest.java index 477a153ed87..97c6766676f 100644 --- a/src/test/java/org/jabref/logic/journals/JournalAbbreviationRepositoryTest.java +++ b/src/test/java/org/jabref/logic/journals/JournalAbbreviationRepositoryTest.java @@ -1,24 +1,13 @@ package org.jabref.logic.journals; -import java.io.IOException; -import java.io.StringWriter; -import java.util.List; - import javax.swing.undo.CompoundEdit; +import org.jabref.architecture.AllowedToUseSwing; import org.jabref.gui.journals.AbbreviationType; import org.jabref.gui.journals.UndoableAbbreviator; import org.jabref.gui.journals.UndoableUnabbreviator; -import org.jabref.logic.bibtex.BibEntryWriter; -import org.jabref.logic.bibtex.FieldContentFormatterPreferences; -import org.jabref.logic.bibtex.FieldWriter; -import org.jabref.logic.bibtex.FieldWriterPreferences; -import org.jabref.logic.exporter.BibWriter; -import org.jabref.logic.util.OS; import org.jabref.model.database.BibDatabase; -import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BibEntryTypesManager; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; @@ -29,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +@AllowedToUseSwing("UndoableUnabbreviator and UndoableAbbreviator requires Swing Compound Edit in order test the abbreviation and unabreviation of journal titles") class JournalAbbreviationRepositoryTest { private JournalAbbreviationRepository repository; @@ -170,12 +160,7 @@ void testAbbreviationsWithEscapedAmpersand() { } @Test - void testJournalAbbreviationWithEscapedAmpersand() throws IOException { - FieldWriterPreferences fieldWriterPreferences = new FieldWriterPreferences(true, List.of(StandardField.MONTH), new FieldContentFormatterPreferences()); - BibEntryWriter bibEntryWriter = new BibEntryWriter(new FieldWriter(fieldWriterPreferences), new BibEntryTypesManager()); - StringWriter stringWriter = new StringWriter(); - BibWriter bibWriter = new BibWriter(stringWriter, OS.NEWLINE); - + void testJournalAbbreviationWithEscapedAmpersand() { BibDatabase bibDatabase = new BibDatabase(); JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository(); UndoableAbbreviator undoableAbbreviator = new UndoableAbbreviator(journalAbbreviationRepository, AbbreviationType.DEFAULT); @@ -183,26 +168,14 @@ void testJournalAbbreviationWithEscapedAmpersand() throws IOException { BibEntry entryWithEscapedAmpersandInJournal = new BibEntry(StandardEntryType.Article); entryWithEscapedAmpersandInJournal.setField(StandardField.JOURNAL, "ACS Applied Materials \\& Interfaces"); - // @formatter:off - String expectedAbbreviatedJournalEntry = """ - @Article{, - journal = {ACS Appl. Mater. Interfaces}, - } - """.replaceAll("\n", OS.NEWLINE); - // @formatter:on - undoableAbbreviator.abbreviate(bibDatabase, entryWithEscapedAmpersandInJournal, StandardField.JOURNAL, new CompoundEdit()); - bibEntryWriter.write(entryWithEscapedAmpersandInJournal, bibWriter, BibDatabaseMode.BIBLATEX); - assertEquals(expectedAbbreviatedJournalEntry, stringWriter.toString()); + BibEntry expectedAbbreviatedJournalEntry = new BibEntry(StandardEntryType.Article) + .withField(StandardField.JOURNAL, "ACS Appl. Mater. Interfaces"); + assertEquals(expectedAbbreviatedJournalEntry, entryWithEscapedAmpersandInJournal); } @Test - void testJournalUnabbreviate() throws IOException { - FieldWriterPreferences fieldWriterPreferences = new FieldWriterPreferences(true, List.of(StandardField.MONTH), new FieldContentFormatterPreferences()); - BibEntryWriter bibEntryWriter = new BibEntryWriter(new FieldWriter(fieldWriterPreferences), new BibEntryTypesManager()); - StringWriter stringWriter = new StringWriter(); - BibWriter bibWriter = new BibWriter(stringWriter, OS.NEWLINE); - + void testJournalUnabbreviate() { BibDatabase bibDatabase = new BibDatabase(); JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository(); UndoableUnabbreviator undoableUnabbreviator = new UndoableUnabbreviator(journalAbbreviationRepository); @@ -210,26 +183,14 @@ void testJournalUnabbreviate() throws IOException { BibEntry abbreviatedJournalEntry = new BibEntry(StandardEntryType.Article); abbreviatedJournalEntry.setField(StandardField.JOURNAL, "ACS Appl. Mater. Interfaces"); - // @formatter:off - String expectedUnabbreviatedJournalEntry = """ - @Article{, - journal = {ACS Applied Materials & Interfaces}, - } - """.replaceAll("\n", OS.NEWLINE); - // @formatter:on - undoableUnabbreviator.unabbreviate(bibDatabase, abbreviatedJournalEntry, StandardField.JOURNAL, new CompoundEdit()); - bibEntryWriter.write(abbreviatedJournalEntry, bibWriter, BibDatabaseMode.BIBLATEX); - assertEquals(expectedUnabbreviatedJournalEntry, stringWriter.toString()); + BibEntry expectedAbbreviatedJournalEntry = new BibEntry(StandardEntryType.Article) + .withField(StandardField.JOURNAL, "ACS Applied Materials & Interfaces"); + assertEquals(expectedAbbreviatedJournalEntry, abbreviatedJournalEntry); } @Test - void testJournalAbbreviateWithoutEscapedAmpersand() throws IOException { - FieldWriterPreferences fieldWriterPreferences = new FieldWriterPreferences(true, List.of(StandardField.MONTH), new FieldContentFormatterPreferences()); - BibEntryWriter bibEntryWriter = new BibEntryWriter(new FieldWriter(fieldWriterPreferences), new BibEntryTypesManager()); - StringWriter stringWriter = new StringWriter(); - BibWriter bibWriter = new BibWriter(stringWriter, OS.NEWLINE); - + void testJournalAbbreviateWithoutEscapedAmpersand() { BibDatabase bibDatabase = new BibDatabase(); JournalAbbreviationRepository journalAbbreviationRepository = JournalAbbreviationLoader.loadBuiltInRepository(); UndoableAbbreviator undoableAbbreviator = new UndoableAbbreviator(journalAbbreviationRepository, AbbreviationType.DEFAULT); @@ -237,16 +198,9 @@ void testJournalAbbreviateWithoutEscapedAmpersand() throws IOException { BibEntry entryWithoutEscapedAmpersandInJournal = new BibEntry(StandardEntryType.Article); entryWithoutEscapedAmpersandInJournal.setField(StandardField.JOURNAL, "ACS Applied Materials & Interfaces"); - // @formatter:off - String expectedAbbreviatedJournalEntry = """ - @Article{, - journal = {ACS Appl. Mater. Interfaces}, - } - """.replaceAll("\n", OS.NEWLINE); - // @formatter:on - undoableAbbreviator.abbreviate(bibDatabase, entryWithoutEscapedAmpersandInJournal, StandardField.JOURNAL, new CompoundEdit()); - bibEntryWriter.write(entryWithoutEscapedAmpersandInJournal, bibWriter, BibDatabaseMode.BIBLATEX); - assertEquals(expectedAbbreviatedJournalEntry, stringWriter.toString()); + BibEntry expectedAbbreviatedJournalEntry = new BibEntry(StandardEntryType.Article) + .withField(StandardField.JOURNAL, "ACS Appl. Mater. Interfaces"); + assertEquals(expectedAbbreviatedJournalEntry, entryWithoutEscapedAmpersandInJournal); } }