01: /* ====================================================================
02: The Jicarilla Software License
03:
04: Copyright (c) 2003 Leo Simons.
05: All rights reserved.
06:
07: Permission is hereby granted, free of charge, to any person obtaining
08: a copy of this software and associated documentation files (the
09: "Software"), to deal in the Software without restriction, including
10: without limitation the rights to use, copy, modify, merge, publish,
11: distribute, sublicense, and/or sell copies of the Software, and to
12: permit persons to whom the Software is furnished to do so, subject to
13: the following conditions:
14:
15: The above copyright notice and this permission notice shall be
16: included in all copies or substantial portions of the Software.
17:
18: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23: TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24: SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25: ==================================================================== */
26: package org.jicarilla.container.test.util;
27:
28: import junit.framework.TestCase;
29: import org.jicarilla.container.util.ReflectionUtil;
30:
31: import java.util.Arrays;
32:
33: /**
34: *
35: *
36: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
37: * @version $Id: ReflectionUtilTestCase.java,v 1.1 2004/02/29 18:08:09 lsimons Exp $
38: */
39: public class ReflectionUtilTestCase extends TestCase {
40: public void testLoadClass() throws Throwable {
41: assertEquals(this .getClass(), ReflectionUtil.loadClass(this
42: .getClass().getName()));
43:
44: try {
45: ReflectionUtil.loadClass(null);
46: fail("Expected an exception!");
47: } catch (AssertionError ae) {
48: }
49:
50: try {
51: ReflectionUtil
52: .loadClass("org.jicarilla.nonexistent.package.ClassName");
53: fail("Expected an exception!");
54: } catch (ClassNotFoundException th) {
55: }
56:
57: try {
58: ReflectionUtil.loadClass("bla bla");
59: fail("Expected an exception!");
60: } catch (ClassNotFoundException th) {
61: }
62: }
63:
64: public void testGetAllInterfaces() {
65: Class[] intf = ReflectionUtil.getAllInterfaces(Clazz.class);
66: assertEquals(4, intf.length);
67: assertTrue(Arrays.asList(intf).contains(AnInterface.class));
68: assertTrue(Arrays.asList(intf).contains(AnotherInterface.class));
69: assertTrue(Arrays.asList(intf).contains(ThirdInterface.class));
70: assertTrue(Arrays.asList(intf).contains(MixinInterface.class));
71: assertFalse(Arrays.asList(intf).contains(Clazz.class));
72:
73: intf = ReflectionUtil.getAllInterfaces(ThirdInterface.class);
74: assertEquals(3, intf.length);
75: assertTrue(Arrays.asList(intf).contains(AnInterface.class));
76: assertTrue(Arrays.asList(intf).contains(AnotherInterface.class));
77: assertTrue(Arrays.asList(intf).contains(ThirdInterface.class));
78: assertFalse(Arrays.asList(intf).contains(MixinInterface.class));
79: assertFalse(Arrays.asList(intf).contains(Clazz.class));
80: }
81:
82: public interface AnInterface {
83: }
84:
85: public interface AnotherInterface extends AnInterface {
86: }
87:
88: public interface MixinInterface extends AnInterface {
89: }
90:
91: public interface ThirdInterface extends AnotherInterface {
92: }
93:
94: public class Clazz implements ThirdInterface, MixinInterface {
95: }
96: }
|