1   /*
2    * Copyright (C) 2004 TiongHiang Lee
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not,  write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   *
18   * Email: thlee@onemindsoft.org
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          //do it again to test the cache behavior.
56          //result verified through log4j output
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  }