Hey y’all,
I have added a ExpectedException rule and a UserExceptionMatcher to the unit
test framework. This is useful for unit tests that expect UserExceptions (with
expected type and message). The thrownException variable should be accessible
from all test classes. Sample usage:
@Test
public void checkUserExceptionType() throws Exception {
// UserException(ErrorType expectedType)
thrownException.expect(new UserExceptionMatcher(VALIDATION));
test(String.format("ALTER session SET `%s` = '%s';",
ExecConstants.SLICE_TARGET, "fail"));
}
@Test
public void checkUserExceptionTypeAndMessage() throws Exception {
// UserException(ErrorType expectedType, String expectedMessage)
thrownException.expect(new UserExceptionMatcher(VALIDATION, "Option
planner.slice_target must be of type LONG but you tried to set to STRING."));
test(String.format("ALTER session SET `%s` = '%s';",
ExecConstants.SLICE_TARGET, "fail"));
}
Note that the expected message should be contained in the actual message (i.e.
actualMessage.contains(expectedMessage) comparison and not
actualMessage.equals(expectedMessage) comparison).
Thank you,
Sudheesh