01: package com.mockrunner.test.util;
02:
03: import java.io.OutputStream;
04: import java.io.Serializable;
05: import java.net.URL;
06: import java.util.Arrays;
07:
08: import com.mockrunner.jms.JMSTestModule;
09: import com.mockrunner.util.common.ClassUtil;
10:
11: import junit.framework.TestCase;
12:
13: public class ClassUtilTest extends TestCase {
14: public void testGetPackageName() {
15: assertEquals("com.mockrunner.test.util", ClassUtil
16: .getPackageName(this .getClass()));
17: assertEquals("java.lang", ClassUtil.getPackageName(""
18: .getClass()));
19: assertEquals("java.io", ClassUtil
20: .getPackageName(OutputStream.class));
21: assertEquals("com.mockrunner.test.util", ClassUtil
22: .getPackageName(TestClass.class));
23: }
24:
25: public void testGetClassName() {
26: assertEquals("ClassUtilTest", ClassUtil.getClassName(this
27: .getClass()));
28: assertEquals("String", ClassUtil.getClassName("".getClass()));
29: assertEquals("OutputStream", ClassUtil
30: .getClassName(OutputStream.class));
31: assertEquals("ClassUtilTest$TestClass", ClassUtil
32: .getClassName(TestClass.class));
33: assertEquals("OutputStream[][]", ClassUtil
34: .getClassName(OutputStream[][].class));
35: assertEquals("int[]", ClassUtil.getClassName(int[].class));
36: }
37:
38: public void testIsKeyword() {
39: assertTrue(ClassUtil.isKeyword("void"));
40: assertTrue(ClassUtil.isKeyword("volatile"));
41: assertFalse(ClassUtil.isKeyword("Boolean"));
42: assertFalse(ClassUtil.isKeyword("xyz"));
43: }
44:
45: public void testGetArgumentName() {
46: assertEquals("voidValue", ClassUtil.getArgumentName(Void.class));
47: assertEquals("booleanValue", ClassUtil
48: .getArgumentName(Boolean.TYPE));
49: assertEquals("string", ClassUtil.getArgumentName(String.class));
50: assertEquals("classUtilTest", ClassUtil
51: .getArgumentName(ClassUtilTest.class));
52: assertEquals("jmsTestModule", ClassUtil
53: .getArgumentName(JMSTestModule.class));
54: assertEquals("url", ClassUtil.getArgumentName(URL.class));
55: assertEquals("urls", ClassUtil.getArgumentName(URL[].class));
56: assertEquals("jmsTestModules", ClassUtil
57: .getArgumentName(JMSTestModule[].class));
58: assertEquals("strings", ClassUtil
59: .getArgumentName(String[].class));
60: assertEquals("intValues", ClassUtil
61: .getArgumentName(int[][][].class));
62: assertEquals("doubleValues", ClassUtil
63: .getArgumentName(Double[][].class));
64: }
65:
66: public void testGetInheritanceHierarchy() {
67: Class[] classes = ClassUtil
68: .getInheritanceHierarchy(Object.class);
69: assertTrue(Arrays.equals(classes, new Class[] { Object.class }));
70: classes = ClassUtil.getInheritanceHierarchy(Super.class);
71: assertTrue(Arrays.equals(classes, new Class[] { Object.class,
72: Super.class }));
73: classes = ClassUtil.getInheritanceHierarchy(Sub2.class);
74: assertTrue(Arrays.equals(classes, new Class[] { Object.class,
75: Super.class, Sub1.class, Sub2.class }));
76: }
77:
78: public static class TestClass {
79:
80: }
81:
82: public static class Super {
83:
84: }
85:
86: public static class Sub1 extends Super implements Serializable {
87:
88: }
89:
90: public static class Sub2 extends Sub1 implements Cloneable {
91:
92: }
93: }
|