use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SuppressWarningsHolderTest method createAuditEvent.
private static AuditEvent createAuditEvent(String moduleId, int line, int column) {
final Checker source = new Checker();
final Violation violation = new Violation(line, column, null, null, null, moduleId, MemberNameCheck.class, "violation");
return new AuditEvent(source, "filename", violation);
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class NPathComplexityCheckTest method testDefaultHooks.
@Test
public void testDefaultHooks() {
final NPathComplexityCheck npathComplexityCheckObj = new NPathComplexityCheck();
final DetailAstImpl ast = new DetailAstImpl();
ast.initialize(new CommonToken(TokenTypes.INTERFACE_DEF, "interface"));
npathComplexityCheckObj.visitToken(ast);
final SortedSet<Violation> violations1 = npathComplexityCheckObj.getViolations();
assertWithMessage("No exception violations expected").that(violations1).isEmpty();
npathComplexityCheckObj.leaveToken(ast);
final SortedSet<Violation> violations2 = npathComplexityCheckObj.getViolations();
assertWithMessage("No exception violations expected").that(violations2).isEmpty();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class PackageObjectFactoryTest method testCreateModuleWithNonExistName.
@Test
public void testCreateModuleWithNonExistName() {
final String[] names = { "NonExistClassOne", "NonExistClassTwo" };
for (String name : names) {
try {
factory.createModule(name);
assertWithMessage("Exception is expected").fail();
} catch (CheckstyleException ex) {
final String attemptedNames = BASE_PACKAGE + PACKAGE_SEPARATOR + name + STRING_SEPARATOR + name + CHECK_SUFFIX + STRING_SEPARATOR + BASE_PACKAGE + PACKAGE_SEPARATOR + name + CHECK_SUFFIX;
final Violation exceptionMessage = new Violation(1, Definitions.CHECKSTYLE_BUNDLE, UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE, new String[] { name, attemptedNames }, null, factory.getClass(), null);
assertWithMessage("Invalid exception message").that(ex.getMessage()).isEqualTo(exceptionMessage.getViolation());
}
}
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class PackageObjectFactoryTest method testCreateObjectFromFullModuleNamesWithCantInstantiateException.
@Test
public void testCreateObjectFromFullModuleNamesWithCantInstantiateException() {
final String package1 = BASE_PACKAGE + ".wrong1";
final String package2 = BASE_PACKAGE + ".wrong2";
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final PackageObjectFactory objectFactory = new PackageObjectFactory(new LinkedHashSet<>(Arrays.asList(package1, package2)), classLoader);
final String name = "FooCheck";
final String checkName = name + CHECK_SUFFIX;
try {
objectFactory.createModule(name);
assertWithMessage("Exception is expected").fail();
} catch (CheckstyleException ex) {
final String attemptedNames = package1 + PACKAGE_SEPARATOR + name + STRING_SEPARATOR + package2 + PACKAGE_SEPARATOR + name + STRING_SEPARATOR + checkName + STRING_SEPARATOR + package1 + PACKAGE_SEPARATOR + checkName + STRING_SEPARATOR + package2 + PACKAGE_SEPARATOR + checkName;
final Violation exceptionMessage = new Violation(1, Definitions.CHECKSTYLE_BUNDLE, UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE, new String[] { name, attemptedNames }, null, getClass(), null);
assertWithMessage("Invalid exception message").that(ex.getMessage()).isEqualTo(exceptionMessage.getViolation());
}
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class XpathFileGeneratorAstFilterTest method testNoXpathQuery.
@Test
public void testNoXpathQuery() throws Exception {
final Violation violation = new Violation(10, 10, TokenTypes.LCURLY, "messages.properties", null, null, SeverityLevel.ERROR, null, LeftCurlyCheck.class, null);
final TreeWalkerAuditEvent event = createTreeWalkerAuditEvent("InputXpathFileGeneratorAstFilter.java", violation);
final XpathFileGeneratorAstFilter filter = new XpathFileGeneratorAstFilter();
assertWithMessage("filter accepted").that(filter.accept(event)).isTrue();
final AuditEvent auditEvent = new AuditEvent(this, getPath("InputXpathFileGeneratorAstFilter.java"), violation);
assertWithMessage("expected null").that(XpathFileGeneratorAstFilter.findCorrespondingXpathQuery(auditEvent)).isNull();
}
Aggregations