From 7a30c307707e02e68ba2ef524a6e34615a07114b Mon Sep 17 00:00:00 2001 From: siddhant Date: Wed, 27 Aug 2025 16:58:08 +0530 Subject: [PATCH 1/5] changed ISSNCleanup into NormalizeIssn, refactored respective tests --- CHANGELOG.md | 2 +- .../gui/cleanup/CleanupPresetPanel.java | 5 -- .../gui/cleanup/CleanupPresetPanel.fxml | 9 ++- .../jabref/logic/cleanup/CleanupWorker.java | 2 - .../logic/cleanup/FieldFormatterCleanups.java | 12 +--- .../org/jabref/logic/cleanup/ISSNCleanup.java | 29 ---------- .../formatter/bibtexfields/NormalizeIssn.java | 40 +++++++++++++ .../jabref/logic/cleanup/ISSNCleanupTest.java | 58 ------------------- .../bibtexfields/NormalizeIssnTest.java | 32 ++++++++++ 9 files changed, 80 insertions(+), 109 deletions(-) delete mode 100644 jablib/src/main/java/org/jabref/logic/cleanup/ISSNCleanup.java create mode 100644 jablib/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssn.java delete mode 100644 jablib/src/test/java/org/jabref/logic/cleanup/ISSNCleanupTest.java create mode 100644 jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c64e30e43c..165f102acd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We added support for finding CSL-Styles based on their short title (e.g. apa instead of "american psychological association"). [#13728](https://github.com/JabRef/jabref/pull/13728) ### Changed - +- We changed `ISSNCleanup` into `NormalizeIssn` a `ISSN` formatter. [#13748](https://github.com/JabRef/jabref/issues/13748) - We changed Citation Relations tab and gave tab panes more descriptive titles and tooltips. [#13619](https://github.com/JabRef/jabref/issues/13619) - We changed the name from Open AI Provider to Open AI (or API compatible). [#13585](https://github.com/JabRef/jabref/issues/13585) - We improved the citations relations caching by implementing an offline storage. [#11189](https://github.com/JabRef/jabref/issues/11189) diff --git a/jabgui/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java b/jabgui/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java index 20d818d9b04..b0bbc74dc6d 100644 --- a/jabgui/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java +++ b/jabgui/src/main/java/org/jabref/gui/cleanup/CleanupPresetPanel.java @@ -28,7 +28,6 @@ public class CleanupPresetPanel extends VBox { @FXML private CheckBox cleanUpDOI; @FXML private CheckBox cleanUpEprint; @FXML private CheckBox cleanUpURL; - @FXML private CheckBox cleanUpISSN; @FXML private CheckBox cleanUpMovePDF; @FXML private CheckBox cleanUpMakePathsRelative; @FXML private CheckBox cleanUpRenamePDF; @@ -117,7 +116,6 @@ private void updateDisplay(CleanupPreferences preset) { cleanUpTimestampToCreationDate.setSelected(preset.isActive(CleanupPreferences.CleanupStep.CONVERT_TIMESTAMP_TO_CREATIONDATE)); cleanUpTimestampToModificationDate.setSelected(preset.isActive(CleanupPreferences.CleanupStep.CONVERT_TIMESTAMP_TO_MODIFICATIONDATE)); cleanUpTimestampToModificationDate.setSelected(preset.isActive(CleanupPreferences.CleanupStep.DO_NOT_CONVERT_TIMESTAMP)); - cleanUpISSN.setSelected(preset.isActive(CleanupPreferences.CleanupStep.CLEAN_UP_ISSN)); formatterCleanupsPanel.cleanupsDisableProperty().setValue(!preset.getFieldFormatterCleanups().isEnabled()); formatterCleanupsPanel.cleanupsProperty().setValue(FXCollections.observableArrayList(preset.getFieldFormatterCleanups().getConfiguredActions())); } @@ -137,9 +135,6 @@ public CleanupPreferences getCleanupPreset() { if (cleanUpURL.isSelected()) { activeJobs.add(CleanupPreferences.CleanupStep.CLEAN_UP_URL); } - if (cleanUpISSN.isSelected()) { - activeJobs.add(CleanupPreferences.CleanupStep.CLEAN_UP_ISSN); - } if (cleanUpMakePathsRelative.isSelected()) { activeJobs.add(CleanupPreferences.CleanupStep.MAKE_PATHS_RELATIVE); } diff --git a/jabgui/src/main/resources/org/jabref/gui/cleanup/CleanupPresetPanel.fxml b/jabgui/src/main/resources/org/jabref/gui/cleanup/CleanupPresetPanel.fxml index 86c4af68002..f6421d75a4d 100644 --- a/jabgui/src/main/resources/org/jabref/gui/cleanup/CleanupPresetPanel.fxml +++ b/jabgui/src/main/resources/org/jabref/gui/cleanup/CleanupPresetPanel.fxml @@ -20,7 +20,6 @@ - @@ -45,9 +44,9 @@ - - - - + + + + diff --git a/jablib/src/main/java/org/jabref/logic/cleanup/CleanupWorker.java b/jablib/src/main/java/org/jabref/logic/cleanup/CleanupWorker.java index 1290f3417d6..1e4bd868f97 100644 --- a/jablib/src/main/java/org/jabref/logic/cleanup/CleanupWorker.java +++ b/jablib/src/main/java/org/jabref/logic/cleanup/CleanupWorker.java @@ -90,8 +90,6 @@ private CleanupJob toJob(CleanupPreferences.CleanupStep action) { new MoveFilesCleanup(() -> databaseContext, filePreferences); case FIX_FILE_LINKS -> new FileLinksCleanup(); - case CLEAN_UP_ISSN -> - new ISSNCleanup(); default -> throw new UnsupportedOperationException(action.name()); }; diff --git a/jablib/src/main/java/org/jabref/logic/cleanup/FieldFormatterCleanups.java b/jablib/src/main/java/org/jabref/logic/cleanup/FieldFormatterCleanups.java index 5bf2a008a19..b0725b6eaa6 100644 --- a/jablib/src/main/java/org/jabref/logic/cleanup/FieldFormatterCleanups.java +++ b/jablib/src/main/java/org/jabref/logic/cleanup/FieldFormatterCleanups.java @@ -13,14 +13,7 @@ import org.jabref.logic.formatter.Formatters; import org.jabref.logic.formatter.IdentityFormatter; -import org.jabref.logic.formatter.bibtexfields.ConvertMSCCodesFormatter; -import org.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter; -import org.jabref.logic.formatter.bibtexfields.HtmlToUnicodeFormatter; -import org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter; -import org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter; -import org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter; -import org.jabref.logic.formatter.bibtexfields.OrdinalsToSuperscriptFormatter; -import org.jabref.logic.formatter.bibtexfields.UnicodeToLatexFormatter; +import org.jabref.logic.formatter.bibtexfields.*; import org.jabref.logic.layout.format.LatexToUnicodeFormatter; import org.jabref.logic.layout.format.ReplaceUnicodeLigaturesFormatter; import org.jabref.model.FieldChange; @@ -64,7 +57,8 @@ public class FieldFormatterCleanups { new FieldFormatterCleanup(StandardField.DATE, new NormalizeDateFormatter()), new FieldFormatterCleanup(StandardField.MONTH, new NormalizeMonthFormatter()), new FieldFormatterCleanup(InternalField.INTERNAL_ALL_TEXT_FIELDS_FIELD, new ReplaceUnicodeLigaturesFormatter()), - new FieldFormatterCleanup(StandardField.KEYWORDS, new ConvertMSCCodesFormatter())); + new FieldFormatterCleanup(StandardField.KEYWORDS, new ConvertMSCCodesFormatter()), + new FieldFormatterCleanup(StandardField.ISSN, new NormalizeIssn())); List recommendedBibtexFormatters = new ArrayList<>(DEFAULT_SAVE_ACTIONS); recommendedBibtexFormatters.addAll(List.of( diff --git a/jablib/src/main/java/org/jabref/logic/cleanup/ISSNCleanup.java b/jablib/src/main/java/org/jabref/logic/cleanup/ISSNCleanup.java deleted file mode 100644 index 602048469fa..00000000000 --- a/jablib/src/main/java/org/jabref/logic/cleanup/ISSNCleanup.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.jabref.logic.cleanup; - -import java.util.List; -import java.util.Optional; - -import org.jabref.model.FieldChange; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.field.StandardField; -import org.jabref.model.entry.identifier.ISSN; - -public class ISSNCleanup implements CleanupJob { - - @Override - public List cleanup(BibEntry entry) { - Optional issnString = entry.getField(StandardField.ISSN); - if (issnString.isEmpty()) { - return List.of(); - } - - ISSN issn = new ISSN(issnString.get()); - if (issn.isCanBeCleaned()) { - String newValue = issn.getCleanedISSN(); - FieldChange change = new FieldChange(entry, StandardField.ISSN, issnString.get(), newValue); - entry.setField(StandardField.ISSN, newValue); - return List.of(change); - } - return List.of(); - } -} diff --git a/jablib/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssn.java b/jablib/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssn.java new file mode 100644 index 00000000000..72c60548f04 --- /dev/null +++ b/jablib/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssn.java @@ -0,0 +1,40 @@ +package org.jabref.logic.formatter.bibtexfields; + +import org.jabref.logic.cleanup.Formatter; +import org.jabref.model.entry.identifier.ISSN; + +public class NormalizeIssn extends Formatter { + + + @Override + public String getName() { + return "Normalize ISSN"; + } + + @Override + public String getKey() { + return "normalize_issn"; + } + + @Override + public String format(String value) { + if((value == null) || value.isBlank()) + return value; + + ISSN issn = new ISSN(value); + + if(issn.isCanBeCleaned()) + return issn.getCleanedISSN(); + return value; + } + + @Override + public String getDescription() { + return "Normalizes ISSNs by ensuring they contain a dash (e.g., 12345678 → 1234-5678)"; + } + + @Override + public String getExampleInput() { + return "12345678"; + } +} diff --git a/jablib/src/test/java/org/jabref/logic/cleanup/ISSNCleanupTest.java b/jablib/src/test/java/org/jabref/logic/cleanup/ISSNCleanupTest.java deleted file mode 100644 index 4bcadcde1c9..00000000000 --- a/jablib/src/test/java/org/jabref/logic/cleanup/ISSNCleanupTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.jabref.logic.cleanup; - -import java.util.Optional; - -import org.jabref.logic.FilePreferences; -import org.jabref.logic.preferences.TimestampPreferences; -import org.jabref.model.database.BibDatabaseContext; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.field.StandardField; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.mock; - -class ISSNCleanupTest { - - private CleanupWorker worker; - - @BeforeEach - void setUp() { - worker = new CleanupWorker( - mock(BibDatabaseContext.class), - mock(FilePreferences.class), - mock(TimestampPreferences.class)); - } - - @Test - void cleanupISSNReturnsCorrectISSN() { - CleanupPreferences preset = new CleanupPreferences(CleanupPreferences.CleanupStep.CLEAN_UP_ISSN); - BibEntry entry = new BibEntry(); - entry.setField(StandardField.ISSN, "0123-4567"); - - worker.cleanup(preset, entry); - assertEquals(Optional.of("0123-4567"), entry.getField(StandardField.ISSN)); - } - - @Test - void cleanupISSNAddsMissingDash() { - CleanupPreferences preset = new CleanupPreferences(CleanupPreferences.CleanupStep.CLEAN_UP_ISSN); - BibEntry entry = new BibEntry(); - entry.setField(StandardField.ISSN, "01234567"); - - worker.cleanup(preset, entry); - assertEquals(Optional.of("0123-4567"), entry.getField(StandardField.ISSN)); - } - - @Test - void cleanupISSNJunkStaysJunk() { - CleanupPreferences preset = new CleanupPreferences(CleanupPreferences.CleanupStep.CLEAN_UP_ISSN); - BibEntry entry = new BibEntry(); - entry.setField(StandardField.ISSN, "Banana"); - - worker.cleanup(preset, entry); - assertEquals(Optional.of("Banana"), entry.getField(StandardField.ISSN)); - } -} diff --git a/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java b/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java new file mode 100644 index 00000000000..28b438a0420 --- /dev/null +++ b/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java @@ -0,0 +1,32 @@ +package org.jabref.logic.formatter.bibtexfields; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +class NormalizeISSNTest { + + private final NormalizeIssn formatISSN = new NormalizeIssn(); + + @Test + void returnValidIssnUnchanged() { + assertEquals("0123-4567", formatISSN.format("0123-4567")); + } + + @Test + void assMissingDashToIssn() { + assertEquals("0123-4567",formatISSN.format("01234567")); + } + + @Test + void leavesInvalidInputUnchanged() { + assertEquals("Banana", formatISSN.format("Banana")); + } + + @Test + void emptyOrNullReturnsSame() { + assertEquals("",formatISSN.format("")); + assertNull(formatISSN.format(null)); + } +} From c3687be2b1a897ffeec9c5f0b4221153aae9f12b Mon Sep 17 00:00:00 2001 From: siddhant Date: Wed, 27 Aug 2025 23:45:40 +0530 Subject: [PATCH 2/5] fixed earlier failure and fixed style --- CHANGELOG.md | 1 + .../logic/cleanup/FieldFormatterCleanups.java | 10 +++++++++- .../org/jabref/logic/formatter/Formatters.java | 4 +++- .../formatter/bibtexfields/NormalizeIssn.java | 15 ++++++++++----- .../src/main/resources/l10n/JabRef_en.properties | 2 +- .../logic/cleanup/FieldFormatterCleanupsTest.java | 2 ++ .../formatter/bibtexfields/NormalizeIssnTest.java | 11 +++++------ 7 files changed, 31 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 165f102acd3..f16749a9be4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We added support for finding CSL-Styles based on their short title (e.g. apa instead of "american psychological association"). [#13728](https://github.com/JabRef/jabref/pull/13728) ### Changed + - We changed `ISSNCleanup` into `NormalizeIssn` a `ISSN` formatter. [#13748](https://github.com/JabRef/jabref/issues/13748) - We changed Citation Relations tab and gave tab panes more descriptive titles and tooltips. [#13619](https://github.com/JabRef/jabref/issues/13619) - We changed the name from Open AI Provider to Open AI (or API compatible). [#13585](https://github.com/JabRef/jabref/issues/13585) diff --git a/jablib/src/main/java/org/jabref/logic/cleanup/FieldFormatterCleanups.java b/jablib/src/main/java/org/jabref/logic/cleanup/FieldFormatterCleanups.java index b0725b6eaa6..8063b15a67b 100644 --- a/jablib/src/main/java/org/jabref/logic/cleanup/FieldFormatterCleanups.java +++ b/jablib/src/main/java/org/jabref/logic/cleanup/FieldFormatterCleanups.java @@ -13,7 +13,15 @@ import org.jabref.logic.formatter.Formatters; import org.jabref.logic.formatter.IdentityFormatter; -import org.jabref.logic.formatter.bibtexfields.*; +import org.jabref.logic.formatter.bibtexfields.ConvertMSCCodesFormatter; +import org.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter; +import org.jabref.logic.formatter.bibtexfields.HtmlToUnicodeFormatter; +import org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter; +import org.jabref.logic.formatter.bibtexfields.NormalizeIssn; +import org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter; +import org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter; +import org.jabref.logic.formatter.bibtexfields.OrdinalsToSuperscriptFormatter; +import org.jabref.logic.formatter.bibtexfields.UnicodeToLatexFormatter; import org.jabref.logic.layout.format.LatexToUnicodeFormatter; import org.jabref.logic.layout.format.ReplaceUnicodeLigaturesFormatter; import org.jabref.model.FieldChange; diff --git a/jablib/src/main/java/org/jabref/logic/formatter/Formatters.java b/jablib/src/main/java/org/jabref/logic/formatter/Formatters.java index a830762f5a5..3da6bc203db 100644 --- a/jablib/src/main/java/org/jabref/logic/formatter/Formatters.java +++ b/jablib/src/main/java/org/jabref/logic/formatter/Formatters.java @@ -20,6 +20,7 @@ import org.jabref.logic.formatter.bibtexfields.HtmlToUnicodeFormatter; import org.jabref.logic.formatter.bibtexfields.LatexCleanupFormatter; import org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter; +import org.jabref.logic.formatter.bibtexfields.NormalizeIssn; import org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter; import org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter; import org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter; @@ -98,7 +99,8 @@ public static List getOthers() { new ShortenDOIFormatter(), new NormalizeUnicodeFormatter(), new ReplaceUnicodeLigaturesFormatter(), - new UnprotectTermsFormatter() + new UnprotectTermsFormatter(), + new NormalizeIssn() ); } diff --git a/jablib/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssn.java b/jablib/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssn.java index 72c60548f04..cb95226352f 100644 --- a/jablib/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssn.java +++ b/jablib/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssn.java @@ -1,14 +1,16 @@ package org.jabref.logic.formatter.bibtexfields; import org.jabref.logic.cleanup.Formatter; +import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.identifier.ISSN; -public class NormalizeIssn extends Formatter { +import java.util.Objects; +public class NormalizeIssn extends Formatter { @Override public String getName() { - return "Normalize ISSN"; + return Localization.lang( "Normalize ISSN"); } @Override @@ -18,13 +20,16 @@ public String getKey() { @Override public String format(String value) { - if((value == null) || value.isBlank()) - return value; + Objects.requireNonNull(value); + if (value.isBlank()) { + return value; + } ISSN issn = new ISSN(value); - if(issn.isCanBeCleaned()) + if (issn.isCanBeCleaned()) { return issn.getCleanedISSN(); + } return value; } diff --git a/jablib/src/main/resources/l10n/JabRef_en.properties b/jablib/src/main/resources/l10n/JabRef_en.properties index 0473ea5ff3b..5a3c48724f2 100644 --- a/jablib/src/main/resources/l10n/JabRef_en.properties +++ b/jablib/src/main/resources/l10n/JabRef_en.properties @@ -1731,7 +1731,7 @@ Found\ touching\ ranges=Found touching ranges Note\:\ Use\ the\ placeholder\ %DIR%\ for\ the\ location\ of\ the\ opened\ library\ file.=Note: Use the placeholder %DIR% for the location of the opened library file. Error\ occurred\ while\ executing\ the\ command\ \"%0\".=Error occurred while executing the command \"%0\". -Reformat\ ISSN=Reformat ISSN +Normalize\ ISSN=Normalize ISSN Computer\ science=Computer science Countries\ and\ territories\ in\ English=Countries and territories in English diff --git a/jablib/src/test/java/org/jabref/logic/cleanup/FieldFormatterCleanupsTest.java b/jablib/src/test/java/org/jabref/logic/cleanup/FieldFormatterCleanupsTest.java index 95b6aca99bf..a36c7cb2a2f 100644 --- a/jablib/src/test/java/org/jabref/logic/cleanup/FieldFormatterCleanupsTest.java +++ b/jablib/src/test/java/org/jabref/logic/cleanup/FieldFormatterCleanupsTest.java @@ -339,6 +339,7 @@ void getMetaDataStringWorks() { month[normalize_month] all-text-fields[replace_unicode_ligatures] keywords[MSC_codes_to_descriptions] + issn[normalize_issn] """, FieldFormatterCleanups.getMetaDataString(FieldFormatterCleanups.DEFAULT_SAVE_ACTIONS, "\n")); } @@ -350,6 +351,7 @@ void parsingOfDefaultSaveActions() { month[normalize_month] all-text-fields[replace_unicode_ligatures] keywords[MSC_codes_to_descriptions] + issn[normalize_issn] """)); } diff --git a/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java b/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java index 28b438a0420..97e917b99b4 100644 --- a/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java +++ b/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java @@ -2,8 +2,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.*; class NormalizeISSNTest { @@ -15,8 +14,8 @@ void returnValidIssnUnchanged() { } @Test - void assMissingDashToIssn() { - assertEquals("0123-4567",formatISSN.format("01234567")); + void addMissingDashToIssn() { + assertEquals("0123-4567", formatISSN.format("01234567")); } @Test @@ -26,7 +25,7 @@ void leavesInvalidInputUnchanged() { @Test void emptyOrNullReturnsSame() { - assertEquals("",formatISSN.format("")); - assertNull(formatISSN.format(null)); + assertEquals("", formatISSN.format("")); + assertThrows(NullPointerException.class, () -> formatISSN.format(null)); } } From 7bcfe620b36854b4e5d926ba185f92022649c67c Mon Sep 17 00:00:00 2001 From: siddhant Date: Thu, 28 Aug 2025 01:50:09 +0530 Subject: [PATCH 3/5] fixed style(fixes #13748) --- .../jabref/logic/formatter/bibtexfields/NormalizeIssn.java | 6 +++--- .../logic/formatter/bibtexfields/NormalizeIssnTest.java | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/jablib/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssn.java b/jablib/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssn.java index cb95226352f..cd33f85998b 100644 --- a/jablib/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssn.java +++ b/jablib/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssn.java @@ -1,16 +1,16 @@ package org.jabref.logic.formatter.bibtexfields; +import java.util.Objects; + import org.jabref.logic.cleanup.Formatter; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.identifier.ISSN; -import java.util.Objects; - public class NormalizeIssn extends Formatter { @Override public String getName() { - return Localization.lang( "Normalize ISSN"); + return Localization.lang("Normalize ISSN"); } @Override diff --git a/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java b/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java index 97e917b99b4..ac11ea6d7e9 100644 --- a/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java +++ b/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java @@ -2,7 +2,8 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; class NormalizeISSNTest { From ccda2f990b605dd76dfaf5b72249287697dddcac Mon Sep 17 00:00:00 2001 From: siddhant Date: Thu, 28 Aug 2025 18:00:44 +0530 Subject: [PATCH 4/5] Refactor: Normalize ISSN with @NonNull, parameterized tests --- .../jabref/logic/formatter/Formatters.java | 6 ++-- .../formatter/bibtexfields/NormalizeIssn.java | 7 ++-- .../bibtexfields/NormalizeIssnTest.java | 32 +++++++------------ 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/jablib/src/main/java/org/jabref/logic/formatter/Formatters.java b/jablib/src/main/java/org/jabref/logic/formatter/Formatters.java index 3da6bc203db..f7fa786fc19 100644 --- a/jablib/src/main/java/org/jabref/logic/formatter/Formatters.java +++ b/jablib/src/main/java/org/jabref/logic/formatter/Formatters.java @@ -86,9 +86,11 @@ public static List getOthers() { new LatexCleanupFormatter(), new MinifyNameListFormatter(), new NormalizeDateFormatter(), + new NormalizeIssn(), new NormalizeMonthFormatter(), new NormalizeNamesFormatter(), new NormalizePagesFormatter(), + new NormalizeUnicodeFormatter(), new OrdinalsToSuperscriptFormatter(), new RemoveEnclosingBracesFormatter(), new RemoveWordEnclosingAndOuterEnclosingBracesFormatter(), @@ -97,10 +99,8 @@ public static List getOthers() { new EscapeAmpersandsFormatter(), new EscapeDollarSignFormatter(), new ShortenDOIFormatter(), - new NormalizeUnicodeFormatter(), new ReplaceUnicodeLigaturesFormatter(), - new UnprotectTermsFormatter(), - new NormalizeIssn() + new UnprotectTermsFormatter() ); } diff --git a/jablib/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssn.java b/jablib/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssn.java index cd33f85998b..6c8e82f757d 100644 --- a/jablib/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssn.java +++ b/jablib/src/main/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssn.java @@ -1,11 +1,11 @@ package org.jabref.logic.formatter.bibtexfields; -import java.util.Objects; - import org.jabref.logic.cleanup.Formatter; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.identifier.ISSN; +import org.jspecify.annotations.NonNull; + public class NormalizeIssn extends Formatter { @Override @@ -19,8 +19,7 @@ public String getKey() { } @Override - public String format(String value) { - Objects.requireNonNull(value); + public String format(@NonNull String value) { if (value.isBlank()) { return value; } diff --git a/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java b/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java index ac11ea6d7e9..9b8ef520e5f 100644 --- a/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java +++ b/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java @@ -1,32 +1,22 @@ package org.jabref.logic.formatter.bibtexfields; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; class NormalizeISSNTest { private final NormalizeIssn formatISSN = new NormalizeIssn(); - @Test - void returnValidIssnUnchanged() { - assertEquals("0123-4567", formatISSN.format("0123-4567")); - } - - @Test - void addMissingDashToIssn() { - assertEquals("0123-4567", formatISSN.format("01234567")); - } - - @Test - void leavesInvalidInputUnchanged() { - assertEquals("Banana", formatISSN.format("Banana")); - } - - @Test - void emptyOrNullReturnsSame() { - assertEquals("", formatISSN.format("")); - assertThrows(NullPointerException.class, () -> formatISSN.format(null)); + @ParameterizedTest + @CsvSource({ + "0123-4567, 0123-4567", + "01234567, 0123-4567", + "Banana, Banana", + "'',''" + }) + void testIssnFormatting(String input, String expected) { + assertEquals(expected, formatISSN.format(input)); } } From 1122be97c7a3ab1b8790ab9f557b36ac22f408b4 Mon Sep 17 00:00:00 2001 From: siddhant Date: Thu, 28 Aug 2025 18:20:16 +0530 Subject: [PATCH 5/5] Apply OpenRewrite cleanup to NormalizeIssnTest --- .../jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java b/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java index 9b8ef520e5f..c631df53df3 100644 --- a/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java +++ b/jablib/src/test/java/org/jabref/logic/formatter/bibtexfields/NormalizeIssnTest.java @@ -16,7 +16,7 @@ class NormalizeISSNTest { "Banana, Banana", "'',''" }) - void testIssnFormatting(String input, String expected) { + void issnFormatting(String input, String expected) { assertEquals(expected, formatISSN.format(input)); } }