For testing my code I have to create some additional assertion methods (It's for an assignment).
This one checks if an executable throws the expectedType, throws nothing, throws the wrong exceptionMessage or does not have an exceptionMessage.
Here is my code thusfar, but I don't know what to do with the exceptionMessage checks.
public class Test {
public static void assertThrowsMessage(Class<? extends Exception> expectedType,
Executable executable, String exceptionMessage, String message) {
//Throws AssertionError when wrong exception type is thrown
Assertions.assertThrows(
expectedType,
() -> {throw new Exception();},
message
);
//Throws AssertionError when no exception type is thrown
Assertions.assertThrows(
expectedType,
() -> {},
message
);
//Throws AssertionError when no exceptionMessage is thrown
Assertions.assertThrows(
);
//Throws AssertionError when wrong exceptionMessage is thrown
Assertions.assertThrows(
);
}