use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.
the class NewlineAtEndOfFileCheckTest method testSetLineSeparatorFailure.
@Test
public void testSetLineSeparatorFailure() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(NewlineAtEndOfFileCheck.class);
checkConfig.addAttribute("lineSeparator", "ct");
try {
createChecker(checkConfig);
fail("exception expected");
} catch (CheckstyleException ex) {
assertTrue(ex.getMessage().startsWith("cannot initialize module com.puppycrawl.tools.checkstyle." + "checks.NewlineAtEndOfFileCheck - " + "Cannot set property 'lineSeparator' to 'ct' in module"));
}
}
use of com.puppycrawl.tools.checkstyle.api.CheckstyleException in project checkstyle by checkstyle.
the class SuppressionCommentFilterTest method testInvalidCheckFormat.
@Test
public void testInvalidCheckFormat() throws Exception {
final DefaultConfiguration filterConfig = createFilterConfig(SuppressionCommentFilter.class);
filterConfig.addAttribute("checkFormat", "e[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 e[l", cause.getMessage());
}
}
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"));
}
}
Aggregations