KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > impl > TestDefaultClassResolver


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.impl;
16
17 import java.net.URL JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.apache.hivemind.ApplicationRuntimeException;
23 import org.apache.hivemind.ClassResolver;
24 import org.apache.hivemind.test.HiveMindTestCase;
25
26 /**
27  * Tests for {@link org.apache.hivemind.impl.DefaultClassResolver}.
28  *
29  * @author Howard M. Lewis Ship
30  * @since 1.1
31  */

32 public class TestDefaultClassResolver extends HiveMindTestCase
33 {
34     public void testDefaultClassLoader()
35     {
36         ClassResolver cr = new DefaultClassResolver();
37
38         assertSame(Thread.currentThread().getContextClassLoader(), cr.getClassLoader());
39     }
40
41     public void testGetResource()
42     {
43         ClassResolver cr = new DefaultClassResolver();
44
45         URL JavaDoc normal = cr.getResource("org/apache/hivemind/impl/Privates.xml");
46         URL JavaDoc withSlash = cr.getResource("/org/apache/hivemind/impl/Privates.xml");
47
48         URL JavaDoc expected = Thread.currentThread().getContextClassLoader().getResource(
49                 "org/apache/hivemind/impl/Privates.xml");
50
51         assertEquals(expected, normal);
52         assertEquals(expected, withSlash);
53     }
54
55     public void testFindClassSuccess()
56     {
57         ClassResolver cr = new DefaultClassResolver();
58
59         assertEquals(HashMap JavaDoc.class, cr.findClass("java.util.HashMap"));
60     }
61
62     public void testFindClassFailure()
63     {
64         ClassResolver cr = new DefaultClassResolver();
65
66         try
67         {
68             cr.findClass("com.foo.Xyzzyx");
69             unreachable();
70         }
71         catch (ApplicationRuntimeException ex)
72         {
73             assertExceptionSubstring(ex, "Could not load class com.foo.Xyzzyx ");
74         }
75     }
76
77     public void testFindClassPrimitive()
78     {
79         ClassResolver cr = new DefaultClassResolver();
80
81         assertSame(boolean.class, cr.findClass("boolean"));
82     }
83
84     public void testCheckClassExists()
85     {
86         ClassResolver cr = new DefaultClassResolver();
87
88         assertSame(Iterator JavaDoc.class, cr.findClass("java.util.Iterator"));
89     }
90
91     public void testCheckClassMissing()
92     {
93         ClassResolver cr = new DefaultClassResolver();
94
95         assertNull(cr.checkForClass("java.lang.Qbert"));
96     }
97
98     public void testFindClassArray()
99     {
100         ClassResolver cr = new DefaultClassResolver();
101
102         assertSame(List JavaDoc[].class, cr.findClass("java.util.List[]"));
103         assertSame(List JavaDoc[][].class, cr.findClass("java.util.List[][]"));
104     }
105
106     public void testFindPrimitiveArray()
107     {
108         ClassResolver cr = new DefaultClassResolver();
109
110         assertSame(int[].class, cr.findClass("int[]"));
111         assertSame(int[][].class, cr.findClass("int[][]"));
112     }
113 }
Popular Tags