Search in sources :

Example 6 with ConversionException

use of org.apache.commons.beanutils.ConversionException in project contribution by checkstyle.

the class AbstractUsageCheck method setIgnoreFormat.

/**
 * Set the ignore format to the specified regular expression.
 * @param aFormat a <code>String</code> value
 * @throws ConversionException unable to parse aFormat
 */
public void setIgnoreFormat(String aFormat) throws ConversionException {
    try {
        mRegexp = Utils.getPattern(aFormat);
        mIgnoreFormat = aFormat;
    } catch (PatternSyntaxException e) {
        throw new ConversionException("unable to parse " + aFormat, e);
    }
}
Also used : ConversionException(org.apache.commons.beanutils.ConversionException) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 7 with ConversionException

use of org.apache.commons.beanutils.ConversionException 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

ConversionException (org.apache.commons.beanutils.ConversionException)7 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 DynaProperty (org.apache.commons.beanutils.DynaProperty)2 DefaultContext (com.puppycrawl.tools.checkstyle.DefaultContext)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Matcher (java.util.regex.Matcher)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 KeyValPair (org.apache.apex.malhar.lib.util.KeyValPair)1 DateConverter (org.apache.commons.beanutils.converters.DateConverter)1 DateTimeConverter (org.apache.commons.beanutils.converters.DateTimeConverter)1 Test (org.junit.jupiter.api.Test)1