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: "));
}
}
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());
}
}
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: "));
}
}
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"));
}
}
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"));
}
}
Aggregations