Search in sources :

Example 1 with DefaultContext

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);
    }
}
Also used : DefaultContext(com.puppycrawl.tools.checkstyle.DefaultContext) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultContext

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;
}
Also used : DefaultContext(com.puppycrawl.tools.checkstyle.DefaultContext)

Example 3 with DefaultContext

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);
    }
}
Also used : ConversionException(org.apache.commons.beanutils.ConversionException) DefaultContext(com.puppycrawl.tools.checkstyle.DefaultContext) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultContext (com.puppycrawl.tools.checkstyle.DefaultContext)3 Test (org.junit.jupiter.api.Test)2 ConversionException (org.apache.commons.beanutils.ConversionException)1