use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class RequireThisCheckTest method testUnusedMethod.
@Test
public void testUnusedMethod() throws Exception {
final DetailAstImpl ident = new DetailAstImpl();
ident.setText("testName");
final Class<?> cls = Class.forName(RequireThisCheck.class.getName() + "$CatchFrame");
final Constructor<?> constructor = cls.getDeclaredConstructors()[0];
constructor.setAccessible(true);
final Object o = constructor.newInstance(null, ident);
final DetailAstImpl actual = TestUtil.invokeMethod(o, "getFrameNameIdent");
assertWithMessage("expected ident token").that(actual).isSameInstanceAs(ident);
assertWithMessage("expected catch frame type").that(TestUtil.invokeMethod(o, "getType").toString()).isEqualTo("CATCH_FRAME");
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class VisibilityModifierCheckTest method testWrongTokenType.
@Test
public void testWrongTokenType() {
final VisibilityModifierCheck obj = new VisibilityModifierCheck();
final DetailAstImpl ast = new DetailAstImpl();
ast.initialize(new CommonToken(TokenTypes.CLASS_DEF, "class"));
try {
obj.visitToken(ast);
assertWithMessage("exception expected").fail();
} catch (IllegalArgumentException ex) {
assertWithMessage("Invalid exception message").that(ex.getMessage()).isEqualTo("Unexpected token type: class");
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class IllegalInstantiationCheckTest method testImproperToken.
@Test
public void testImproperToken() {
final IllegalInstantiationCheck check = new IllegalInstantiationCheck();
final DetailAstImpl lambdaAst = new DetailAstImpl();
lambdaAst.setType(TokenTypes.LAMBDA);
try {
check.visitToken(lambdaAst);
assertWithMessage("IllegalArgumentException is expected").fail();
} catch (IllegalArgumentException ex) {
// it is OK
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class IllegalTypeCheckTest method testImproperToken.
@Test
public void testImproperToken() {
final IllegalTypeCheck check = new IllegalTypeCheck();
final DetailAstImpl classDefAst = new DetailAstImpl();
classDefAst.setType(TokenTypes.DOT);
try {
check.visitToken(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 ClassDataAbstractionCouplingCheckTest method testWrongToken.
@Test
public void testWrongToken() {
final ClassDataAbstractionCouplingCheck classDataAbstractionCouplingCheckObj = new ClassDataAbstractionCouplingCheck();
final DetailAstImpl ast = new DetailAstImpl();
ast.initialize(new CommonToken(TokenTypes.CTOR_DEF, "ctor"));
try {
classDataAbstractionCouplingCheckObj.visitToken(ast);
assertWithMessage("exception expected").fail();
} catch (IllegalArgumentException ex) {
assertWithMessage("Invalid exception message").that(ex.getMessage()).isEqualTo("Unknown type: ctor[0x-1]");
}
}
Aggregations