KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > ClassResolverTest


1 package com.puppycrawl.tools.checkstyle.checks;
2
3 import junit.framework.TestCase;
4
5 import java.util.Set JavaDoc;
6 import java.util.HashSet JavaDoc;
7
8 public class ClassResolverTest
9     extends TestCase
10 {
11     public void testMisc() throws ClassNotFoundException JavaDoc
12     {
13         final Set JavaDoc imps = new HashSet JavaDoc();
14         imps.add("java.io.File");
15         imps.add("nothing.will.match.*");
16         imps.add("java.applet.*");
17         ClassResolver cr =
18             new ClassResolver(Thread.currentThread().getContextClassLoader(),
19                               null, imps);
20         assertNotNull(cr);
21         try {
22             cr.resolve("who.will.win.the.world.cup", "");
23             fail("Should not resolve class");
24         }
25         catch (ClassNotFoundException JavaDoc e) {
26         }
27         cr.resolve("java.lang.String", "");
28         cr.resolve("StringBuffer", "");
29         cr.resolve("AppletContext", "");
30
31         try {
32             cr.resolve("ChoiceFormat", "");
33             fail();
34         }
35         catch (ClassNotFoundException JavaDoc e) {
36         }
37
38         imps.add("java.text.ChoiceFormat");
39         cr.resolve("ChoiceFormat", "");
40
41         cr = new ClassResolver(Thread.currentThread().getContextClassLoader(),
42                                "java.util", imps);
43         cr.resolve("List", "");
44         try {
45             cr.resolve("two.nil.england", "");
46             fail();
47         }
48         catch (ClassNotFoundException JavaDoc e) {
49         }
50     }
51 }
52
Popular Tags