use of com.puppycrawl.tools.checkstyle.DefaultContext in project checkstyle by checkstyle.
the class AutomaticBeanTest method testContextualizeInvocationTargetException.
@Test
public void testContextualizeInvocationTargetException() {
final TestBean testBean = new TestBean();
final DefaultContext context = new DefaultContext();
context.add("exceptionalMethod", 123.0f);
try {
testBean.contextualize(context);
assertWithMessage("InvocationTargetException is expected").fail();
} catch (CheckstyleException ex) {
final String expected = "Cannot set property ";
assertWithMessage("Invalid exception cause, should be: ReflectiveOperationException").that(ex).hasCauseThat().isInstanceOf(ReflectiveOperationException.class);
assertWithMessage("Invalid exception message, should start with: " + expected).that(ex).hasMessageThat().startsWith(expected);
}
}
use of com.puppycrawl.tools.checkstyle.DefaultContext in project contribution by checkstyle.
the class ClassFileSetCheck method finishLocalSetup.
/**
* @see com.puppycrawl.tools.checkstyle.api.Configurable
*/
public void finishLocalSetup() {
DefaultContext checkContext = new DefaultContext();
checkContext.add("classLoader", mClassLoader);
checkContext.add("messageMap", mMessageMap);
checkContext.add("severity", getSeverity());
mChildContext = checkContext;
}
use of com.puppycrawl.tools.checkstyle.DefaultContext in project checkstyle by checkstyle.
the class AutomaticBeanTest method testContextualizeConversionException.
@Test
public void testContextualizeConversionException() {
final TestBean testBean = new TestBean();
final DefaultContext context = new DefaultContext();
context.add("val", "some string");
try {
testBean.contextualize(context);
assertWithMessage("InvocationTargetException is expected").fail();
} catch (CheckstyleException ex) {
final String expected = "illegal value ";
assertWithMessage("Invalid exception cause, should be: ConversionException").that(ex).hasCauseThat().isInstanceOf(ConversionException.class);
assertWithMessage("Invalid exception message, should start with: " + expected).that(ex).hasMessageThat().startsWith(expected);
}
}
Aggregations