KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > PackageNamesLoaderTest


1 package com.puppycrawl.tools.checkstyle;
2
3 import java.util.Arrays JavaDoc;
4 import java.util.HashSet JavaDoc;
5 import java.util.Set JavaDoc;
6
7 import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
8
9 import junit.framework.TestCase;
10
11 /**
12  * Enter a description of class PackageNamesLoaderTest.java.
13  * @author Rick Giles
14  * @author lkuehne
15  * @version $Revision$
16  */

17 public class PackageNamesLoaderTest extends TestCase
18 {
19     public void testDefault()
20         throws CheckstyleException
21     {
22         ModuleFactory moduleFactory = PackageNamesLoader
23                 .loadModuleFactory(Thread.currentThread()
24                         .getContextClassLoader());
25         validateFactory(moduleFactory);
26     }
27
28     public void testNoFile()
29     {
30         try {
31             PackageNamesLoader.loadModuleFactory("NoFile");
32             fail("Loaded non-existant file.");
33         }
34         catch (CheckstyleException ex) {
35             assertEquals("CheckstyleException.message.",
36                 "unable to find NoFile",
37                 ex.getMessage());
38         }
39     }
40
41     public void testFile()
42         throws CheckstyleException
43     {
44         final ModuleFactory moduleFactory =
45             PackageNamesLoader.loadModuleFactory(
46                 System.getProperty("checkstyle.root")
47                 + "/src/checkstyle/com/puppycrawl/tools/checkstyle/checkstyle_packages.xml");
48         validateFactory(moduleFactory);
49     }
50
51     private void validateFactory(ModuleFactory aModuleFactory)
52     {
53         final String JavaDoc[] checkstylePackages = {
54             "com.puppycrawl.tools.checkstyle.",
55             "com.puppycrawl.tools.checkstyle.checks.",
56             "com.puppycrawl.tools.checkstyle.checks.blocks.",
57             "com.puppycrawl.tools.checkstyle.checks.coding.",
58             "com.puppycrawl.tools.checkstyle.checks.design.",
59             "com.puppycrawl.tools.checkstyle.checks.duplicates.",
60             "com.puppycrawl.tools.checkstyle.checks.header.",
61             "com.puppycrawl.tools.checkstyle.checks.imports.",
62             "com.puppycrawl.tools.checkstyle.checks.indentation.",
63             "com.puppycrawl.tools.checkstyle.checks.javadoc.",
64             "com.puppycrawl.tools.checkstyle.checks.metrics.",
65             "com.puppycrawl.tools.checkstyle.checks.modifier.",
66             "com.puppycrawl.tools.checkstyle.checks.naming.",
67             "com.puppycrawl.tools.checkstyle.checks.sizes.",
68             "com.puppycrawl.tools.checkstyle.checks.whitespace.",
69             "com.puppycrawl.tools.checkstyle.filters.",
70
71         };
72
73         PackageObjectFactory factory = (PackageObjectFactory) aModuleFactory;
74         String JavaDoc[] pkgNames = factory.getPackages();
75
76         assertEquals("pkgNames.length.", checkstylePackages.length,
77             pkgNames.length);
78         Set JavaDoc checkstylePackagesSet =
79             new HashSet JavaDoc(Arrays.asList(checkstylePackages));
80         Set JavaDoc pkgNamesSet = new HashSet JavaDoc(Arrays.asList(pkgNames));
81         assertEquals("names set.", checkstylePackagesSet, pkgNamesSet);
82     }
83
84 }
85
Popular Tags