Skip to content

Commit

Permalink
Enable org.openrewrite.java.testing.junit5.JUnit5BestPractices
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Nov 21, 2023
1 parent f6b772c commit 4f4ac59
Show file tree
Hide file tree
Showing 351 changed files with 2,171 additions and 2,169 deletions.
2 changes: 1 addition & 1 deletion rewrite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,5 @@ recipeList:
# - org.openrewrite.staticanalysis.WriteOctalValuesAsDecimal

- org.openrewrite.java.testing.junit5.CleanupAssertions
# - org.openrewrite.java.testing.junit5.JUnit5BestPractices
- org.openrewrite.java.testing.junit5.JUnit5BestPractices
# - org.openrewrite.java.testing.junit5.UpgradeOkHttpMockWebServer
4 changes: 2 additions & 2 deletions src/test/java/org/jabref/IconsPropertiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class IconsPropertiesTest {
class IconsPropertiesTest {

@Test
public void testExistenceOfIconImagesReferencedFromIconsProperties() throws IOException {
void testExistenceOfIconImagesReferencedFromIconsProperties() throws IOException {
String folder = "src/main/resources/images/external";
String iconsProperties = "Icons.properties";
String iconsPropertiesPath = "src/main/resources/images/" + iconsProperties;
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/jabref/cli/AuxCommandLineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.mock;

public class AuxCommandLineTest {
class AuxCommandLineTest {

private ImportFormatPreferences importFormatPreferences;

@BeforeEach
public void setUp() throws Exception {
void setUp() throws Exception {
importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS);
}

@Test
public void test() throws URISyntaxException, IOException {
void test() throws URISyntaxException, IOException {
InputStream originalStream = AuxCommandLineTest.class.getResourceAsStream("origin.bib");

File auxFile = Path.of(AuxCommandLineTest.class.getResource("paper.aux").toURI()).toFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

public class AppendPersonNamesStrategyTest {
class AppendPersonNamesStrategyTest {

@Test
void testWithoutParam() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class ContentSelectorSuggestionProviderTest {
class ContentSelectorSuggestionProviderTest {

private ContentSelectorSuggestionProvider autoCompleter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

public class PersonNameStringConverterTest {
class PersonNameStringConverterTest {

/** The author. **/
private Author author;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SuggestionProvidersTest {
private SuggestionProviders suggestionProviders;

@BeforeEach
public void initializeSuggestionProviders() {
void initializeSuggestionProviders() {
BibDatabase database = new BibDatabase();
JournalAbbreviationRepository abbreviationRepository = mock(JournalAbbreviationRepository.class);
Set<Field> completeFields = Set.of(StandardField.AUTHOR, StandardField.XREF, StandardField.XDATA, StandardField.JOURNAL, StandardField.PUBLISHER, SpecialField.PRINTED);
Expand Down Expand Up @@ -57,7 +57,7 @@ private static Stream<Arguments> getTestPairs() {

@ParameterizedTest
@MethodSource("getTestPairs")
public void testAppropriateCompleterReturned(Class<SuggestionProvider<BibEntry>> expected, Field field) {
void testAppropriateCompleterReturned(Class<SuggestionProvider<BibEntry>> expected, Field field) {
assertEquals(expected, suggestionProviders.getForField(field).getClass());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BackupManagerDiscardedTest {
private Path backupDir;

@BeforeEach
public void setup(@TempDir Path tempDir) throws Exception {
void setup(@TempDir Path tempDir) throws Exception {
this.backupDir = tempDir.resolve("backups");
Files.createDirectories(backupDir);

Expand Down Expand Up @@ -85,22 +85,22 @@ private void makeBackup() {
}

@Test
public void noDiscardingAChangeLeadsToNewerBackupBeReported() throws Exception {
void noDiscardingAChangeLeadsToNewerBackupBeReported() throws Exception {
databaseModification();
makeBackup();
assertTrue(BackupManager.backupFileDiffers(testBib, backupDir));
}

@Test
public void noDiscardingASavedChange() throws Exception {
void noDiscardingASavedChange() throws Exception {
databaseModification();
makeBackup();
saveDatabase();
assertFalse(BackupManager.backupFileDiffers(testBib, backupDir));
}

@Test
public void discardingAChangeLeadsToNewerBackupToBeIgnored() throws Exception {
void discardingAChangeLeadsToNewerBackupToBeIgnored() throws Exception {
databaseModification();
makeBackup();
backupManager.discardBackup(backupDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class BackupManagerTest {
class BackupManagerTest {

Path backupDir;

Expand All @@ -43,7 +43,7 @@ void setup(@TempDir Path tempDir) {
}

@Test
public void backupFileNameIsCorrectlyGeneratedInAppDataDirectory() {
void backupFileNameIsCorrectlyGeneratedInAppDataDirectory() {
Path bibPath = Path.of("tmp", "test.bib");
backupDir = OS.getNativeDesktop().getBackupDirectory();
Path bakPath = BackupManager.getBackupPathForNewBackup(bibPath, backupDir);
Expand All @@ -53,13 +53,13 @@ public void backupFileNameIsCorrectlyGeneratedInAppDataDirectory() {
}

@Test
public void backupFileIsEqualForNonExistingBackup() throws Exception {
void backupFileIsEqualForNonExistingBackup() throws Exception {
Path originalFile = Path.of(BackupManagerTest.class.getResource("no-autosave.bib").toURI());
assertFalse(BackupManager.backupFileDiffers(originalFile, backupDir));
}

@Test
public void backupFileIsEqual() throws Exception {
void backupFileIsEqual() throws Exception {
// Prepare test: Create backup file on "right" path
Path source = Path.of(BackupManagerTest.class.getResource("no-changes.bib.bak").toURI());
Path target = BackupFileUtil.getPathForNewBackupFileAndCreateDirectory(Path.of(BackupManagerTest.class.getResource("no-changes.bib").toURI()), BackupFileType.BACKUP, backupDir);
Expand All @@ -70,7 +70,7 @@ public void backupFileIsEqual() throws Exception {
}

@Test
public void backupFileDiffers() throws Exception {
void backupFileDiffers() throws Exception {
// Prepare test: Create backup file on "right" path
Path source = Path.of(BackupManagerTest.class.getResource("changes.bib.bak").toURI());
Path target = BackupFileUtil.getPathForNewBackupFileAndCreateDirectory(Path.of(BackupManagerTest.class.getResource("changes.bib").toURI()), BackupFileType.BACKUP, backupDir);
Expand All @@ -81,7 +81,7 @@ public void backupFileDiffers() throws Exception {
}

@Test
public void correctBackupFileDeterminedForMultipleBakFiles() throws Exception {
void correctBackupFileDeterminedForMultipleBakFiles() throws Exception {
Path noChangesBib = Path.of(BackupManagerTest.class.getResource("no-changes.bib").toURI());
Path noChangesBibBak = Path.of(BackupManagerTest.class.getResource("no-changes.bib.bak").toURI());

Expand All @@ -105,7 +105,7 @@ public void correctBackupFileDeterminedForMultipleBakFiles() throws Exception {
}

@Test
public void bakFileWithNewerTimeStampLeadsToDiff() throws Exception {
void bakFileWithNewerTimeStampLeadsToDiff() throws Exception {
Path changesBib = Path.of(BackupManagerTest.class.getResource("changes.bib").toURI());
Path changesBibBak = Path.of(BackupManagerTest.class.getResource("changes.bib.bak").toURI());

Expand All @@ -116,7 +116,7 @@ public void bakFileWithNewerTimeStampLeadsToDiff() throws Exception {
}

@Test
public void bakFileWithOlderTimeStampDoesNotLeadToDiff() throws Exception {
void bakFileWithOlderTimeStampDoesNotLeadToDiff() throws Exception {
Path changesBib = Path.of(BackupManagerTest.class.getResource("changes.bib").toURI());
Path changesBibBak = Path.of(BackupManagerTest.class.getResource("changes.bib.bak").toURI());

Expand All @@ -130,7 +130,7 @@ public void bakFileWithOlderTimeStampDoesNotLeadToDiff() throws Exception {
}

@Test
public void shouldNotCreateABackup(@TempDir Path customDir) throws Exception {
void shouldNotCreateABackup(@TempDir Path customDir) throws Exception {
Path backupDir = customDir.resolve("subBackupDir");
Files.createDirectories(backupDir);

Expand All @@ -156,7 +156,7 @@ public void shouldNotCreateABackup(@TempDir Path customDir) throws Exception {
}

@Test
public void shouldCreateABackup(@TempDir Path customDir) throws Exception {
void shouldCreateABackup(@TempDir Path customDir) throws Exception {
Path backupDir = customDir.resolve("subBackupDir");
Files.createDirectories(backupDir);

Expand Down
24 changes: 12 additions & 12 deletions src/test/java/org/jabref/gui/edit/CopyMoreActionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class CopyMoreActionTest {
class CopyMoreActionTest {

private final DialogService dialogService = spy(DialogService.class);
private final ClipBoardManager clipBoardManager = mock(ClipBoardManager.class);
Expand All @@ -46,7 +46,7 @@ public class CopyMoreActionTest {
private BibEntry entry;

@BeforeEach
public void setUp() {
void setUp() {
String title = "A tale from the trenches";
entry = new BibEntry(StandardEntryType.Misc)
.withField(StandardField.AUTHOR, "Souti Chattopadhyay and Nicholas Nelson and Audrey Au and Natalia Morales and Christopher Sanchez and Rahul Pandita and Anita Sarma")
Expand All @@ -61,7 +61,7 @@ public void setUp() {
}

@Test
public void testExecuteOnFail() {
void testExecuteOnFail() {
when(stateManager.getActiveDatabase()).thenReturn(Optional.empty());
when(stateManager.getSelectedEntries()).thenReturn(FXCollections.emptyObservableList());
copyMoreAction = new CopyMoreAction(StandardActions.COPY_TITLE, dialogService, stateManager, clipBoardManager, preferencesService, abbreviationRepository);
Expand All @@ -72,7 +72,7 @@ public void testExecuteOnFail() {
}

@Test
public void testExecuteCopyTitleWithNoTitle() {
void testExecuteCopyTitleWithNoTitle() {
BibEntry entryWithNoTitle = (BibEntry) entry.clone();
entryWithNoTitle.clearField(StandardField.TITLE);
ObservableList<BibEntry> entriesWithNoTitles = FXCollections.observableArrayList(entryWithNoTitle);
Expand All @@ -88,7 +88,7 @@ public void testExecuteCopyTitleWithNoTitle() {
}

@Test
public void testExecuteCopyTitleOnPartialSuccess() {
void testExecuteCopyTitleOnPartialSuccess() {
BibEntry entryWithNoTitle = (BibEntry) entry.clone();
entryWithNoTitle.clearField(StandardField.TITLE);
ObservableList<BibEntry> mixedEntries = FXCollections.observableArrayList(entryWithNoTitle, entry);
Expand All @@ -106,7 +106,7 @@ public void testExecuteCopyTitleOnPartialSuccess() {
}

@Test
public void testExecuteCopyTitleOnSuccess() {
void testExecuteCopyTitleOnSuccess() {
ObservableList<BibEntry> entriesWithTitles = FXCollections.observableArrayList(entry);
BibDatabaseContext databaseContext = new BibDatabaseContext(new BibDatabase(entriesWithTitles));

Expand All @@ -122,7 +122,7 @@ public void testExecuteCopyTitleOnSuccess() {
}

@Test
public void testExecuteCopyKeyWithNoKey() {
void testExecuteCopyKeyWithNoKey() {
BibEntry entryWithNoKey = (BibEntry) entry.clone();
entryWithNoKey.clearCiteKey();
ObservableList<BibEntry> entriesWithNoKeys = FXCollections.observableArrayList(entryWithNoKey);
Expand All @@ -138,7 +138,7 @@ public void testExecuteCopyKeyWithNoKey() {
}

@Test
public void testExecuteCopyKeyOnPartialSuccess() {
void testExecuteCopyKeyOnPartialSuccess() {
BibEntry entryWithNoKey = (BibEntry) entry.clone();
entryWithNoKey.clearCiteKey();
ObservableList<BibEntry> mixedEntries = FXCollections.observableArrayList(entryWithNoKey, entry);
Expand All @@ -156,7 +156,7 @@ public void testExecuteCopyKeyOnPartialSuccess() {
}

@Test
public void testExecuteCopyKeyOnSuccess() {
void testExecuteCopyKeyOnSuccess() {
ObservableList<BibEntry> entriesWithKeys = FXCollections.observableArrayList(entry);
BibDatabaseContext databaseContext = new BibDatabaseContext(new BibDatabase(entriesWithKeys));

Expand All @@ -172,7 +172,7 @@ public void testExecuteCopyKeyOnSuccess() {
}

@Test
public void testExecuteCopyDoiWithNoDoi() {
void testExecuteCopyDoiWithNoDoi() {
BibEntry entryWithNoDoi = (BibEntry) entry.clone();
entryWithNoDoi.clearField(StandardField.DOI);
ObservableList<BibEntry> entriesWithNoDois = FXCollections.observableArrayList(entryWithNoDoi);
Expand All @@ -188,7 +188,7 @@ public void testExecuteCopyDoiWithNoDoi() {
}

@Test
public void testExecuteCopyDoiOnPartialSuccess() {
void testExecuteCopyDoiOnPartialSuccess() {
BibEntry entryWithNoDoi = (BibEntry) entry.clone();
entryWithNoDoi.clearField(StandardField.DOI);
ObservableList<BibEntry> mixedEntries = FXCollections.observableArrayList(entryWithNoDoi, entry);
Expand All @@ -206,7 +206,7 @@ public void testExecuteCopyDoiOnPartialSuccess() {
}

@Test
public void testExecuteCopyDoiOnSuccess() {
void testExecuteCopyDoiOnSuccess() {
ObservableList<BibEntry> entriesWithDois = FXCollections.observableArrayList(entry);
BibDatabaseContext databaseContext = new BibDatabaseContext(new BibDatabase(entriesWithDois));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;

public class CopyOrMoveFieldContentTabViewModelTest {
class CopyOrMoveFieldContentTabViewModelTest {
CopyOrMoveFieldContentTabViewModel copyOrMoveFieldContentTabViewModel;
BibEntry entryA;
BibEntry entryB;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.mockito.Mockito.mock;

public class EditFieldContentTabViewModelTest {
class EditFieldContentTabViewModelTest {
EditFieldContentViewModel editFieldContentViewModel;
BibEntry entryA;
BibEntry entryB;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ManageKeywordsViewModelTest {
class ManageKeywordsViewModelTest {

private final BibEntryPreferences bibEntryPreferences = mock(BibEntryPreferences.class);
private ManageKeywordsViewModel keywordsViewModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;

public class RenameFieldViewModelTest {
class RenameFieldViewModelTest {
RenameFieldViewModel renameFieldViewModel;
BibEntry entryA;
BibEntry entryB;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ReplaceStringViewModelTest {
class ReplaceStringViewModelTest {

private final LibraryTab libraryTab = mock(LibraryTab.class);
private ReplaceStringViewModel viewModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void testDetermineFieldsToShowWorksForMultipleUsers() {
}

@Test
public void testDifferentiateCaseInUserName() {
void testDifferentiateCaseInUserName() {
UserSpecificCommentField field1 = new UserSpecificCommentField("USER");
UserSpecificCommentField field2 = new UserSpecificCommentField("user");
assertNotEquals(field1, field2, "Two UserSpecificCommentField instances with usernames that differ only by case should be considered different");
Expand Down
Loading

0 comments on commit 4f4ac59

Please sign in to comment.