I have the following code (the part that throws the exception is obviously part of a class but I only put the relevant lines).
if (found==null)
{
log.warn("Got request from source IP - " + ip + " which is not in the env - not answering");
throw new SourceHostUnknownException("This command is only supported from within the Environment");
}
@Test
public void testSecurityResult_whenRVERegex_assertexception()
{
Throwable exception = Assertions.assertThrows(SourceHostUnknownException.class, () -> {
SecurityResult result = secSvc.validateRequest(req);
});
String expectedMessage = "This command is only supported from within the Environment";
String actualMessage = exception.getMessage();
Assertions.assertEquals(expectedMessage,actualMessage);
}
My goal is to test if the exception was thrown, but when I'm trying to get the message from the exception, the value is null- meaning, the exception doesn't contain the message.
What am I doing wrong?