You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by Sudheesh Katkam <sk...@maprtech.com> on 2015/09/08 20:02:23 UTC

UserException Matching in Unit Tests

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