Skip to content

Commit

Permalink
Clean up test code (JabRef#10658)
Browse files Browse the repository at this point in the history
* Enable org.openrewrite.java.testing.junit5.CleanupAssertions

* Fix indent

* Update rewrite.yml
  • Loading branch information
koppor authored Nov 21, 2023
1 parent 77a360a commit 75107ab
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 40 deletions.
3 changes: 3 additions & 0 deletions rewrite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,6 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public void typeOnlyMainTableColumnModelParserRetrievesCorrectType() {
public void typeOnlyMainTableColumnModelParserRetrievesCorrectQualifier() {
MainTableColumnModel testColumnModel = MainTableColumnModel.parse(testTypeOnlyName);

assertEquals(testColumnModel.getQualifier(), "");
assertEquals("", testColumnModel.getQualifier());
}
}
12 changes: 6 additions & 6 deletions src/test/java/org/jabref/gui/sidepane/SidePaneViewModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/jabref/gui/theme/ThemeManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -194,7 +194,7 @@ public void installThemeOnWebEngine() throws IOException {
});

Assertions.assertDoesNotThrow(() -> {
assertEquals(webEngineStyleSheetLocation.get(), TEST_CSS_DATA);
assertEquals(TEST_CSS_DATA, webEngineStyleSheetLocation.get());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void searchByIdWithOldHtmlFormatWithoutDateCheck(String id) throws Fetche
Optional<BibEntry> 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());
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/jabref/logic/journals/AbbreviationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/jabref/logic/msbib/MsBibAuthorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/jabref/logic/net/ProxyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/jabref/model/FieldChangeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void selfEqualsFieldchangeDifferentEntry() {

@Test
void fieldChangeDoesNotEqualString() {
assertNotEquals(fc, "foo");
assertNotEquals("foo", fc);
}

@Test
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/jabref/model/entry/BibEntryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void testCitationEntryEquals() {
assertEquals(citationEntry1, citationEntry1);
assertEquals(citationEntry1, citationEntry3);
assertNotEquals(citationEntry1, citationEntry2);
assertNotEquals(citationEntry1, "Random String");
assertNotEquals("Random String", citationEntry1);
}

@Test
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/jabref/model/strings/StringUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 75107ab

Please sign in to comment.