KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.TestCase;
6
7 public class GuardTest extends TestCase
8 {
9     public void testPkgGuard1()
10     {
11         final Guard g = new Guard(true, false, "pkg", false);
12         assertNotNull(g);
13         assertEquals(AccessResult.UNKNOWN, g.verifyImport("asda"));
14         assertEquals(AccessResult.UNKNOWN, g.verifyImport("p"));
15         assertEquals(AccessResult.UNKNOWN, g.verifyImport("pkga"));
16         assertEquals(AccessResult.ALLOWED, g.verifyImport("pkg.a"));
17         assertEquals(AccessResult.ALLOWED, g.verifyImport("pkg.a.b"));
18         assertEquals(AccessResult.UNKNOWN, g.verifyImport("pkg"));
19     }
20
21     public void testPkgGuard2()
22     {
23         final Guard g = new Guard(true, false, "pkg", true);
24         assertNotNull(g);
25         assertEquals(AccessResult.UNKNOWN, g.verifyImport("asda"));
26         assertEquals(AccessResult.UNKNOWN, g.verifyImport("p"));
27         assertEquals(AccessResult.ALLOWED, g.verifyImport("pkg.a"));
28         assertEquals(AccessResult.UNKNOWN, g.verifyImport("pkg.a.b"));
29         assertEquals(AccessResult.UNKNOWN, g.verifyImport("pkg"));
30     }
31
32     public void testClassGuard()
33     {
34         final Guard g = new Guard(true, false, "pkg.a");
35         assertNotNull(g);
36         assertEquals(AccessResult.UNKNOWN, g.verifyImport("asda"));
37         assertEquals(AccessResult.UNKNOWN, g.verifyImport("p"));
38         assertEquals(AccessResult.UNKNOWN, g.verifyImport("pkga"));
39         assertEquals(AccessResult.ALLOWED, g.verifyImport("pkg.a"));
40         assertEquals(AccessResult.UNKNOWN, g.verifyImport("pkg.a.b"));
41         assertEquals(AccessResult.UNKNOWN, g.verifyImport("pkg"));
42     }
43 }
44
Popular Tags