drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sudheesh Katkam <skat...@maprtech.com>
Subject UserException Matching in Unit Tests
Date Tue, 08 Sep 2015 18:02:23 GMT
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
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message