use of com.puppycrawl.tools.checkstyle.api.Context in project checkstyle by checkstyle.
the class ExecutableStatementCountCheckTest method testStatefulFieldsClearedOnBeginTree.
@Test
@SuppressWarnings("unchecked")
public void testStatefulFieldsClearedOnBeginTree() {
final DetailAstImpl ast = new DetailAstImpl();
ast.setType(TokenTypes.STATIC_INIT);
final ExecutableStatementCountCheck check = new ExecutableStatementCountCheck();
assertWithMessage("Stateful field is not cleared after beginTree").that(TestUtil.isStatefulFieldClearedDuringBeginTree(check, ast, "contextStack", contextStack -> ((Collection<Context>) contextStack).isEmpty())).isTrue();
}
use of com.puppycrawl.tools.checkstyle.api.Context in project checkstyle by checkstyle.
the class NPathComplexityCheckTest method testStatefulFieldsClearedOnBeginTree1.
@Test
@SuppressWarnings("unchecked")
public void testStatefulFieldsClearedOnBeginTree1() {
final DetailAstImpl ast = new DetailAstImpl();
ast.setType(TokenTypes.LITERAL_ELSE);
final NPathComplexityCheck check = new NPathComplexityCheck();
assertWithMessage("Stateful field is not cleared after beginTree").that(TestUtil.isStatefulFieldClearedDuringBeginTree(check, ast, "rangeValues", rangeValues -> ((Collection<Context>) rangeValues).isEmpty())).isTrue();
assertWithMessage("Stateful field is not cleared after beginTree").that(TestUtil.isStatefulFieldClearedDuringBeginTree(check, ast, "expressionValues", expressionValues -> ((Collection<Context>) expressionValues).isEmpty())).isTrue();
}
use of com.puppycrawl.tools.checkstyle.api.Context in project checkstyle by checkstyle.
the class NPathComplexityCheckTest method testStatefulFieldsClearedOnBeginTree2.
@Test
@SuppressWarnings("unchecked")
public void testStatefulFieldsClearedOnBeginTree2() {
final DetailAstImpl ast = new DetailAstImpl();
ast.setType(TokenTypes.LITERAL_RETURN);
ast.setLineNo(5);
final DetailAstImpl child = new DetailAstImpl();
child.setType(TokenTypes.SEMI);
ast.addChild(child);
final NPathComplexityCheck check = new NPathComplexityCheck();
assertWithMessage("Stateful field is not cleared after beginTree").that(TestUtil.isStatefulFieldClearedDuringBeginTree(check, ast, "afterValues", isAfterValues -> ((Collection<Context>) isAfterValues).isEmpty())).isTrue();
}
use of com.puppycrawl.tools.checkstyle.api.Context in project checkstyle by checkstyle.
the class TreeWalkerTest method testFinishLocalSetupFullyInitialized.
@Test
public void testFinishLocalSetupFullyInitialized() {
final TreeWalker treeWalker = new TreeWalker();
treeWalker.setSeverity("error");
treeWalker.setTabWidth(100);
treeWalker.finishLocalSetup();
final Context context = TestUtil.getInternalState(treeWalker, "childContext");
assertWithMessage("Severity differs from expected").that(context.get("severity")).isEqualTo("error");
assertWithMessage("Tab width differs from expected").that(context.get("tabWidth")).isEqualTo(String.valueOf(100));
}
use of com.puppycrawl.tools.checkstyle.api.Context in project checkstyle by checkstyle.
the class CheckerTest method testNoModuleFactory.
@Test
public void testNoModuleFactory() throws Exception {
final Checker checker = new Checker();
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
checker.setModuleClassLoader(classLoader);
checker.finishLocalSetup();
final Context actualCtx = TestUtil.getInternalState(checker, "childContext");
assertWithMessage("Default module factory should be created when it is not specified").that(actualCtx.get("moduleFactory")).isNotNull();
}
Aggregations