KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > util > classes > v1 > jdk0 > ArrayClassLoaderUTest


1 /*
2  * @(#)ArrayClassLoaderUTest.java 0.9.0 23-May-2001 - 14:40
3  *
4  * Copyright (C) 2001,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.jdk0;
28
29 import junit.framework.Test;
30 import junit.framework.TestCase;
31 import junit.framework.TestSuite;
32
33
34 /**
35  * Just like util.http.tests, this uses the Sourceforge account to ensure
36  * that the URLs work correctly. It loads the sample applet "BeliefOfTheDay"
37  * to make sure that this is able to load classes remotely.
38  * As insurance, this also tests to make sure that the same applet is not
39  * in the current classpath.
40  *
41  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
42  * @version $Date: 2003/02/10 22:52:39 $
43  * @since May 23, 2001
44  */

45 public class ArrayClassLoaderUTest extends TestCase
46 {
47     private static final Class JavaDoc THIS_CLASS = ArrayClassLoaderUTest.class;
48     
49     public ArrayClassLoaderUTest( String JavaDoc name )
50     {
51         super( name );
52     }
53     
54     public static Test suite()
55     {
56         TestSuite suite = new TestSuite( THIS_CLASS );
57         
58         return suite;
59     }
60     
61     public static void main( String JavaDoc[] args )
62     {
63         String JavaDoc[] name = { THIS_CLASS.getName() };
64         
65         // junit.textui.TestRunner.main( name );
66
// junit.swingui.TestRunner.main( name );
67

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

83         super.tearDown();
84     }
85
86     
87     public void testInstantiate()
88     {
89         new ArrayClassLoader();
90     }
91     
92     private class NullBytecodeSource implements BytecodeSource
93     {
94         public byte[] getBytecode( String JavaDoc classname )
95         {
96             return null;
97         }
98     }
99     
100     
101     public void testSetBytecodeSource()
102     {
103         ArrayClassLoader acl = new ArrayClassLoader();
104         acl.setBytecodeSource( new NullBytecodeSource() );
105     }
106     
107     
108     public void testSetBytecodeSourceNull()
109     {
110         ArrayClassLoader acl = new ArrayClassLoader();
111         acl.setBytecodeSource( null ); // should not throw an exception
112
}
113     
114     
115     public void testAddClassNull1()
116     {
117         ArrayClassLoader acl = new ArrayClassLoader();
118         try
119         {
120             acl.addClass( null, null );
121         }
122         catch (IllegalArgumentException JavaDoc iae)
123         {
124             return;
125         }
126         assertTrue( "Did not throw an IllegalArgumentException with null args.",
127             true );
128     }
129     
130     
131     public void testAddClassNull2()
132     {
133         ArrayClassLoader acl = new ArrayClassLoader();
134         try
135         {
136             acl.addClass( "SomeClass", null );
137         }
138         catch (IllegalArgumentException JavaDoc iae)
139         {
140             return;
141         }
142         assertTrue( "Did not throw an IllegalArgumentException with null args.",
143             true );
144     }
145     
146     
147     public void testAddClassNull3()
148     {
149         ArrayClassLoader acl = new ArrayClassLoader();
150         try
151         {
152             acl.addClass( null, new byte[0] );
153         }
154         catch (IllegalArgumentException JavaDoc iae)
155         {
156             return;
157         }
158         assertTrue( "Did not throw an IllegalArgumentException with null args.",
159             true );
160     }
161     
162     
163     public void testLoadClassNull1() throws ClassNotFoundException JavaDoc
164     {
165         ArrayClassLoader acl = new ArrayClassLoader();
166         try
167         {
168             acl.loadClass( null, true );
169             fail( "Did not throw an IllegalArgumentException with null args." );
170         }
171         catch (IllegalArgumentException JavaDoc iae)
172         {
173             // check error
174
return;
175         }
176     }
177     
178     
179     public void testLoadClassBad1()
180     {
181         ArrayClassLoader acl = setupLoader();
182         try
183         {
184             acl.loadClass( BAD_CLASS, true );
185             fail("Did not throw an Exception with a bad class.");
186         }
187         catch (ClassFormatError JavaDoc cfe)
188         {
189             // check error?
190
}
191         catch (ClassNotFoundException JavaDoc cnfe)
192         {
193             // check error?
194
}
195     }
196     
197     
198     protected static final String JavaDoc BAD_CLASS = "BadClass";
199     
200     protected ArrayClassLoader setupLoader()
201     {
202         ArrayClassLoader acl = new ArrayClassLoader();
203         acl.addClass( BAD_CLASS, new byte[0] );
204         
205         return acl;
206     }
207 }
208
Popular Tags