diff --git a/rewrite.yml b/rewrite.yml index 7d5eaad4866..bbaa6bb76ab 100644 --- a/rewrite.yml +++ b/rewrite.yml @@ -195,3 +195,7 @@ recipeList: - org.openrewrite.staticanalysis.UseSystemLineSeparator - org.openrewrite.staticanalysis.WhileInsteadOfFor # - org.openrewrite.staticanalysis.WriteOctalValuesAsDecimal + + - org.openrewrite.java.testing.junit5.CleanupAssertions + # - org.openrewrite.java.testing.junit5.JUnit5BestPractices + # - org.openrewrite.java.testing.junit5.UpgradeOkHttpMockWebServer diff --git a/src/test/java/org/jabref/gui/externalfiles/FileFilterUtilsTest.java b/src/test/java/org/jabref/gui/externalfiles/FileFilterUtilsTest.java index 9af4b1364bb..9deab592e8f 100755 --- a/src/test/java/org/jabref/gui/externalfiles/FileFilterUtilsTest.java +++ b/src/test/java/org/jabref/gui/externalfiles/FileFilterUtilsTest.java @@ -16,7 +16,9 @@ import org.junit.jupiter.api.io.TempDir; 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 FileFilterUtilsTest { @@ -25,42 +27,42 @@ public class FileFilterUtilsTest { @Test public void isDuringLastDayNegativeTest() { - assertEquals(fileFilterUtils.isDuringLastDay(time.minusHours(24)), false); + assertFalse(fileFilterUtils.isDuringLastDay(time.minusHours(24))); } @Test public void isDuringLastDayPositiveTest() { - assertEquals(fileFilterUtils.isDuringLastDay(time.minusHours(23)), true); + assertTrue(fileFilterUtils.isDuringLastDay(time.minusHours(23))); } @Test public void isDuringLastWeekNegativeTest() { - assertEquals(fileFilterUtils.isDuringLastWeek(time.minusDays(7)), false); + assertFalse(fileFilterUtils.isDuringLastWeek(time.minusDays(7))); } @Test public void isDuringLastWeekPositiveTest() { - assertEquals(fileFilterUtils.isDuringLastWeek(time.minusDays(6).minusHours(23)), true); + assertTrue(fileFilterUtils.isDuringLastWeek(time.minusDays(6).minusHours(23))); } @Test public void isDuringLastMonthNegativeTest() { - assertEquals(fileFilterUtils.isDuringLastMonth(time.minusDays(30)), false); + assertFalse(fileFilterUtils.isDuringLastMonth(time.minusDays(30))); } @Test public void isDuringLastMonthPositiveTest() { - assertEquals(fileFilterUtils.isDuringLastMonth(time.minusDays(29).minusHours(23)), true); + assertTrue(fileFilterUtils.isDuringLastMonth(time.minusDays(29).minusHours(23))); } @Test public void isDuringLastYearNegativeTest() { - assertEquals(fileFilterUtils.isDuringLastYear(time.minusDays(365)), false); + assertFalse(fileFilterUtils.isDuringLastYear(time.minusDays(365))); } @Test public void isDuringLastYearPositiveTest() { - assertEquals(fileFilterUtils.isDuringLastYear(time.minusDays(364).minusHours(23)), true); + assertTrue(fileFilterUtils.isDuringLastYear(time.minusDays(364).minusHours(23))); } @Nested diff --git a/src/test/java/org/jabref/gui/maintable/MainTableColumnModelTest.java b/src/test/java/org/jabref/gui/maintable/MainTableColumnModelTest.java index a344886401a..750d92708fb 100644 --- a/src/test/java/org/jabref/gui/maintable/MainTableColumnModelTest.java +++ b/src/test/java/org/jabref/gui/maintable/MainTableColumnModelTest.java @@ -52,6 +52,6 @@ public void typeOnlyMainTableColumnModelParserRetrievesCorrectType() { public void typeOnlyMainTableColumnModelParserRetrievesCorrectQualifier() { MainTableColumnModel testColumnModel = MainTableColumnModel.parse(testTypeOnlyName); - assertEquals(testColumnModel.getQualifier(), ""); + assertEquals("", testColumnModel.getQualifier()); } } diff --git a/src/test/java/org/jabref/gui/sidepane/SidePaneViewModelTest.java b/src/test/java/org/jabref/gui/sidepane/SidePaneViewModelTest.java index 27db78fe64d..0419752b78e 100644 --- a/src/test/java/org/jabref/gui/sidepane/SidePaneViewModelTest.java +++ b/src/test/java/org/jabref/gui/sidepane/SidePaneViewModelTest.java @@ -76,30 +76,30 @@ void setUp() { void moveUp() { sidePaneViewModel.moveUp(SidePaneType.WEB_SEARCH); - assertEquals(sidePaneComponents.get(0), SidePaneType.WEB_SEARCH); - assertEquals(sidePaneComponents.get(1), SidePaneType.GROUPS); + assertEquals(SidePaneType.WEB_SEARCH, sidePaneComponents.get(0)); + assertEquals(SidePaneType.GROUPS, sidePaneComponents.get(1)); } @Test void moveUpFromFirstPosition() { sidePaneViewModel.moveUp(SidePaneType.GROUPS); - assertEquals(sidePaneComponents.get(0), SidePaneType.GROUPS); + assertEquals(SidePaneType.GROUPS, sidePaneComponents.get(0)); } @Test void moveDown() { sidePaneViewModel.moveDown(SidePaneType.WEB_SEARCH); - assertEquals(sidePaneComponents.get(1), SidePaneType.OPEN_OFFICE); - assertEquals(sidePaneComponents.get(2), SidePaneType.WEB_SEARCH); + assertEquals(SidePaneType.OPEN_OFFICE, sidePaneComponents.get(1)); + assertEquals(SidePaneType.WEB_SEARCH, sidePaneComponents.get(2)); } @Test void moveDownFromLastPosition() { sidePaneViewModel.moveDown(SidePaneType.OPEN_OFFICE); - assertEquals(sidePaneComponents.get(2), SidePaneType.OPEN_OFFICE); + assertEquals(SidePaneType.OPEN_OFFICE, sidePaneComponents.get(2)); } @Test diff --git a/src/test/java/org/jabref/gui/theme/ThemeManagerTest.java b/src/test/java/org/jabref/gui/theme/ThemeManagerTest.java index f96308c18b8..87e1d1a654c 100644 --- a/src/test/java/org/jabref/gui/theme/ThemeManagerTest.java +++ b/src/test/java/org/jabref/gui/theme/ThemeManagerTest.java @@ -145,7 +145,7 @@ public void largeCustomThemeNotHeldInMemory() throws IOException { Files.move(largeCssTestFile, largeCssTestFile.resolveSibling("renamed.css")); // getAdditionalStylesheet() should no longer offer the deleted stylesheet as it is not been held in memory - assertEquals(themeManager.getActiveTheme().getAdditionalStylesheet().get().getWebEngineStylesheet(), "", + assertEquals("", themeManager.getActiveTheme().getAdditionalStylesheet().get().getWebEngineStylesheet(), "didn't expect additional stylesheet after css was deleted"); Files.move(largeCssTestFile.resolveSibling("renamed.css"), largeCssTestFile); @@ -194,7 +194,7 @@ public void installThemeOnWebEngine() throws IOException { }); Assertions.assertDoesNotThrow(() -> { - assertEquals(webEngineStyleSheetLocation.get(), TEST_CSS_DATA); + assertEquals(TEST_CSS_DATA, webEngineStyleSheetLocation.get()); }); } diff --git a/src/test/java/org/jabref/logic/bibtex/comparator/BibStringDiffTest.java b/src/test/java/org/jabref/logic/bibtex/comparator/BibStringDiffTest.java index 28f8ed4d801..03527cb4387 100644 --- a/src/test/java/org/jabref/logic/bibtex/comparator/BibStringDiffTest.java +++ b/src/test/java/org/jabref/logic/bibtex/comparator/BibStringDiffTest.java @@ -10,9 +10,7 @@ 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; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -54,17 +52,17 @@ void notEqualTest() { @Test void identicalObjectsAreEqual() { BibStringDiff other = diff; - assertTrue(other.equals(diff)); + assertEquals(other, diff); } @Test void compareToNullObjectIsFalse() { - assertFalse(diff.equals(null)); + assertNotEquals(null, diff); } @Test void compareToDifferentClassIsFalse() { - assertFalse(diff.equals(new Object())); + assertNotEquals(diff, new Object()); } @Test diff --git a/src/test/java/org/jabref/logic/database/DatabaseMergerTest.java b/src/test/java/org/jabref/logic/database/DatabaseMergerTest.java index a7464dbaed5..b6a874c93b6 100644 --- a/src/test/java/org/jabref/logic/database/DatabaseMergerTest.java +++ b/src/test/java/org/jabref/logic/database/DatabaseMergerTest.java @@ -162,7 +162,7 @@ void mergeMetaDataWithoutAllEntriesGroup() { // Assert that groups of other are children of root node of target assertEquals(targetRootGroup, target.getGroups().get()); - assertEquals(target.getGroups().get().getChildren().size(), 1); + assertEquals(1, target.getGroups().get().getChildren().size()); assertEquals(otherRootGroup, target.getGroups().get().getChildren().get(0)); } @@ -185,7 +185,7 @@ void mergeMetaDataWithAllEntriesGroup() { // Assert that groups of other are children of root node of target assertEquals(targetRootGroup, target.getGroups().get()); - assertEquals(target.getGroups().get().getChildren().size(), 1); + assertEquals(1, target.getGroups().get().getChildren().size()); assertEquals(expectedImportedGroupNode, target.getGroups().get().getChildren().get(0)); assertEquals(expectedContentSelectors, target.getContentSelectorList()); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IacrEprintFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/IacrEprintFetcherTest.java index 2eb837d2364..c168c4bceb7 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/IacrEprintFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/IacrEprintFetcherTest.java @@ -168,7 +168,7 @@ public void searchByIdWithOldHtmlFormatWithoutDateCheck(String id) throws Fetche Optional fetchedEntry = fetcher.performSearchById(id); assertTrue(fetchedEntry.isPresent(), "Expected to get an entry for id " + id); assertNotEquals(Optional.empty(), fetchedEntry.get().getField(StandardField.DATE), "Expected non empty date field, entry is\n" + fetchedEntry.toString()); - assertTrue(fetchedEntry.get().getField(StandardField.DATE).get().length() == 10, "Expected yyyy-MM-dd date format, entry is\n" + fetchedEntry.toString()); + assertEquals(10, fetchedEntry.get().getField(StandardField.DATE).get().length(), "Expected yyyy-MM-dd date format, entry is\n" + fetchedEntry.toString()); assertNotEquals(Optional.empty(), fetchedEntry.get().getField(StandardField.ABSTRACT), "Expected non empty abstract field, entry is\n" + fetchedEntry.toString()); } diff --git a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java index 1f3ba7a8eab..423e235c0c2 100644 --- a/src/test/java/org/jabref/logic/journals/AbbreviationTest.java +++ b/src/test/java/org/jabref/logic/journals/AbbreviationTest.java @@ -105,10 +105,10 @@ void testDefaultAndShortestUniqueAbbreviationsAreSame() { @Test void testEquals() { - Abbreviation abbreviation = new Abbreviation("Long Name", "L N", "LN"); - Abbreviation otherAbbreviation = new Abbreviation("Long Name", "L N", "LN"); - assertEquals(abbreviation, otherAbbreviation); - assertNotEquals(abbreviation, "String"); + Abbreviation abbreviation = new Abbreviation("Long Name", "L N", "LN"); + Abbreviation otherAbbreviation = new Abbreviation("Long Name", "L N", "LN"); + assertEquals(abbreviation, otherAbbreviation); + assertNotEquals("String", abbreviation); } @Test diff --git a/src/test/java/org/jabref/logic/layout/format/ReplaceTest.java b/src/test/java/org/jabref/logic/layout/format/ReplaceTest.java index 3d1eb4ebb9b..31bc81144f5 100644 --- a/src/test/java/org/jabref/logic/layout/format/ReplaceTest.java +++ b/src/test/java/org/jabref/logic/layout/format/ReplaceTest.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class ReplaceTest { @@ -26,7 +27,7 @@ public void testSimpleTextNoHit() { public void testFormatNull() { ParamLayoutFormatter a = new Replace(); a.setArgument("Eds.,Ed."); - assertEquals(null, a.format(null)); + assertNull(a.format(null)); } @Test diff --git a/src/test/java/org/jabref/logic/msbib/MsBibAuthorTest.java b/src/test/java/org/jabref/logic/msbib/MsBibAuthorTest.java index 3b09b26c7d9..2ccef4f8722 100644 --- a/src/test/java/org/jabref/logic/msbib/MsBibAuthorTest.java +++ b/src/test/java/org/jabref/logic/msbib/MsBibAuthorTest.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class MsBibAuthorTest { @@ -26,14 +27,14 @@ public void testGetMiddleName() { public void testGetNoMiddleName() { Author author = new Author("Gustav", null, null, "Bach", null); MsBibAuthor msBibAuthor = new MsBibAuthor(author); - assertEquals(null, msBibAuthor.getMiddleName()); + assertNull(msBibAuthor.getMiddleName()); } @Test public void testGetNoFirstName() { Author author = new Author(null, null, null, "Bach", null); MsBibAuthor msBibAuthor = new MsBibAuthor(author); - assertEquals(null, msBibAuthor.getMiddleName()); + assertNull(msBibAuthor.getMiddleName()); } @Test diff --git a/src/test/java/org/jabref/logic/net/ProxyTest.java b/src/test/java/org/jabref/logic/net/ProxyTest.java index 6b6e844d1b6..20f904441cb 100644 --- a/src/test/java/org/jabref/logic/net/ProxyTest.java +++ b/src/test/java/org/jabref/logic/net/ProxyTest.java @@ -3,6 +3,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ProxyTest { /** @@ -31,10 +32,10 @@ public void testProxyPreferencesStorePassword() { persist); // Check if mock data is stored in object memory and can be extracted - assertEquals(proxyPref.shouldUseProxy(), true); + assertTrue(proxyPref.shouldUseProxy()); assertEquals(proxyPref.getHostname(), hostname); assertEquals(proxyPref.getPort(), port); - assertEquals(proxyPref.shouldUseAuthentication(), true); + assertTrue(proxyPref.shouldUseAuthentication()); assertEquals(proxyPref.getUsername(), username); assertEquals(proxyPref.getPassword(), password); assertEquals(proxyPref.shouldPersistPassword(), persist); diff --git a/src/test/java/org/jabref/model/FieldChangeTest.java b/src/test/java/org/jabref/model/FieldChangeTest.java index 1625a1ae652..b2a6b77f64b 100644 --- a/src/test/java/org/jabref/model/FieldChangeTest.java +++ b/src/test/java/org/jabref/model/FieldChangeTest.java @@ -57,7 +57,7 @@ void selfEqualsFieldchangeDifferentEntry() { @Test void fieldChangeDoesNotEqualString() { - assertNotEquals(fc, "foo"); + assertNotEquals("foo", fc); } @Test diff --git a/src/test/java/org/jabref/model/entry/BibEntryTest.java b/src/test/java/org/jabref/model/entry/BibEntryTest.java index b913030cc73..63cd6657bc9 100644 --- a/src/test/java/org/jabref/model/entry/BibEntryTest.java +++ b/src/test/java/org/jabref/model/entry/BibEntryTest.java @@ -364,17 +364,17 @@ void isEmptyCiteKey() { @Test void identicObjectsareEqual() throws Exception { BibEntry otherEntry = entry; - assertTrue(entry.equals(otherEntry)); + assertEquals(entry, otherEntry); } @Test void compareToNullObjectIsFalse() throws Exception { - assertFalse(entry.equals(null)); + assertNotEquals(null, entry); } @Test void compareToDifferentClassIsFalse() throws Exception { - assertFalse(entry.equals(new Object())); + assertNotEquals(entry, new Object()); } @Test diff --git a/src/test/java/org/jabref/model/openoffice/CitationEntryTest.java b/src/test/java/org/jabref/model/openoffice/CitationEntryTest.java index 8648d9b5df9..481afa00eac 100644 --- a/src/test/java/org/jabref/model/openoffice/CitationEntryTest.java +++ b/src/test/java/org/jabref/model/openoffice/CitationEntryTest.java @@ -48,7 +48,7 @@ void testCitationEntryEquals() { assertEquals(citationEntry1, citationEntry1); assertEquals(citationEntry1, citationEntry3); assertNotEquals(citationEntry1, citationEntry2); - assertNotEquals(citationEntry1, "Random String"); + assertNotEquals("Random String", citationEntry1); } @Test diff --git a/src/test/java/org/jabref/model/strings/StringUtilTest.java b/src/test/java/org/jabref/model/strings/StringUtilTest.java index a1ba47b247a..f41584e1939 100644 --- a/src/test/java/org/jabref/model/strings/StringUtilTest.java +++ b/src/test/java/org/jabref/model/strings/StringUtilTest.java @@ -14,6 +14,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -142,7 +143,7 @@ void testStripBrackets() { assertEquals("]", StringUtil.stripBrackets("]")); assertEquals("", StringUtil.stripBrackets("[]")); assertEquals("f[]f", StringUtil.stripBrackets("f[]f")); - assertEquals(null, StringUtil.stripBrackets(null)); + assertNull(StringUtil.stripBrackets(null)); } @Test