1 package org.apache.myfaces.util; 2 3 import junit.framework.TestCase; 4 5 16 public class ClassUtilsTest 17 extends TestCase 18 { 19 public void testClassForName() 20 throws ClassNotFoundException 21 { 22 assertEquals(ClassUtils.classForName("java.lang.String"), String .class); 23 24 try 25 { 26 ClassUtils.classForName("x.y.NotFound"); 27 assertTrue("ClassNotFoundException expected", false); 28 } 29 catch (ClassNotFoundException e) 30 { 31 } 33 34 try 35 { 36 ClassUtils.classForName("java.lang.String[]"); 37 assertTrue("ClassNotFoundException expected", false); 38 } 39 catch (ClassNotFoundException e) 40 { 41 } 43 44 try 45 { 46 ClassUtils.classForName("int"); 47 assertTrue("ClassNotFoundException expected", false); 48 } 49 catch (ClassNotFoundException e) 50 { 51 } 53 } 54 55 56 public void testJavaTypeToClass() 57 throws ClassNotFoundException 58 { 59 assertEquals(ClassUtils.javaTypeToClass("java.lang.String"), String .class); 60 61 try 62 { 63 ClassUtils.javaTypeToClass("x.y.NotFound"); 64 assertTrue("ClassNotFoundException expected", false); 65 } 66 catch (ClassNotFoundException e) 67 { 68 } 70 71 assertEquals(ClassUtils.javaTypeToClass("java.lang.String[]"), (new String [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 e) 81 { 82 } 84 } 85 } 86 | Popular Tags |