@Override protected void finishLocalSetup() throws CheckstyleException { final Locale locale = new Locale(localeLanguage, localeCountry); LocalizedMessage.setLocale(locale); if (moduleFactory == null) { if (moduleClassLoader == null) { throw new CheckstyleException( "if no custom moduleFactory is set, " + "moduleClassLoader must be specified"); } final Set<String> packageNames = PackageNamesLoader .getPackageNames(moduleClassLoader); moduleFactory = new PackageObjectFactory(packageNames, moduleClassLoader); } final DefaultContext context = new DefaultContext(); context.add("charset", charset); context.add("classLoader", classLoader); context.add("moduleFactory", moduleFactory); context.add("severity", severity.getName()); context.add("basedir", basedir); childContext = context; }
@Test public void testContextualizeInvocationTargetException() { final TestBean testBean = new TestBean(); final DefaultContext context = new DefaultContext(); context.add("exceptionalMethod", 123.0f); try { testBean.contextualize(context); fail("InvocationTargetException is expected"); } catch (CheckstyleException ex) { final String expected = "Cannot set property "; assertTrue("Invalid exception cause, should be: InvocationTargetException", ex.getCause() instanceof InvocationTargetException); assertTrue("Invalid exception message, should start with: " + expected, ex.getMessage().startsWith(expected)); } }
@Test public void testContextualizeConversionException() { final TestBean testBean = new TestBean(); final DefaultContext context = new DefaultContext(); context.add("val", "some string"); try { testBean.contextualize(context); fail("InvocationTargetException is expected"); } catch (CheckstyleException ex) { final String expected = "illegal value "; assertTrue("Invalid exception cause, should be: ConversionException", ex.getCause() instanceof ConversionException); assertTrue("Invalid exception message, should start with: " + expected, ex.getMessage().startsWith(expected)); } }
@Override public void finishLocalSetup() { DefaultContext context = new DefaultContext(); context.add("classLoader", this.classLoader); context.add("severity", getSeverity()); context.add("tabWidth", String.valueOf(this.tabWidth)); context.add("moduleFactory", this.moduleFactory); Properties properties = new Properties(); properties.put("headerType", this.headerType); properties.put("headerCopyrightPattern", this.headerCopyrightPattern); this.checks = new SpringConfigurationLoader(context, this.moduleFactory) .load(new PropertiesExpander(properties)); }
@Override protected void finishLocalSetup() throws CheckstyleException { final Locale locale = new Locale(localeLanguage, localeCountry); LocalizedMessage.setLocale(locale); if (moduleFactory == null) { if (moduleClassLoader == null) { throw new CheckstyleException( "if no custom moduleFactory is set, " + "moduleClassLoader must be specified"); } final Set<String> packageNames = PackageNamesLoader .getPackageNames(moduleClassLoader); moduleFactory = new PackageObjectFactory(packageNames, moduleClassLoader); } final DefaultContext context = new DefaultContext(); context.add("charset", charset); context.add("classLoader", classLoader); context.add("moduleFactory", moduleFactory); context.add("severity", severity.getName()); context.add("basedir", basedir); childContext = context; }