KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > util > ClassUtilsTest


1 package org.apache.myfaces.util;
2
3 import junit.framework.TestCase;
4
5 /**
6  * @author Manfred Geiler (latest modification by $Author: matze $)
7  * @version $Revision: 1.3 $ $Date: 2004/10/13 11:50:59 $
8  * $Log: ClassUtilsTest.java,v $
9  * Revision 1.3 2004/10/13 11:50:59 matze
10  * renamed packages to org.apache
11  *
12  * Revision 1.2 2004/10/05 22:34:20 dave0000
13  * bug 1021656 with related improvements
14  *
15  */

16 public class ClassUtilsTest
17         extends TestCase
18 {
19     public void testClassForName()
20         throws ClassNotFoundException JavaDoc
21     {
22         assertEquals(ClassUtils.classForName("java.lang.String"), String JavaDoc.class);
23
24         try
25         {
26             ClassUtils.classForName("x.y.NotFound");
27             assertTrue("ClassNotFoundException expected", false);
28         }
29         catch (ClassNotFoundException JavaDoc e)
30         {
31             // ignore, must trow this exception
32
}
33
34         try
35         {
36             ClassUtils.classForName("java.lang.String[]");
37             assertTrue("ClassNotFoundException expected", false);
38         }
39         catch (ClassNotFoundException JavaDoc e)
40         {
41             // ignore, must trow this exception
42
}
43
44         try
45         {
46             ClassUtils.classForName("int");
47             assertTrue("ClassNotFoundException expected", false);
48         }
49         catch (ClassNotFoundException JavaDoc e)
50         {
51             // ignore, must trow this exception
52
}
53     }
54
55
56     public void testJavaTypeToClass()
57         throws ClassNotFoundException JavaDoc
58     {
59         assertEquals(ClassUtils.javaTypeToClass("java.lang.String"), String JavaDoc.class);
60
61         try
62         {
63             ClassUtils.javaTypeToClass("x.y.NotFound");
64             assertTrue("ClassNotFoundException expected", false);
65         }
66         catch (ClassNotFoundException JavaDoc e)
67         {
68             // ignore, must trow this exception
69
}
70
71         assertEquals(ClassUtils.javaTypeToClass("java.lang.String[]"), (new String JavaDoc[0]).getClass());
72         assertEquals(ClassUtils.javaTypeToClass("int"), Integer.TYPE);
73         assertEquals(ClassUtils.javaTypeToClass("int[]"), (new int[0]).getClass());
74
75         try
76         {
77             ClassUtils.javaTypeToClass("int[][]");
78             assertTrue("ClassNotFoundException expected", false);
79         }
80         catch (ClassNotFoundException JavaDoc e)
81         {
82             // ignore, must trow this exception
83
}
84     }
85 }
86
Popular Tags