Search in sources :

Example 61 with CheckstyleException

use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.

the class HeaderCheckTest method testNonExistingHeaderFile.

@Test
public void testNonExistingHeaderFile() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(HeaderCheck.class);
    checkConfig.addAttribute("headerFile", getPath("nonExisting.file"));
    try {
        createChecker(checkConfig);
        fail("CheckstyleException is expected");
    } catch (CheckstyleException ex) {
        assertTrue(ex.getMessage().startsWith("cannot initialize module" + " com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck" + " - illegal value "));
        assertTrue(ex.getCause().getCause().getCause().getMessage().startsWith("Unable to find: "));
    }
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 62 with CheckstyleException

use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.

the class RegexpHeaderCheckTest method testEmptyFilename.

@Test
public void testEmptyFilename() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(RegexpHeaderCheck.class);
    checkConfig.addAttribute("headerFile", "");
    try {
        createChecker(checkConfig);
        fail("Checker creation should not succeed with invalid headerFile");
    } catch (CheckstyleException ex) {
        assertEquals("cannot initialize module" + " com.puppycrawl.tools.checkstyle.checks.header.RegexpHeaderCheck" + " - Cannot set property 'headerFile' to '' in" + " module com.puppycrawl.tools.checkstyle.checks.header.RegexpHeaderCheck", ex.getMessage());
    }
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) Test(org.junit.Test)

Example 63 with CheckstyleException

use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.

the class ImportControlCheckTest method testResourceUnableToLoad.

@Test
public void testResourceUnableToLoad() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
    checkConfig.addAttribute("file", getResourcePath("import-control_unknown.xml"));
    try {
        final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
        verify(checkConfig, getPath("InputImportControl.java"), expected);
        fail("Test should fail if exception was not thrown");
    } catch (final CheckstyleException ex) {
        final String message = getCheckstyleExceptionMessage(ex);
        assertTrue(message.startsWith("Unable to find: "));
    }
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) Test(org.junit.Test)

Example 64 with CheckstyleException

use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.

the class CustomImportOrderCheckTest method testSamePackageDepthZero.

@Test
public void testSamePackageDepthZero() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(CustomImportOrderCheck.class);
    checkConfig.addAttribute("sortImportsInGroupAlphabetically", "false");
    checkConfig.addAttribute("separateLineBetweenGroups", "false");
    checkConfig.addAttribute("customImportOrderRules", "SAME_PACKAGE(0)");
    try {
        final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
        verify(checkConfig, getPath("InputCustomImportOrder.java"), expected);
        fail("exception expected");
    } catch (CheckstyleException ex) {
        assertTrue(ex.getMessage().startsWith("cannot initialize module com.puppycrawl.tools.checkstyle.TreeWalker - " + "Cannot set property 'customImportOrderRules' to " + "'SAME_PACKAGE(0)' in module"));
    }
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) Test(org.junit.Test)

Example 65 with CheckstyleException

use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.

the class CustomImportOrderCheckTest method testUnsupportedRule.

@Test
public void testUnsupportedRule() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(CustomImportOrderCheck.class);
    // #AAA##BBBB###CCCC####DDDD
    checkConfig.addAttribute("customImportOrderRules", "SAME_PACKAGE(3)###UNSUPPORTED_RULE");
    checkConfig.addAttribute("sortImportsInGroupAlphabetically", "true");
    try {
        final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
        verify(checkConfig, getPath("InputCustomImportOrder.java"), expected);
        fail("exception expected");
    } catch (CheckstyleException ex) {
        assertTrue(ex.getMessage().startsWith("cannot initialize module com.puppycrawl.tools.checkstyle.TreeWalker - " + "Cannot set property 'customImportOrderRules' to " + "'SAME_PACKAGE(3)###UNSUPPORTED_RULE' in module"));
    }
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) Test(org.junit.Test)

Aggregations

CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)78 Test (org.junit.Test)46 DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)33 File (java.io.File)15 IOException (java.io.IOException)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)9 Properties (java.util.Properties)8 URL (java.net.URL)6 SAXException (org.xml.sax.SAXException)5 PropertiesExpander (com.puppycrawl.tools.checkstyle.PropertiesExpander)4 URI (java.net.URI)4 Checker (com.puppycrawl.tools.checkstyle.Checker)3 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)3 BufferedInputStream (java.io.BufferedInputStream)3 FileInputStream (java.io.FileInputStream)3 Method (java.lang.reflect.Method)3 MalformedURLException (java.net.MalformedURLException)3 ArrayList (java.util.ArrayList)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3