use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class FinalClassCheckTest method testImproperToken.
@Test
public void testImproperToken() {
final FinalClassCheck finalClassCheck = new FinalClassCheck();
final DetailAstImpl badAst = new DetailAstImpl();
final int unsupportedTokenByCheck = TokenTypes.COMPILATION_UNIT;
badAst.setType(unsupportedTokenByCheck);
try {
finalClassCheck.visitToken(badAst);
assertWithMessage("IllegalStateException is expected").fail();
} catch (IllegalStateException ex) {
// it is OK
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class ModifiedControlVariableCheckTest method testImproperToken.
@Test
public void testImproperToken() {
final ModifiedControlVariableCheck check = new ModifiedControlVariableCheck();
final DetailAstImpl classDefAst = new DetailAstImpl();
classDefAst.setType(TokenTypes.CLASS_DEF);
try {
check.visitToken(classDefAst);
assertWithMessage("IllegalStateException is expected").fail();
} catch (IllegalStateException ex) {
// it is OK
}
try {
check.leaveToken(classDefAst);
assertWithMessage("IllegalStateException is expected").fail();
} catch (IllegalStateException ex) {
// it is OK
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class FinalLocalVariableCheckTest method testImproperToken.
@Test
public void testImproperToken() {
final FinalLocalVariableCheck check = new FinalLocalVariableCheck();
final DetailAstImpl lambdaAst = new DetailAstImpl();
lambdaAst.setType(TokenTypes.LAMBDA);
try {
check.visitToken(lambdaAst);
assertWithMessage("IllegalStateException is expected").fail();
} catch (IllegalStateException ex) {
// it is OK
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class UncommentedMainCheckTest method testIllegalStateException.
@Test
public void testIllegalStateException() {
final UncommentedMainCheck check = new UncommentedMainCheck();
final DetailAstImpl ast = new DetailAstImpl();
ast.initialize(new CommonToken(TokenTypes.CTOR_DEF, "ctor"));
try {
check.visitToken(ast);
assertWithMessage("IllegalStateException is expected").fail();
} catch (IllegalStateException ex) {
assertWithMessage("Error message is unexpected").that(ex.getMessage()).isEqualTo(ast.toString());
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class NoWhitespaceAfterCheckTest method testVisitTokenSwitchReflection.
@Test
public void testVisitTokenSwitchReflection() {
// unexpected parent for ARRAY_DECLARATOR token
final DetailAstImpl astImport = mockAST(TokenTypes.IMPORT, "import");
final DetailAstImpl astArrayDeclarator = mockAST(TokenTypes.ARRAY_DECLARATOR, "[");
final DetailAstImpl astRightBracket = mockAST(TokenTypes.RBRACK, "[");
astImport.addChild(astArrayDeclarator);
astArrayDeclarator.addChild(astRightBracket);
final NoWhitespaceAfterCheck check = new NoWhitespaceAfterCheck();
try {
check.visitToken(astArrayDeclarator);
assertWithMessage("no intended exception thrown").fail();
} catch (IllegalStateException ex) {
assertWithMessage("Invalid exception message").that(ex.getMessage()).isEqualTo("unexpected ast syntax import[0x-1]");
}
}
Aggregations