use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.
the class SuppressWithNearbyCommentFilterTest method testInvalidCheckFormat.
@Test
public void testInvalidCheckFormat() throws Exception {
final DefaultConfiguration filterConfig = createFilterConfig(SuppressWithNearbyCommentFilter.class);
filterConfig.addAttribute("checkFormat", "a[l");
try {
final String[] suppressed = CommonUtils.EMPTY_STRING_ARRAY;
verifySuppressed(filterConfig, suppressed);
} catch (CheckstyleException ex) {
final IllegalArgumentException cause = (IllegalArgumentException) ex.getCause();
assertEquals("unable to parse expanded comment a[l", cause.getMessage());
}
}
use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.
the class PackageNamesLoaderTest method testPackagesWithSaxException.
@Test
@SuppressWarnings("unchecked")
public void testPackagesWithSaxException() throws Exception {
final URLConnection mockConnection = Mockito.mock(URLConnection.class);
when(mockConnection.getInputStream()).thenReturn(new ByteArrayInputStream(EMPTY_BYTE_ARRAY));
final URL url = getMockUrl(mockConnection);
final Enumeration<URL> enumeration = mock(Enumeration.class);
when(enumeration.hasMoreElements()).thenReturn(true);
when(enumeration.nextElement()).thenReturn(url);
final ClassLoader classLoader = mock(ClassLoader.class);
when(classLoader.getResources("checkstyle_packages.xml")).thenReturn(enumeration);
try {
PackageNamesLoader.getPackageNames(classLoader);
fail("CheckstyleException is expected");
} catch (CheckstyleException ex) {
assertTrue(ex.getCause() instanceof SAXException);
}
}
use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.
the class TreeWalkerTest method testProcessWithRecognitionException.
@Test
public void testProcessWithRecognitionException() throws Exception {
final TreeWalker treeWalker = new TreeWalker();
treeWalker.configure(createCheckConfig(TypeNameCheck.class));
final PackageObjectFactory factory = new PackageObjectFactory(new HashSet<>(), Thread.currentThread().getContextClassLoader());
treeWalker.setModuleFactory(factory);
treeWalker.setupChild(createCheckConfig(TypeNameCheck.class));
final File file = temporaryFolder.newFile("file.java");
final List<String> lines = new ArrayList<>();
lines.add(" class a%$# {} ");
try {
treeWalker.processFiltered(file, lines);
} catch (CheckstyleException exception) {
assertTrue(exception.getMessage().contains("TokenStreamRecognitionException occurred during the analysis of file"));
}
}
use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.
the class ConfigurationLoaderTest method testLoadConfigurationFromClassPath.
@Test
public void testLoadConfigurationFromClassPath() {
try {
final DefaultConfiguration config = (DefaultConfiguration) ConfigurationLoader.loadConfiguration("/com/puppycrawl/tools/checkstyle/configs/" + "config_with_ignore.xml", new PropertiesExpander(new Properties()), true);
final Configuration[] children = config.getChildren();
assertEquals(0, children[0].getChildren().length);
} catch (CheckstyleException ex) {
fail("unexpected exception");
}
}
use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.
the class ImportControlLoaderTest method testWrongFormatUri.
@Test
public void testWrongFormatUri() throws Exception {
try {
ImportControlLoader.load(new URI("aaa://" + getPath("import-control_complete.xml")));
fail("exception expected");
} catch (CheckstyleException ex) {
assertSame(MalformedURLException.class, ex.getCause().getClass());
assertEquals("unknown protocol: aaa", ex.getCause().getMessage());
}
}
Aggregations