use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class InterfaceMemberImpliedModifierCheckTest method testIllegalState.
@Test
public void testIllegalState() {
final DetailAstImpl init = new DetailAstImpl();
init.setType(TokenTypes.STATIC_INIT);
final DetailAstImpl objBlock = new DetailAstImpl();
objBlock.setType(TokenTypes.OBJBLOCK);
objBlock.addChild(init);
final DetailAstImpl interfaceAst = new DetailAstImpl();
interfaceAst.setType(TokenTypes.INTERFACE_DEF);
interfaceAst.addChild(objBlock);
final InterfaceMemberImpliedModifierCheck check = new InterfaceMemberImpliedModifierCheck();
try {
check.visitToken(init);
assertWithMessage("IllegalStateException is expected").fail();
} catch (IllegalStateException ex) {
assertWithMessage("Error message is unexpected").that(ex.getMessage()).isEqualTo(init.toString());
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class RedundantModifierCheckTest method testWrongTokenType.
@Test
public void testWrongTokenType() {
final RedundantModifierCheck obj = new RedundantModifierCheck();
final DetailAstImpl ast = new DetailAstImpl();
ast.initialize(TokenTypes.LITERAL_NULL, "null");
final IllegalStateException exception = assertThrows(IllegalStateException.class, () -> {
obj.visitToken(ast);
}, "IllegalStateException was expected");
assertWithMessage("Expected and actual violation messages do not match").that(exception.getMessage()).isEqualTo("Unexpected token type: " + ast.getType());
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class BooleanExpressionComplexityCheckTest method testWrongToken.
@Test
public void testWrongToken() {
final BooleanExpressionComplexityCheck booleanExpressionComplexityCheckObj = new BooleanExpressionComplexityCheck();
final DetailAstImpl ast = new DetailAstImpl();
ast.initialize(new CommonToken(TokenTypes.INTERFACE_DEF, "interface"));
try {
booleanExpressionComplexityCheckObj.visitToken(ast);
assertWithMessage("exception expected").fail();
} catch (IllegalArgumentException ex) {
assertWithMessage("Invalid exception message").that(ex.getMessage()).isEqualTo("Unknown type: interface[0x-1]");
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class ClassMemberImpliedModifierCheckTest method testIllegalState.
@Test
public void testIllegalState() {
final DetailAstImpl init = new DetailAstImpl();
init.setType(TokenTypes.STATIC_INIT);
final DetailAstImpl objBlock = new DetailAstImpl();
objBlock.setType(TokenTypes.OBJBLOCK);
objBlock.addChild(init);
final DetailAstImpl interfaceAst = new DetailAstImpl();
interfaceAst.setType(TokenTypes.CLASS_DEF);
interfaceAst.addChild(objBlock);
final ClassMemberImpliedModifierCheck check = new ClassMemberImpliedModifierCheck();
try {
check.visitToken(init);
assertWithMessage("IllegalStateException is expected").fail();
} catch (IllegalStateException ex) {
assertWithMessage("Error message is unexpected").that(ex.getMessage()).isEqualTo(init.toString());
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class JavadocTagInfoTest method testDeprecated.
@Test
public void testDeprecated() throws ReflectiveOperationException {
final DetailAstImpl ast = new DetailAstImpl();
final DetailAstImpl astParent = new DetailAstImpl();
astParent.setType(TokenTypes.LITERAL_CATCH);
final Method setParent = ast.getClass().getDeclaredMethod("setParent", DetailAstImpl.class);
setParent.setAccessible(true);
setParent.invoke(ast, astParent);
final int[] validTypes = { TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF, TokenTypes.ENUM_DEF, TokenTypes.ANNOTATION_DEF, TokenTypes.METHOD_DEF, TokenTypes.CTOR_DEF, TokenTypes.ENUM_CONSTANT_DEF, TokenTypes.ANNOTATION_FIELD_DEF, TokenTypes.VARIABLE_DEF };
for (int type : validTypes) {
ast.setType(type);
assertWithMessage("Invalid ast type for current tag: " + ast.getType()).that(JavadocTagInfo.DEPRECATED.isValidOn(ast)).isTrue();
}
astParent.setType(TokenTypes.SLIST);
ast.setType(TokenTypes.VARIABLE_DEF);
assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.DEPRECATED.isValidOn(ast)).isFalse();
ast.setType(TokenTypes.PARAMETER_DEF);
assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.DEPRECATED.isValidOn(ast)).isFalse();
}
Aggregations