use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class TokenUtilTest method testIsOfTypeFalse.
@Test
public void testIsOfTypeFalse() {
final int type = TokenTypes.LITERAL_CATCH;
final DetailAstImpl astForTest1 = new DetailAstImpl();
final DetailAstImpl astForTest2 = null;
astForTest1.setType(type);
final boolean result1 = TokenUtil.isOfType(type, TokenTypes.LITERAL_FOR, TokenTypes.LITERAL_IF, TokenTypes.LITERAL_ELSE);
final boolean result2 = TokenUtil.isOfType(astForTest1, TokenTypes.LITERAL_FOR, TokenTypes.LITERAL_IF, TokenTypes.LITERAL_ELSE);
final boolean result3 = TokenUtil.isOfType(astForTest2, TokenTypes.LITERAL_FOR, TokenTypes.LITERAL_IF, TokenTypes.LITERAL_ELSE);
assertWithMessage("Token type should not match").that(result1).isFalse();
assertWithMessage("Token type should not match").that(result2).isFalse();
assertWithMessage("Token type should not match").that(result3).isFalse();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class SuppressWarningsHolderTest method testAstWithoutChildren.
@Test
public void testAstWithoutChildren() {
final SuppressWarningsHolder holder = new SuppressWarningsHolder();
final DetailAstImpl methodDef = new DetailAstImpl();
methodDef.setType(TokenTypes.METHOD_DEF);
try {
holder.visitToken(methodDef);
assertWithMessage("Exception expected").fail();
} catch (IllegalArgumentException ex) {
assertWithMessage("Error message is unexpected").that(ex.getMessage()).isEqualTo("Identifier AST expected, but get null.");
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class SuppressWarningsHolderTest method testGetAllAnnotationValuesWrongArg.
@Test
public void testGetAllAnnotationValuesWrongArg() throws ReflectiveOperationException {
final SuppressWarningsHolder holder = new SuppressWarningsHolder();
final Method getAllAnnotationValues = holder.getClass().getDeclaredMethod("getAllAnnotationValues", DetailAST.class);
getAllAnnotationValues.setAccessible(true);
final DetailAstImpl methodDef = new DetailAstImpl();
methodDef.setType(TokenTypes.METHOD_DEF);
methodDef.setText("Method Def");
methodDef.setLineNo(0);
methodDef.setColumnNo(0);
final DetailAstImpl lparen = new DetailAstImpl();
lparen.setType(TokenTypes.LPAREN);
final DetailAstImpl parent = new DetailAstImpl();
parent.addChild(lparen);
parent.addChild(methodDef);
try {
getAllAnnotationValues.invoke(holder, parent);
assertWithMessage("Exception expected").fail();
} catch (ReflectiveOperationException ex) {
assertWithMessage("Error type is unexpected").that(ex).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
assertWithMessage("Error message is unexpected").that(ex).hasCauseThat().hasMessageThat().isEqualTo("Unexpected AST: Method Def[0x0]");
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class SuppressWarningsHolderTest method testGetAnnotationTargetWrongArg.
@Test
public void testGetAnnotationTargetWrongArg() throws ReflectiveOperationException {
final SuppressWarningsHolder holder = new SuppressWarningsHolder();
final Method getAnnotationTarget = holder.getClass().getDeclaredMethod("getAnnotationTarget", DetailAST.class);
getAnnotationTarget.setAccessible(true);
final DetailAstImpl methodDef = new DetailAstImpl();
methodDef.setType(TokenTypes.METHOD_DEF);
methodDef.setText("Method Def");
final DetailAstImpl parent = new DetailAstImpl();
parent.setType(TokenTypes.ASSIGN);
parent.setText("Parent ast");
parent.addChild(methodDef);
parent.setLineNo(0);
parent.setColumnNo(0);
try {
getAnnotationTarget.invoke(holder, methodDef);
assertWithMessage("Exception expected").fail();
} catch (ReflectiveOperationException ex) {
assertWithMessage("Error type is unexpected").that(ex).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
assertWithMessage("Error message is unexpected").that(ex).hasCauseThat().hasMessageThat().isEqualTo("Unexpected container AST: Parent ast[0x0]");
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class RequireThisCheckTest method testDefaultSwitch.
@Test
public void testDefaultSwitch() {
final RequireThisCheck check = new RequireThisCheck();
final DetailAstImpl ast = new DetailAstImpl();
ast.initialize(new CommonToken(TokenTypes.ENUM, "ENUM"));
check.visitToken(ast);
final SortedSet<Violation> violations = check.getViolations();
assertWithMessage("No exception violations expected").that(violations).isEmpty();
}
Aggregations