Skip to content

Commit

Permalink
Merge AB-4 'Migrate from JUnit 4 to JUnit 5'
Browse files Browse the repository at this point in the history
* commit '12ab4e029ec963e5e425a943d4f0452bf15357d1':
  Build.gradle: Remove JUnit 4 libraries
  Checkstyle: Remove exceptions for JUnit 4 annotations
  ClockRule: Migrate to ClockExtension
  UiTest: Migrate StageRule to StageExtension and UiPartRule to UiPartExtension
  TemporaryFolder: Migrate to JUnit 5 TempDir API
  JUnit: Migrate to use JUnit 5 test runner
  JUnit: Upgrade to JUnit 5.4.0
  JUnit Assert: Migrate to JUnit 5 API
  Assert: Use JUnit 5 Assert#assertThrows
  CheckStyle: Allow exceptions for JUnit 5 test annotations
  • Loading branch information
pyokagan committed May 3, 2019
2 parents 8f86a0b + 12ab4e0 commit 259dc30
Show file tree
Hide file tree
Showing 51 changed files with 194 additions and 215 deletions.
10 changes: 8 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ jacocoTestReport {
}
}

test {
useJUnitPlatform()
}

dependencies {
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.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion

testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion
}

shadowJar {
Expand Down
5 changes: 3 additions & 2 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/AppParametersTest.java
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/commons/util/JsonUtilTest.java
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
29 changes: 15 additions & 14 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
@@ -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 @@ -36,16 +35,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 @@ -69,11 +69,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
Original file line number Diff line number Diff line change
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.model.Model;
import seedu.address.model.ModelManager;
Expand All @@ -20,7 +20,7 @@ public class AddCommandIntegrationTest {

private Model model;

@Before
@BeforeEach
public void setUp() {
model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
Expand Down
Original file line number Diff line number Diff line change
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.model.AddressBook;
import seedu.address.model.Model;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package seedu.address.logic.commands;

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 org.junit.Test;
import org.junit.jupiter.api.Test;

public class CommandResultTest {
@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.address.logic.commands;

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.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package seedu.address.logic.commands;

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.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON;
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

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

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
Expand Down
Loading

0 comments on commit 259dc30

Please sign in to comment.