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

Commit

Permalink
Merge 7ca9de4 into 921e61f
Browse files Browse the repository at this point in the history
  • Loading branch information
sijie123 committed Feb 23, 2019
2 parents 921e61f + 7ca9de4 commit 6efd586
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test {

dependencies {
String testFxVersion = '4.0.12-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'
Expand Down
61 changes: 55 additions & 6 deletions src/test/java/seedu/address/testutil/Assert.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
package seedu.address.testutil;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.function.Executable;

/**
* A set of assertion methods useful for writing tests.
*/
public class Assert {

/**
* Asserts that the {@code callable} throws the {@code expected} Exception.
* Asserts that the {@code executable} throws the {@code expectedType} Exception.
* This is a wrapper method that invokes
* {@code Assertions.assertThrows(Class<? extends Throwable>, Executable)}, to maintain
* consistency with our custom
* {@see assertThrowsWithMessage(Class<? extends Throwable>, String, Executable)} method.
*/
public static void assertThrows(Class<? extends Throwable> expectedType, Executable executable) {
Assertions.assertThrows(expectedType, executable);
}

/**
* Asserts that the {@code executable} throws the {@code expectedType} Exception. Otherwise, display
* {@code feedbackMessage} in the error log.
* This is a wrapper method that invokes
* {@code Assertions.assertThrows(Class<? extends Throwable>, Executable}, to maintain
* consistency with our custom
* {@see assertThrowsWithMessage(Class<? extends Throwable>, String, Executable)} method.
*/
public static void assertThrows(Class<? extends Throwable> expected, VoidCallable callable) {
assertThrows(expected, null, callable);
public static void assertThrows(Class<? extends Throwable> expectedType, Executable executable,
String feedbackMessage) {
Assertions.assertThrows(expectedType, executable, feedbackMessage);
}

/**
* Asserts that the {@code callable} throws the {@code expectedException} and the {@code expectedMessage}.
* If there's no need for the verification of the exception's error message, call
* {@code assertThrows(Class<? extends Throwable>, VoidCallable)} instead.
* {@see assertThrows(Class<? extends Throwable>, VoidCallable}
*
* @deprecated use {@see assertThrowsWithMessage(Class<? extends Throwable>, String, Executable)} instead.
*/
@Deprecated
public static void assertThrows(Class<? extends Throwable> expectedException, String expectedMessage,
VoidCallable callable) {
try {
Expand All @@ -42,10 +62,39 @@ public static void assertThrows(Class<? extends Throwable> expectedException, St
"Expected %s to be thrown, but nothing was thrown.", expectedException.getName()));
}


/**
* Asserts that the {@code executable} throws the {@code expectedType} Exception with the
* {@code expectedMessage} message. If there's no need for the verification of the exception's error
* message, call {@code assertThrows(Class<? extends Throwable>, Executable)} instead.
* {@see assertThrows(Class<? extends Throwable>, Executable}}
*/
public static void assertThrowsWithMessage(Class<? extends Throwable> expectedType, String expectedMessage,
Executable executable) {
Throwable thrownException = Assertions.assertThrows(expectedType, executable);
Assertions.assertEquals(expectedMessage, thrownException.getMessage());
}

/**
* Asserts that the {@code executable} throws the {@code expectedType} Exception with the
* {@code expectedMessage} message. Otherwise, display {@code feedbackMessage}} in the error log.
* If there's no need for the verification of the exception's error message, call
* {@code assertThrows(Class<? extends Throwable>, Executable)} instead.
* {@see assertThrows(Class<? extends Throwable>, Executable}}
*/
public static void assertThrowsWithMessage(Class<? extends Throwable> expectedType, String expectedMessage,
Executable executable, String feedbackMessage) {
Throwable thrownException = Assertions.assertThrows(expectedType, executable, feedbackMessage);
Assertions.assertEquals(expectedMessage, thrownException.getMessage(), feedbackMessage);
}

/**
* Represents a function which does not return anything and may throw an exception.
*
* @deprecated use {@code org.junit.jupiter.api.function.Executable} instead
*/
@FunctionalInterface
@Deprecated
public interface VoidCallable {
void call() throws Exception;
}
Expand Down

0 comments on commit 6efd586

Please sign in to comment.