1 21 22 package org.opensubsystems.core.util; 23 24 import junit.framework.TestCase; 25 26 import org.opensubsystems.core.error.OSSDynamicClassException; 27 28 36 public class ClassUtilsTest extends TestCase 37 { 38 42 public ClassUtilsTest( 43 String arg0 44 ) 45 { 46 super(arg0); 47 } 48 49 54 protected void setUp( 55 ) throws Exception 56 { 57 super.setUp(); 58 } 59 60 65 protected void tearDown() throws Exception 66 { 67 super.tearDown(); 68 } 69 70 75 public void testCreateNewInstanceWithClass( 76 ) throws Exception 77 { 78 Object test; 79 Object test2; 80 81 test = ClassUtils.createNewInstance(String .class); 83 assertNotNull("Cannot instantiate String class", test); 84 85 test2 = ClassUtils.createNewInstance(String .class); 87 assertNotNull("Cannot instantiate String class", test2); 88 assertTrue("Cannot create the same instance twice", test != test2); 89 90 try 92 { 93 test = ClassUtils.createNewInstance(java.io.File .class); 94 fail("Instantiated class with no public constructor"); 95 } 96 catch (OSSDynamicClassException dceExc) 97 { 98 } 100 } 101 102 107 public void testCreateNewInstanceWithString( 108 ) throws Exception 109 { 110 Object test; 111 Object test2; 112 113 test = ClassUtils.createNewInstance("java.lang.String"); 115 assertNotNull("Cannot instantiate String class", test); 116 117 test2 = ClassUtils.createNewInstance("java.lang.String"); 119 assertNotNull("Cannot instantiate String class", test2); 120 assertTrue("Cannot create the same instance twice", test != test2); 121 122 try 124 { 125 test = ClassUtils.createNewInstance("java.io.File"); 126 fail("Instantiated class with no public constructor"); 127 } 128 catch (OSSDynamicClassException dceExc) 129 { 130 } 132 133 try 135 { 136 test = ClassUtils.createNewInstance("class.which.doesnt.exist"); 137 fail("Instantiated class which doesn't exist"); 138 } 139 catch (OSSDynamicClassException dceExc) 140 { 141 } 143 } 144 } 145 | Popular Tags |