Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Commit

Permalink
Migrate from JUnit 4 to JUnit 5 (#959)
Browse files Browse the repository at this point in the history
Finish the migration from JUnit4 to JUnit5 started by 435849c (Gradle:
upgrade to JUnit5, 2018-03-23).

  [1/10] CheckStyle: Allow exceptions for JUnit 5 test annotations
  [2/10] Assert: Use JUnit 5 Assert#assertThrows
  [3/10] JUnit Assert: Migrate to JUnit 5 API
  [4/10] JUnit: Upgrade to JUnit 5.4.0
  [5/10] JUnit: Migrate to use JUnit 5 test runner
  [6/10] TemporaryFolder: Migrate to JUnit 5 TempDir API
  [7/10] UiTest: Migrate StageRule to StageExtension and UiPartRule to UiPartExtension
  [8/10] ClockRule: Migrate to ClockExtension
  [9/10] Checkstyle: Remove exceptions for JUnit 4 annotations
  [10/10] Build.gradle: Remove JUnit 4 libraries
  • Loading branch information
pyokagan committed Apr 30, 2019
2 parents 4808530 + cc73829 commit 12ab4e0
Show file tree
Hide file tree
Showing 84 changed files with 343 additions and 397 deletions.
4 changes: 1 addition & 3 deletions build.gradle
Expand Up @@ -43,18 +43,16 @@ test {

dependencies {
String testFxVersion = '4.0.15-alpha'
String jUnitVersion = '5.1.0'
String jUnitVersion = '5.4.0'

implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.7.0'
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.7.4'

testImplementation group: 'junit', name: 'junit', version: '4.12'
testImplementation group: 'org.testfx', name: 'testfx-core', version: testFxVersion

testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion

testRuntimeOnly group: 'org.testfx', name: 'openjfx-monocle', version: '8u76-b04'
testRuntimeOnly group:'org.junit.vintage', name:'junit-vintage-engine', version: jUnitVersion
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion
}

Expand Down
5 changes: 3 additions & 2 deletions config/checkstyle/checkstyle.xml
Expand Up @@ -229,6 +229,7 @@
<module name="VisibilityModifier">
<property name="protectedAllowed" value="true"/>
<property name="allowPublicFinalFields" value="true"/>
<property name="ignoreAnnotationCanonicalNames" value="RegisterExtension, TempDir"/>
</module>

<!--
Expand Down Expand Up @@ -390,7 +391,7 @@
Single line of code methods are often due to refactor for readability.
-->
<property name="minLineCount" value="1"/>
<property name="allowedAnnotations" value="Override, Test, Before, BeforeClass, After, AfterClass, Subscribe"/>
<property name="allowedAnnotations" value="Override, Test, BeforeAll, BeforeEach, AfterAll, AfterEach, Subscribe"/>
<property name="scope" value="public"/>
<property name="allowUndeclaredRTE" value="true"/>
<property name="allowThrowsTagsForSubclasses" value="true"/>
Expand All @@ -407,7 +408,7 @@
We define methods that have more than 3 lines of code as non-trivial.
-->
<property name="minLineCount" value="3"/>
<property name="allowedAnnotations" value="Override, Test, Before, BeforeClass, After, AfterClass, Subscribe"/>
<property name="allowedAnnotations" value="Override, Test, BeforeAll, BeforeEach, AfterAll, AfterEach, Subscribe"/>
<property name="scope" value="private"/>
<property name="allowUndeclaredRTE" value="true"/>
<property name="allowThrowsTagsForSubclasses" value="true"/>
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/guitests/guihandles/StageHandle.java
@@ -1,7 +1,7 @@
package guitests.guihandles;

import static java.util.Objects.requireNonNull;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertFalse;

import java.util.Optional;
import java.util.logging.Logger;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/AppParametersTest.java
@@ -1,14 +1,14 @@
package seedu.address;

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

import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import javafx.application.Application;

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/seedu/address/commons/core/ConfigTest.java
@@ -1,10 +1,10 @@
package seedu.address.commons.core;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ConfigTest {

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/seedu/address/commons/core/VersionTest.java
@@ -1,10 +1,10 @@
package seedu.address.commons.core;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.Assert.assertThrows;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class VersionTest {

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/seedu/address/commons/core/index/IndexTest.java
@@ -1,11 +1,11 @@
package seedu.address.commons.core.index;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.Assert.assertThrows;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class IndexTest {

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/commons/util/AppUtilTest.java
@@ -1,9 +1,9 @@
package seedu.address.commons.util;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static seedu.address.testutil.Assert.assertThrows;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class AppUtilTest {

Expand Down
@@ -1,7 +1,7 @@
package seedu.address.commons.util;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
import static seedu.address.testutil.Assert.assertThrows;

Expand All @@ -10,7 +10,7 @@
import java.util.Collections;
import java.util.List;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class CollectionUtilTest {
@Test
Expand Down
16 changes: 7 additions & 9 deletions src/test/java/seedu/address/commons/util/ConfigUtilTest.java
@@ -1,7 +1,7 @@
package seedu.address.commons.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static seedu.address.testutil.Assert.assertThrows;

import java.io.IOException;
Expand All @@ -10,9 +10,8 @@
import java.util.Optional;
import java.util.logging.Level;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import seedu.address.commons.core.Config;
import seedu.address.commons.exceptions.DataConversionException;
Expand All @@ -21,9 +20,8 @@ public class ConfigUtilTest {

private static final Path TEST_DATA_FOLDER = Paths.get("src", "test", "data", "ConfigUtilTest");


@Rule
public TemporaryFolder testFolder = new TemporaryFolder();
@TempDir
public Path tempDir;

@Test
public void read_null_throwsNullPointerException() {
Expand Down Expand Up @@ -89,7 +87,7 @@ public void save_nullFile_throwsNullPointerException() {
public void saveConfig_allInOrder_success() throws DataConversionException, IOException {
Config original = getTypicalConfig();

Path configFilePath = testFolder.getRoot().toPath().resolve("TempConfig.json");
Path configFilePath = tempDir.resolve("TempConfig.json");

//Try writing when the file doesn't exist
ConfigUtil.saveConfig(original, configFilePath);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/seedu/address/commons/util/FileUtilTest.java
@@ -1,10 +1,10 @@
package seedu.address.commons.util;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.Assert.assertThrows;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class FileUtilTest {

Expand Down
@@ -1,8 +1,8 @@
package seedu.address.commons.util;

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

import org.junit.Test;
import org.junit.jupiter.api.Test;

import javafx.beans.InvalidationListener;
import javafx.beans.property.SimpleObjectProperty;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/commons/util/JsonUtilTest.java
@@ -1,11 +1,11 @@
package seedu.address.commons.util;

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

import java.io.IOException;
import java.nio.file.Path;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import seedu.address.testutil.SerializableTestClass;
import seedu.address.testutil.TestUtil;
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/seedu/address/commons/util/StringUtilTest.java
@@ -1,12 +1,12 @@
package seedu.address.commons.util;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.Assert.assertThrows;

import java.io.FileNotFoundException;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class StringUtilTest {

Expand Down
14 changes: 7 additions & 7 deletions src/test/java/seedu/address/logic/CommandHistoryTest.java
@@ -1,19 +1,19 @@
package seedu.address.logic;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
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 java.util.Arrays;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class CommandHistoryTest {
private CommandHistory history;

@Before
@BeforeEach
public void setUp() {
history = new CommandHistory();
}
Expand Down
29 changes: 15 additions & 14 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
@@ -1,6 +1,6 @@
package seedu.address.logic;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX;
import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND;
import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_AMY;
Expand All @@ -13,10 +13,9 @@
import java.io.IOException;
import java.nio.file.Path;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.CommandResult;
Expand All @@ -37,16 +36,17 @@
public class LogicManagerTest {
private static final IOException DUMMY_IO_EXCEPTION = new IOException("dummy exception");

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@TempDir
public Path temporaryFolder;

private Model model = new ModelManager();
private Logic logic;

@Before
public void setUp() throws Exception {
JsonAddressBookStorage addressBookStorage = new JsonAddressBookStorage(temporaryFolder.newFile().toPath());
JsonUserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(temporaryFolder.newFile().toPath());
@BeforeEach
public void setUp() {
JsonAddressBookStorage addressBookStorage =
new JsonAddressBookStorage(temporaryFolder.resolve("addressBook.json"));
JsonUserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(temporaryFolder.resolve("userPrefs.json"));
StorageManager storage = new StorageManager(addressBookStorage, userPrefsStorage);
logic = new LogicManager(model, storage);
}
Expand All @@ -73,11 +73,12 @@ public void execute_validCommand_success() throws Exception {
}

@Test
public void execute_storageThrowsIoException_throwsCommandException() throws Exception {
public void execute_storageThrowsIoException_throwsCommandException() {
// Setup LogicManager with JsonAddressBookIoExceptionThrowingStub
JsonAddressBookStorage addressBookStorage =
new JsonAddressBookIoExceptionThrowingStub(temporaryFolder.newFile().toPath());
JsonUserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(temporaryFolder.newFile().toPath());
new JsonAddressBookIoExceptionThrowingStub(temporaryFolder.resolve("ioExceptionAddressBook.json"));
JsonUserPrefsStorage userPrefsStorage =
new JsonUserPrefsStorage(temporaryFolder.resolve("ioExceptionUserPrefs.json"));
StorageManager storage = new StorageManager(addressBookStorage, userPrefsStorage);
logic = new LogicManager(model, storage);

Expand Down
Expand Up @@ -4,8 +4,8 @@
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import seedu.address.logic.CommandHistory;
import seedu.address.model.Model;
Expand All @@ -22,7 +22,7 @@ public class AddCommandIntegrationTest {
private Model model;
private CommandHistory commandHistory = new CommandHistory();

@Before
@BeforeEach
public void setUp() {
model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
}
Expand Down
@@ -1,17 +1,17 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.Assert.assertThrows;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.function.Predicate;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import javafx.beans.property.ReadOnlyProperty;
import javafx.collections.ObservableList;
Expand Down
Expand Up @@ -3,7 +3,7 @@
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import seedu.address.logic.CommandHistory;
import seedu.address.model.AddressBook;
Expand Down

0 comments on commit 12ab4e0

Please sign in to comment.