use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class JavadocTagInfoTest method testVersions.
@Test
public void testVersions() {
final DetailAstImpl ast = new DetailAstImpl();
final int[] validTypes = { TokenTypes.PACKAGE_DEF, TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF, TokenTypes.ENUM_DEF, TokenTypes.ANNOTATION_DEF };
for (int type : validTypes) {
ast.setType(type);
assertWithMessage("Invalid ast type for current tag: " + ast.getType()).that(JavadocTagInfo.VERSION.isValidOn(ast)).isTrue();
}
ast.setType(TokenTypes.LAMBDA);
assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.VERSION.isValidOn(ast)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class ImportOrderCheckTest method testVisitTokenSwitchReflection.
/**
* This test requires reflection to insert an unsupported option in the check to cover the
* exception that gets thrown when a unsupported option is used. The field has a value by
* default and the setter for the property will throw it's own exception when an unsupported
* option is given, so there is no other way to cover this code.
*/
@Test
public void testVisitTokenSwitchReflection() {
// Create mock ast
final DetailAstImpl astImport = mockAST(TokenTypes.IMPORT, "import", 0, 0);
final DetailAstImpl astIdent = mockAST(TokenTypes.IDENT, "myTestImport", 0, 0);
astImport.addChild(astIdent);
final DetailAST astSemi = mockAST(TokenTypes.SEMI, ";", 0, 0);
astIdent.addNextSibling(astSemi);
// Set unsupported option
final ImportOrderCheck mock = new ImportOrderCheck();
TestUtil.setInternalState(mock, "option", null);
// expecting IllegalStateException
try {
mock.visitToken(astImport);
assertWithMessage("An exception is expected").fail();
} catch (IllegalStateException ex) {
assertWithMessage("invalid exception message").that(ex.getMessage().endsWith(": null")).isTrue();
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class MatchXpathCheckTest method testEvaluationException.
@Test
public void testEvaluationException() {
final MatchXpathCheck matchXpathCheck = new MatchXpathCheck();
matchXpathCheck.setQuery("count(*) div 0");
final DetailAstImpl detailAST = new DetailAstImpl();
detailAST.setType(TokenTypes.CLASS_DEF);
detailAST.setText("Class Def");
detailAST.setLineNo(0);
detailAST.setColumnNo(0);
try {
matchXpathCheck.beginTree(detailAST);
assertWithMessage("Exception was expected").fail();
} catch (IllegalStateException ignored) {
// it is OK
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl 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.DetailAstImpl 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();
}
Aggregations