KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > util > classes > v1 > IUrlClassLoaderUTestI


1 /*
2  * @(#)IUrlClassLoaderUTestI.java 0.9.0 23-May-2001 - 14:40
3  *
4  * Copyright (C) 2001,2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26
27 package net.sourceforge.groboutils.util.classes.v1;
28
29 import net.sourceforge.groboutils.junit.v1.iftc.*;
30 import junit.framework.Test;
31 import junit.framework.TestCase;
32 import junit.framework.TestSuite;
33
34 import java.net.URL JavaDoc;
35
36
37 /**
38  * Offline tests.
39  *
40  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
41  * @version $Date: 2003/02/10 22:52:39 $
42  * @since May 23, 2001 (GroboUtils Alpha 0.9.0)
43  */

44 public class IUrlClassLoaderUTestI extends InterfaceTestCase
45 {
46     private static final Class JavaDoc THIS_CLASS = IUrlClassLoaderUTestI.class;
47     
48     public IUrlClassLoaderUTestI( String JavaDoc name, ImplFactory f )
49     {
50         super( name, IUrlClassLoader.class, f );
51     }
52
53     
54     public IUrlClassLoader createLoader()
55     {
56         return (IUrlClassLoader)createImplObject();
57     }
58     
59     
60     public static InterfaceTestSuite suite()
61     {
62         InterfaceTestSuite suite = new InterfaceTestSuite( THIS_CLASS );
63         
64         return suite;
65     }
66     
67     //-------------------------------------------------------------------------
68

69     protected void setUp() throws Exception JavaDoc
70     {
71         super.setUp();
72         
73         // set ourself up
74
}
75     
76     
77     protected void tearDown() throws Exception JavaDoc
78     {
79         // tear ourself down
80

81         super.tearDown();
82     }
83
84     
85     public void testInstantiate()
86     {
87         assertNotNull( "Creation should not return null.",
88             createLoader() );
89     }
90     
91     
92     
93     
94     public static class MyInner
95     {
96         // default constructor implied
97
}
98     public static final String JavaDoc MY_INNER_RES =
99         "IUrlClassLoaderUTestI$MyInner.class";
100     public static final String JavaDoc MY_INNER_CLASS = MyInner.class.getName();
101     public static final String JavaDoc MY_INNER_FULL_RES =
102         '/' + MY_INNER_CLASS.replace( '.', '/' ) + ".class";
103     
104     public static class InnerClass
105     {
106         public InnerClass()
107         {
108             // do nothing
109
}
110     }
111     
112     
113     public static final String JavaDoc BELIEF_CLASS = "BeliefOfTheDay";
114     
115     
116     public void testGetClass1()
117     {
118         IUrlClassLoader loader = createLoader();
119         
120         Class JavaDoc c = loader.loadClass( MY_INNER_CLASS, null );
121         assertNotNull( "loadClass( "+MY_INNER_CLASS+
122             " ) returned null.",
123             c );
124         assertEquals( "Did not load the class from the default classloader.",
125             MyInner.class, c );
126     }
127     
128     
129     public void testGetClass2()
130     {
131         IUrlClassLoader loader = createLoader();
132         
133         Class JavaDoc c = loader.loadClass( BELIEF_CLASS, null );
134         assertEquals(
135             "getClass( Belief ) was found in the default classloader.",
136             null, c );
137     }
138     
139     
140     public void testGetClass3()
141     {
142         IUrlClassLoader loader = createLoader();
143         
144         URL JavaDoc url = this.getClass().getResource( MY_INNER_RES );
145         assertNotNull( "Did not find resource for inner class "+
146             MY_INNER_RES, url );
147         System.out.println("Found class in URL "+url);
148         String JavaDoc urlStr = url.toString();
149         if (urlStr.endsWith( MY_INNER_FULL_RES ))
150         {
151             urlStr = urlStr.substring( 0, urlStr.length() -
152                 MY_INNER_FULL_RES.length() );
153         }
154         
155         Class JavaDoc c = loader.loadClass( MY_INNER_CLASS, urlStr );
156         assertNotNull( "getClass( "+MY_INNER_CLASS+" ) returned null.", c );
157         assertEquals( "getClass( "+MY_INNER_CLASS+" ) returned the wrong class.",
158             MY_INNER_CLASS, c.getName() );
159     }
160     
161     
162     public void testFlush1()
163     {
164         IUrlClassLoader loader = createLoader();
165         
166         Class JavaDoc c = loader.loadClass( this.getClass().getName(), null );
167         loader.flush();
168         
169         // Can't really test this for correctness, just for error throwing.
170
// Testing for GC size is really inaccurate.
171
}
172     
173 }
174
Popular Tags