use of com.puppycrawl.tools.checkstyle.api.Configuration in project checkstyle by checkstyle.
the class CheckerTest method testSetupChildListener.
@Test
public void testSetupChildListener() throws Exception {
final Checker checker = new Checker();
final PackageObjectFactory factory = new PackageObjectFactory(new HashSet<>(), Thread.currentThread().getContextClassLoader());
checker.setModuleFactory(factory);
final Configuration config = new DefaultConfiguration(DebugAuditAdapter.class.getCanonicalName());
checker.setupChild(config);
}
use of com.puppycrawl.tools.checkstyle.api.Configuration in project checkstyle by checkstyle.
the class ConfigurationLoaderTest method testLoadConfigurationDeprecated.
@Test
public void testLoadConfigurationDeprecated() {
try {
@SuppressWarnings("deprecation") final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration(new FileInputStream(getConfigPath("config_with_ignore.xml")), new PropertiesExpander(new Properties()), true);
final Configuration[] children = config.getChildren();
assertEquals(0, children[0].getChildren().length);
} catch (CheckstyleException | FileNotFoundException ex) {
fail("unexpected exception");
}
}
use of com.puppycrawl.tools.checkstyle.api.Configuration in project checkstyle by checkstyle.
the class ConfigurationLoaderTest method testCheckstyleChecks.
@Test
public void testCheckstyleChecks() throws Exception {
final Properties props = new Properties();
props.setProperty("checkstyle.basedir", "basedir");
final DefaultConfiguration config = (DefaultConfiguration) loadConfiguration("checkstyle_checks.xml", props);
//verify the root, and property substitution
final Properties atts = new Properties();
atts.setProperty("tabWidth", "4");
atts.setProperty("basedir", "basedir");
verifyConfigNode(config, "Checker", 3, atts);
//verify children
final Configuration[] children = config.getChildren();
atts.clear();
verifyConfigNode((DefaultConfiguration) children[1], "JavadocPackage", 0, atts);
verifyConfigNode((DefaultConfiguration) children[2], "Translation", 0, atts);
atts.setProperty("testName", "testValue");
verifyConfigNode((DefaultConfiguration) children[0], "TreeWalker", 8, atts);
//verify TreeWalker's first, last, NoWhitespaceAfterCheck
final Configuration[] grandchildren = children[0].getChildren();
atts.clear();
verifyConfigNode((DefaultConfiguration) grandchildren[0], "AvoidStarImport", 0, atts);
atts.setProperty("format", "System.out.println");
verifyConfigNode((DefaultConfiguration) grandchildren[grandchildren.length - 1], "GenericIllegalRegexp", 0, atts);
atts.clear();
atts.setProperty("tokens", "DOT");
atts.setProperty("allowLineBreaks", "true");
verifyConfigNode((DefaultConfiguration) grandchildren[6], "NoWhitespaceAfter", 0, atts);
}
use of com.puppycrawl.tools.checkstyle.api.Configuration in project checkstyle by checkstyle.
the class ConfigurationLoaderTest method testLoadConfigurationWrongUrl.
@Test
public void testLoadConfigurationWrongUrl() {
try {
final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration(";config_with_ignore.xml", new PropertiesExpander(new Properties()), true);
final Configuration[] children = config.getChildren();
assertEquals(0, children[0].getChildren().length);
fail("Exception is expected");
} catch (CheckstyleException ex) {
assertEquals("Unable to find: ;config_with_ignore.xml", ex.getMessage());
}
}
use of com.puppycrawl.tools.checkstyle.api.Configuration in project checkstyle by checkstyle.
the class ConfigurationLoaderTest method testCustomMessages.
@Test
public void testCustomMessages() throws CheckstyleException {
final Properties props = new Properties();
props.setProperty("checkstyle.basedir", "basedir");
final DefaultConfiguration config = (DefaultConfiguration) loadConfiguration("custom_messages.xml", props);
final Configuration[] children = config.getChildren();
final Configuration[] grandchildren = children[0].getChildren();
assertTrue(grandchildren[0].getMessages().containsKey("name.invalidPattern"));
}
Aggregations