use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class CheckerTest method testAddFilter.
@Test
public void testAddFilter() {
final Checker checker = new Checker();
final DebugFilter filter = new DebugFilter();
checker.addFilter(filter);
filter.resetFilter();
final SortedSet<Violation> violations = new TreeSet<>();
violations.add(new Violation(1, 0, "a Bundle", "message.key", new Object[] { "arg" }, null, getClass(), null));
checker.fireErrors("Some File Name", violations);
assertWithMessage("Checker.fireErrors() doesn't call filter").that(filter.wasCalled()).isTrue();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class PackageObjectFactoryTest method testCreateObjectFromFullModuleNamesWithAmbiguousException.
@Test
public void testCreateObjectFromFullModuleNamesWithAmbiguousException() {
final String barPackage = BASE_PACKAGE + ".packageobjectfactory.bar";
final String fooPackage = BASE_PACKAGE + ".packageobjectfactory.foo";
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final PackageObjectFactory objectFactory = new PackageObjectFactory(new LinkedHashSet<>(Arrays.asList(barPackage, fooPackage)), classLoader);
final String name = "FooCheck";
try {
objectFactory.createModule(name);
assertWithMessage("Exception is expected").fail();
} catch (CheckstyleException ex) {
final String optionalNames = barPackage + PACKAGE_SEPARATOR + name + STRING_SEPARATOR + fooPackage + PACKAGE_SEPARATOR + name;
final Violation exceptionMessage = new Violation(1, Definitions.CHECKSTYLE_BUNDLE, AMBIGUOUS_MODULE_NAME_EXCEPTION_MESSAGE, new String[] { name, optionalNames }, 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 DeclarationOrderCheckTest method testParents.
@Test
public void testParents() {
final DetailAstImpl parent = new DetailAstImpl();
parent.setType(TokenTypes.STATIC_INIT);
final DetailAstImpl method = new DetailAstImpl();
method.setType(TokenTypes.METHOD_DEF);
parent.setFirstChild(method);
final DetailAstImpl ctor = new DetailAstImpl();
ctor.setType(TokenTypes.CTOR_DEF);
method.setNextSibling(ctor);
final DeclarationOrderCheck check = new DeclarationOrderCheck();
check.visitToken(method);
final SortedSet<Violation> violations1 = check.getViolations();
assertWithMessage("No exception violations expected").that(violations1).isEmpty();
check.visitToken(ctor);
final SortedSet<Violation> violations2 = check.getViolations();
assertWithMessage("No exception violations expected").that(violations2).isEmpty();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class DeclarationOrderCheckTest method testImproperToken.
@Test
public void testImproperToken() {
final DetailAstImpl parent = new DetailAstImpl();
parent.setType(TokenTypes.STATIC_INIT);
final DetailAstImpl array = new DetailAstImpl();
array.setType(TokenTypes.ARRAY_INIT);
parent.setFirstChild(array);
final DeclarationOrderCheck check = new DeclarationOrderCheck();
check.visitToken(array);
final SortedSet<Violation> violations = check.getViolations();
assertWithMessage("No exception violations expected").that(violations).isEmpty();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class NPathComplexityCheckTest method testVisitTokenBeforeExpressionRange.
@Test
public void testVisitTokenBeforeExpressionRange() {
// Create first ast
final DetailAstImpl astIf = mockAST(TokenTypes.LITERAL_IF, "if", 2, 2);
final DetailAstImpl astIfLeftParen = mockAST(TokenTypes.LPAREN, "(", 3, 3);
astIf.addChild(astIfLeftParen);
final DetailAstImpl astIfTrue = mockAST(TokenTypes.LITERAL_TRUE, "true", 3, 3);
astIf.addChild(astIfTrue);
final DetailAstImpl astIfRightParen = mockAST(TokenTypes.RPAREN, ")", 4, 4);
astIf.addChild(astIfRightParen);
// Create ternary ast
final DetailAstImpl astTernary = mockAST(TokenTypes.QUESTION, "?", 1, 1);
final DetailAstImpl astTernaryTrue = mockAST(TokenTypes.LITERAL_TRUE, "true", 1, 2);
astTernary.addChild(astTernaryTrue);
final NPathComplexityCheck npathComplexityCheckObj = new NPathComplexityCheck();
// visiting first ast, set expressionSpatialRange to [2,2 - 4,4]
npathComplexityCheckObj.visitToken(astIf);
final SortedSet<Violation> violations1 = npathComplexityCheckObj.getViolations();
assertWithMessage("No exception violations expected").that(violations1).isEmpty();
// visiting ternary, it lies before expressionSpatialRange
npathComplexityCheckObj.visitToken(astTernary);
final SortedSet<Violation> violations2 = npathComplexityCheckObj.getViolations();
assertWithMessage("No exception violations expected").that(violations2).isEmpty();
}
Aggregations