KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > imports > PkgControlTest


1 package com.puppycrawl.tools.checkstyle.checks.imports;
2
3 import com.puppycrawl.tools.checkstyle.checks.imports.AccessResult;
4 import com.puppycrawl.tools.checkstyle.checks.imports.Guard;
5 import com.puppycrawl.tools.checkstyle.checks.imports.PkgControl;
6 import junit.framework.TestCase;
7
8 public class PkgControlTest extends TestCase
9 {
10     private final PkgControl pcRoot = new PkgControl("com.kazgroup.courtlink");
11     private final PkgControl pcCommon = new PkgControl(pcRoot, "common");
12
13     protected void setUp() throws Exception JavaDoc
14     {
15         super.setUp();
16         pcRoot.addGuard(new Guard(false, false, "org.springframework", false));
17         pcRoot.addGuard(new Guard(false, false, "org.hibernate", false));
18         pcRoot.addGuard(new Guard(true, false, "org.apache.commons", false));
19
20         pcCommon.addGuard(new Guard(true, false, "org.hibernate", false));
21     }
22
23     public void testFullPkg()
24     {
25         assertEquals("com.kazgroup.courtlink", pcRoot.getFullPackage());
26         assertEquals("com.kazgroup.courtlink.common", pcCommon.getFullPackage());
27     }
28
29     public void testLocateFinest()
30     {
31         assertEquals(pcRoot, pcRoot
32                 .locateFinest("com.kazgroup.courtlink.domain"));
33         assertEquals(pcCommon, pcRoot
34                 .locateFinest("com.kazgroup.courtlink.common.api"));
35         assertNull(pcRoot.locateFinest("com"));
36     }
37
38     public void testCheckAccess()
39     {
40         assertEquals(AccessResult.DISALLOWED, pcCommon.checkAccess(
41                 "org.springframework.something",
42                 "com.kazgroup.courtlink.common"));
43         assertEquals(AccessResult.ALLOWED, pcCommon
44                 .checkAccess("org.apache.commons.something",
45                         "com.kazgroup.courtlink.common"));
46         assertEquals(AccessResult.DISALLOWED, pcCommon.checkAccess(
47                 "org.apache.commons", "com.kazgroup.courtlink.common"));
48         assertEquals(AccessResult.ALLOWED, pcCommon.checkAccess(
49                 "org.hibernate.something", "com.kazgroup.courtlink.common"));
50         assertEquals(AccessResult.DISALLOWED, pcCommon.checkAccess(
51                 "com.badpackage.something", "com.kazgroup.courtlink.common"));
52         assertEquals(AccessResult.DISALLOWED, pcRoot.checkAccess(
53                 "org.hibernate.something", "com.kazgroup.courtlink"));
54     }
55     
56     public void testUnknownPkg()
57     {
58         assertNull(pcRoot.locateFinest("net.another"));
59     }
60 }
61
Popular Tags