Search in sources :

Example 91 with Configuration

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

the class PropertyCacheFileTest method testConfigHashRemainsOnResetExternalResources.

@Test
public void testConfigHashRemainsOnResetExternalResources() throws IOException {
    final Configuration config = new DefaultConfiguration("myName");
    final String filePath = temporaryFolder.newFile().getPath();
    final PropertyCacheFile cache = new PropertyCacheFile(config, filePath);
    // create cache with one file
    cache.load();
    cache.put("myFile", 1);
    final String hash = cache.get(PropertyCacheFile.CONFIG_HASH_KEY);
    assertNotNull(hash);
    // apply new external resource to clear cache
    final Set<String> resources = new HashSet<>();
    resources.add("dummy");
    cache.putExternalResources(resources);
    assertEquals(hash, cache.get(PropertyCacheFile.CONFIG_HASH_KEY));
    assertFalse(cache.isInCache("myFile", 1));
}
Also used : Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 92 with Configuration

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

the class PropertyCacheFileTest method testCtor.

@Test
public void testCtor() {
    try {
        new PropertyCacheFile(null, "");
    } catch (IllegalArgumentException ex) {
        assertEquals("config can not be null", ex.getMessage());
    }
    try {
        final Configuration config = new DefaultConfiguration("myName");
        new PropertyCacheFile(config, null);
    } catch (IllegalArgumentException ex) {
        assertEquals("fileName can not be null", ex.getMessage());
    }
}
Also used : Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 93 with Configuration

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

the class PropertyCacheFileTest method testInCache.

@Test
public void testInCache() throws IOException {
    final Configuration config = new DefaultConfiguration("myName");
    final String filePath = temporaryFolder.newFile().getPath();
    final PropertyCacheFile cache = new PropertyCacheFile(config, filePath);
    cache.put("myFile", 1);
    assertTrue(cache.isInCache("myFile", 1));
    assertFalse(cache.isInCache("myFile", 2));
    assertFalse(cache.isInCache("myFile1", 1));
}
Also used : Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 94 with Configuration

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

the class JavadocPackageCheckTest method testHtmlDisallowed.

@Test
public void testHtmlDisallowed() throws Exception {
    final Configuration checkConfig = createCheckConfig(JavadocPackageCheck.class);
    final String[] expected = { "0: " + getCheckMessage(MSG_PACKAGE_INFO) };
    verify(createChecker(checkConfig), getPath("pkghtml" + File.separator + "InputIgnored.java"), getPath("pkghtml" + File.separator + "InputIgnored.java"), expected);
}
Also used : Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 95 with Configuration

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

the class JavadocPackageCheckTest method testBoth.

@Test
public void testBoth() throws Exception {
    final Configuration checkConfig = createCheckConfig(JavadocPackageCheck.class);
    final String[] expected = { "0: " + getCheckMessage(MSG_LEGACY_PACKAGE_HTML) };
    verify(createChecker(checkConfig), getPath("bothfiles" + File.separator + "InputIgnored.java"), getPath("bothfiles" + File.separator + "InputIgnored.java"), expected);
}
Also used : Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Aggregations

Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)137 Test (org.junit.Test)127 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)16 Properties (java.util.Properties)13 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)9 File (java.io.File)9 Checker (com.puppycrawl.tools.checkstyle.Checker)5 PropertiesExpander (com.puppycrawl.tools.checkstyle.PropertiesExpander)4 OneTopLevelClassCheck (com.puppycrawl.tools.checkstyle.checks.design.OneTopLevelClassCheck)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 ModuleFactory (com.puppycrawl.tools.checkstyle.ModuleFactory)2 AuditListener (com.puppycrawl.tools.checkstyle.api.AuditListener)2 RootModule (com.puppycrawl.tools.checkstyle.api.RootModule)2 AnnotationLocationCheck (com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationLocationCheck)2 EmptyLineSeparatorCheck (com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineSeparatorCheck)2 MethodParamPadCheck (com.puppycrawl.tools.checkstyle.checks.whitespace.MethodParamPadCheck)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2