1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.onemind.commons.java.lang.reflect;
21
22 import org.onemind.commons.java.lang.reflect.ClassLookupCache;
23 import junit.framework.TestCase;
24
25
26 /***
27 * Unit test the class lookup cache
28 * @author TiongHiang Lee (thlee@onemindsoft.org)
29 * @version $Id: ClassLooupCacheTest.java,v 1.4 2006/10/29 17:02:38 thlee Exp $ $Name: $
30 */
31 public class ClassLooupCacheTest extends TestCase
32 {
33 /*** the cache **/
34 private ClassLookupCache _cache;
35
36 /***
37 * {@inheritDoc}
38 */
39 public void setUp()
40 {
41 _cache = new ClassLookupCache();
42 _cache.addImport("java.io.*");
43 }
44
45 /***
46 * Test lookup
47 */
48 public void testClassLookup() throws Exception
49 {
50 Class c = _cache.getClass("File");
51 assertEquals(c, java.io.File.class);
52 c = _cache.getClass("File1");
53 assertEquals(c, null);
54
55
56
57 assertTrue(_cache.isInCache("java.io.File"));
58 c = _cache.getClass("File1");
59 assertEquals(c, null);
60
61 c = _cache.getClass("Dummy");
62 assertEquals(c, null);
63
64 _cache.addImport("*");
65 c = _cache.getClass("Dummy");
66 assertEquals(Class.forName("Dummy"), c);
67 }
68 }