Search in sources :

Example 6 with Context

use of com.puppycrawl.tools.checkstyle.api.Context in project checkstyle by checkstyle.

the class CheckerTest method testFinishLocalSetupFullyInitialized.

@Test
public void testFinishLocalSetupFullyInitialized() throws Exception {
    final Checker checker = new Checker();
    final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    checker.setModuleClassLoader(contextClassLoader);
    final PackageObjectFactory factory = new PackageObjectFactory(new HashSet<>(), contextClassLoader);
    checker.setModuleFactory(factory);
    checker.setBasedir("testBaseDir");
    checker.setLocaleLanguage("it");
    checker.setLocaleCountry("IT");
    checker.finishLocalSetup();
    final Context context = TestUtil.getInternalState(checker, "childContext");
    final String encoding = StandardCharsets.UTF_8.name();
    assertWithMessage("Charset was different than expected").that(context.get("charset")).isEqualTo(encoding);
    assertWithMessage("Severity is set to unexpected value").that(context.get("severity")).isEqualTo("error");
    assertWithMessage("Basedir is set to unexpected value").that(context.get("basedir")).isEqualTo("testBaseDir");
    final Field sLocale = Violation.class.getDeclaredField("sLocale");
    sLocale.setAccessible(true);
    final Locale locale = (Locale) sLocale.get(null);
    assertWithMessage("Locale is set to unexpected value").that(locale).isEqualTo(Locale.ITALY);
}
Also used : Context(com.puppycrawl.tools.checkstyle.api.Context) Locale(java.util.Locale) Field(java.lang.reflect.Field) 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