Search in sources :

Example 6 with CommonHiddenStreamToken

use of antlr.CommonHiddenStreamToken in project checkstyle by checkstyle.

the class ThrowsCountCheckTest method testWrongTokenType.

@Test
public void testWrongTokenType() {
    final ThrowsCountCheck obj = new ThrowsCountCheck();
    final DetailAST ast = new DetailAST();
    ast.initialize(new CommonHiddenStreamToken(TokenTypes.CLASS_DEF, "class"));
    try {
        obj.visitToken(ast);
        fail("IllegalStateException is expected");
    } catch (IllegalStateException ex) {
        assertEquals(ast.toString(), ex.getMessage());
    }
}
Also used : CommonHiddenStreamToken(antlr.CommonHiddenStreamToken) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.Test)

Example 7 with CommonHiddenStreamToken

use of antlr.CommonHiddenStreamToken in project checkstyle by checkstyle.

the class RequireThisCheckTest method testDefaultSwitch.

@Test
public void testDefaultSwitch() {
    final RequireThisCheck check = new RequireThisCheck();
    final DetailAST ast = new DetailAST();
    ast.initialize(new CommonHiddenStreamToken(TokenTypes.ENUM, "ENUM"));
    check.visitToken(ast);
}
Also used : CommonHiddenStreamToken(antlr.CommonHiddenStreamToken) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.Test)

Example 8 with CommonHiddenStreamToken

use of antlr.CommonHiddenStreamToken in project checkstyle by checkstyle.

the class VisibilityModifierCheckTest method testWrongTokenType.

@Test
public void testWrongTokenType() {
    final VisibilityModifierCheck obj = new VisibilityModifierCheck();
    final DetailAST ast = new DetailAST();
    ast.initialize(new CommonHiddenStreamToken(TokenTypes.CLASS_DEF, "class"));
    try {
        obj.visitToken(ast);
        fail("exception expected");
    } catch (IllegalArgumentException ex) {
        assertEquals("Unexpected token type: class", ex.getMessage());
    }
}
Also used : CommonHiddenStreamToken(antlr.CommonHiddenStreamToken) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.Test)

Example 9 with CommonHiddenStreamToken

use of antlr.CommonHiddenStreamToken in project checkstyle by checkstyle.

the class MutableExceptionCheckTest method testWrongTokenType.

@Test
public void testWrongTokenType() {
    final MutableExceptionCheck obj = new MutableExceptionCheck();
    final DetailAST ast = new DetailAST();
    ast.initialize(new CommonHiddenStreamToken(TokenTypes.INTERFACE_DEF, "interface"));
    try {
        obj.visitToken(ast);
        fail("IllegalStateException is expected");
    } catch (IllegalStateException ex) {
    //expected
    }
}
Also used : CommonHiddenStreamToken(antlr.CommonHiddenStreamToken) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.Test)

Example 10 with CommonHiddenStreamToken

use of antlr.CommonHiddenStreamToken in project checkstyle by checkstyle.

the class ExecutableStatementCountCheckTest method testVisitTokenWithWrongTokenType.

@Test
public void testVisitTokenWithWrongTokenType() {
    final ExecutableStatementCountCheck checkObj = new ExecutableStatementCountCheck();
    final DetailAST ast = new DetailAST();
    ast.initialize(new CommonHiddenStreamToken(TokenTypes.ENUM, "ENUM"));
    try {
        checkObj.visitToken(ast);
        fail("exception expected");
    } catch (IllegalStateException ex) {
        assertEquals("ENUM[0x-1]", ex.getMessage());
    }
}
Also used : CommonHiddenStreamToken(antlr.CommonHiddenStreamToken) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.Test)

Aggregations

CommonHiddenStreamToken (antlr.CommonHiddenStreamToken)15 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)14 Test (org.junit.Test)11 CommonASTWithHiddenTokens (antlr.CommonASTWithHiddenTokens)1 AST (antlr.collections.AST)1