Search in sources :

Example 1 with Context

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();
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Context(com.puppycrawl.tools.checkstyle.api.Context) Test(org.junit.jupiter.api.Test)

Example 2 with Context

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();
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Context(com.puppycrawl.tools.checkstyle.api.Context) Test(org.junit.jupiter.api.Test)

Example 3 with Context

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();
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Context(com.puppycrawl.tools.checkstyle.api.Context) Test(org.junit.jupiter.api.Test)

Example 4 with Context

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));
}
Also used : Context(com.puppycrawl.tools.checkstyle.api.Context) Test(org.junit.jupiter.api.Test)

Example 5 with Context

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();
}
Also used : Context(com.puppycrawl.tools.checkstyle.api.Context) Test(org.junit.jupiter.api.Test)

Aggregations

Context (com.puppycrawl.tools.checkstyle.api.Context)6 Test (org.junit.jupiter.api.Test)6 DetailAstImpl (com.puppycrawl.tools.checkstyle.DetailAstImpl)3 Field (java.lang.reflect.Field)1 Locale (java.util.Locale)1