Search in sources :

Example 31 with CheckstyleException

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

the class ImportOrderCheckTest method testGroupWithSlashes.

@Test
public void testGroupWithSlashes() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(ImportOrderCheck.class);
    checkConfig.addAttribute("groups", "/^javax");
    try {
        final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
        verify(checkConfig, getPath("InputImportOrder.java"), expected);
        fail("exception expected");
    } catch (CheckstyleException ex) {
        assertTrue(ex.getMessage().startsWith("cannot initialize module com.puppycrawl.tools.checkstyle.TreeWalker - " + "Cannot set property 'groups' to '/^javax' in module"));
    }
}
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 32 with CheckstyleException

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

the class ImportControlCheckTest method testUrlInFilePropertyUnableToLoad.

@Test
public void testUrlInFilePropertyUnableToLoad() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
    checkConfig.addAttribute("file", "https://UnableToLoadThisURL");
    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 load "));
    }
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) Test(org.junit.Test)

Example 33 with CheckstyleException

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

the class ImportControlCheckTest method testUrlUnableToLoad.

@Test
public void testUrlUnableToLoad() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
    checkConfig.addAttribute("url", "https://UnableToLoadThisURL");
    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 load "));
    }
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) Test(org.junit.Test)

Example 34 with CheckstyleException

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

the class ImportControlCheckTest method testUnknown.

@Test
public void testUnknown() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
    checkConfig.addAttribute("file", "unknown-file");
    try {
        final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
        verify(checkConfig, getPath("InputImportControl.java"), expected);
        fail("Test should fail if exception was not thrown");
    } catch (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 35 with CheckstyleException

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

the class ImportOrderCheckTest method testInvalidOption.

@Test
public void testInvalidOption() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(ImportOrderCheck.class);
    checkConfig.addAttribute("option", "invalid_option");
    try {
        final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
        verify(checkConfig, getPath("InputImportOrder_Top.java"), expected);
        fail("exception expected");
    } catch (CheckstyleException ex) {
        assertTrue(ex.getMessage().startsWith("cannot initialize module com.puppycrawl.tools.checkstyle.TreeWalker - " + "Cannot set property 'option' to 'invalid_option' in module"));
    }
}
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)

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