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

Commit

Permalink
Remove use of junit.framework package
Browse files Browse the repository at this point in the history
There are certain places in our code base where we use classes from the
`junit.framework` package.

The `junit.framework` package exists for backwards-compatibility with
JUnit 3[1]. We are not a legacy code base stuck on JUnit 3, thus we
should use the JUnit 4 API.

Replace uses of the `junit.framework` package with the JUnit 4 API
equivalents, namely:

 * Rather than using `junit.framework.TestCase.assertNotNull`, use the
   JUnit 4 API's `org.junit.Assert.assertNotNull`[2].

 * Rather than using `junit.framework.AssertionFailedError`, use
   `java.lang.AssertionError` instead, since that is what is thrown by
   the JUnit 4 API on assertion failures.

[1] From the package-info.java of `junit.framework` at
    https://github.com/junit-team/junit4/blob/02c328028b4d32c15bbf0becc9838e54ecbafcbf/src/main/java/junit/framework/package-info.java#L2

    "Provides JUnit v3.x core classes"

[2] https://stackoverflow.com/a/291074

    "JUnit 3.X: junit.framework.Assert

     JUnit 4.X: org.junit.Assert

     Prefer the newest one, especially when running JDK5 and higher with
     annotation support."
  • Loading branch information
pyokagan committed Aug 6, 2018
1 parent c348aa9 commit d7b3f1c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.address.storage;

import static junit.framework.TestCase.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

Expand Down
6 changes: 2 additions & 4 deletions src/test/java/seedu/address/testutil/Assert.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package seedu.address.testutil;

import junit.framework.AssertionFailedError;

/**
* A set of assertion methods useful for writing tests.
*/
Expand Down Expand Up @@ -37,10 +35,10 @@ public static void assertThrows(Class<? extends Throwable> expectedException, St
return;
}

throw new AssertionFailedError(errorMessage);
throw new AssertionError(errorMessage);
}

throw new AssertionFailedError(String.format(
throw new AssertionError(String.format(
"Expected %s to be thrown, but nothing was thrown.", expectedException.getName()));
}

Expand Down

0 comments on commit d7b3f1c

Please sign in to comment.