use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.
the class MainTest method testLoadPropertiesIoException.
@Test
public void testLoadPropertiesIoException() throws Exception {
final Class<?>[] param = new Class<?>[1];
param[0] = File.class;
final Method method = Main.class.getDeclaredMethod("loadProperties", param);
method.setAccessible(true);
try {
if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).startsWith("windows")) {
// https://support.microsoft.com/en-us/kb/177506 but this only for NTFS
// WindowsServer 2012 use Resilient File System (ReFS), so any name is ok
final File file = new File(File.separator + ":invalid");
if (file.exists()) {
file.delete();
}
method.invoke(null, new File(file.getAbsolutePath()));
} else {
method.invoke(null, new File(File.separator + "\0:invalid"));
}
fail("Exception was expected");
} catch (InvocationTargetException ex) {
assertTrue(ex.getCause() instanceof CheckstyleException);
// We do separate validation for message as in Windows
// disk drive letter appear in message,
// so we skip that drive letter for compatibility issues
assertTrue(ex.getCause().getMessage().startsWith("Unable to load properties from file '"));
assertTrue(ex.getCause().getMessage().endsWith(":invalid'."));
}
}
use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.
the class EmptyBlockCheckTest method testInvalidOption.
@Test
public void testInvalidOption() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(EmptyBlockCheck.class);
checkConfig.addAttribute("option", "invalid_option");
try {
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputSemantic.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"));
}
}
use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.
the class HeaderCheckTest method testNoHeader.
@Test
public void testNoHeader() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(HeaderCheck.class);
try {
createChecker(checkConfig);
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputRegexpHeader1.java"), expected);
} catch (CheckstyleException ex) {
// Exception is not expected
fail("Exception is not expected");
}
}
use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.
the class HeaderCheckTest method testEmptyFilename.
@Test
public void testEmptyFilename() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(HeaderCheck.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.HeaderCheck" + " - Cannot set property 'headerFile' to '' in module" + " com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck", ex.getMessage());
}
}
use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.
the class HeaderCheckTest method testWhitespaceHeader.
@Test
public void testWhitespaceHeader() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(HeaderCheck.class);
checkConfig.addAttribute("header", "\n \n");
try {
createChecker(checkConfig);
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputRegexpHeader1.java"), expected);
} catch (CheckstyleException ex) {
// Exception is not expected
fail("Exception is not expected");
}
}
Aggregations