1 26 27 package net.sourceforge.groboutils.util.throwable.v1; 28 29 import java.io.PrintStream ; 30 import java.io.PrintWriter ; 31 import java.io.StringWriter ; 32 import java.io.ByteArrayOutputStream ; 33 import org.easymock.EasyMock; 34 import org.easymock.MockControl; 35 import junit.framework.Test; 36 import junit.framework.TestCase; 37 import junit.framework.TestSuite; 38 import net.sourceforge.groboutils.junit.v1.iftc.*; 39 40 41 48 public class IChainableExceptionUTestI extends InterfaceTestCase 49 { 50 51 57 public static interface IChainableExceptionFactory 58 { 59 public IChainableException createException(); 60 public IChainableException createException( String message ); 61 public IChainableException createException( Throwable cause ); 62 public IChainableException createException( String message, 63 Throwable cause ); 64 public IChainableException createException( Throwable cause, 65 String message ); 66 } 67 68 69 70 71 74 private static final Class THIS_CLASS = 75 IChainableExceptionUTestI.class; 76 77 public IChainableExceptionUTestI( String name, ImplFactory f ) 78 { 79 super( name, IChainableExceptionFactory.class, f ); 80 } 81 82 83 86 90 protected void setUp() throws Exception 91 { 92 super.setUp(); 93 94 } 96 97 98 private IChainableExceptionFactory createChainableExceptionFactory() 99 { 100 return (IChainableExceptionFactory)createImplObject(); 101 } 102 103 104 protected IChainableException createException() 105 { 106 IChainableException ce = createChainableExceptionFactory(). 107 createException(); 108 assertIsRealChainableException( ce ); 109 return ce; 110 } 111 112 113 protected IChainableException createException( String message ) 114 { 115 IChainableException ce = createChainableExceptionFactory(). 116 createException( message ); 117 assertIsRealChainableException( ce ); 118 return ce; 119 } 120 121 122 protected IChainableException createException( Throwable cause ) 123 { 124 IChainableException ce = createChainableExceptionFactory(). 125 createException( cause ); 126 assertIsRealChainableException( ce ); 127 return ce; 128 } 129 130 131 protected IChainableException createException( String message, 132 Throwable cause ) 133 { 134 IChainableException ce = createChainableExceptionFactory(). 135 createException( message, cause ); 136 assertIsRealChainableException( ce ); 137 return ce; 138 } 139 140 141 protected IChainableException createException( Throwable cause, 142 String message ) 143 { 144 IChainableException ce = createChainableExceptionFactory(). 145 createException( cause, message ); 146 assertIsRealChainableException( ce ); 147 return ce; 148 } 149 150 153 154 public void testEmptyConstructor1() 155 { 156 IChainableException ce = createException(); 157 assertNull( 158 "Cause is not null.", 159 ce.getCause() ); 160 } 161 162 163 public void testEmptyConstructor2() 164 { 165 IChainableException ce = createException(); 166 Throwable t = new Throwable (); 167 ce.initCause( t ); 168 assertEquals( 169 "Cause is not right.", 170 t, 171 ce.getCause() ); 172 } 173 174 175 public void testEmptyConstructor3() 176 { 177 IChainableException ce = createException(); 178 try 179 { 180 ce.initCause( (Throwable )ce ); 181 fail( "Did not throw IllegalArgumentException." ); 182 } 183 catch (IllegalArgumentException iae) 184 { 185 } 187 } 188 189 190 public void testCauseConstructor1() 191 { 192 Throwable t = null; 193 IChainableException ce = createException( t ); 194 assertNull( 195 "Cause is not null.", 196 ce.getCause() ); 197 } 198 199 200 public void testCauseConstructor2() 201 { 202 Throwable t = new Throwable (); 203 IChainableException ce = createException( t ); 204 assertEquals( 205 "Cause is not right.", 206 t, 207 ce.getCause() ); 208 } 209 210 211 public void testCauseConstructor3() 212 { 213 Throwable t = new Throwable (); 214 IChainableException ce = createException( t ); 215 try 216 { 217 ce.initCause( t ); 218 fail( "Did not throw IllegalStateException." ); 219 } 220 catch (IllegalStateException ise) 221 { 222 } 224 } 225 226 227 public void testCauseConstructor4() 228 { 229 IChainableException ce = createException( (Throwable )null ); 230 try 231 { 232 ce.initCause( null ); 233 fail( "Did not throw IllegalStateException." ); 234 } 235 catch (IllegalStateException ise) 236 { 237 } 239 } 240 241 242 public void testCauseConstructor5() 243 { 244 IChainableException ce = createException( (Throwable )null ); 245 try 246 { 247 ce.initCause( new Throwable () ); 248 fail( "Did not throw IllegalStateException." ); 249 } 250 catch (IllegalStateException ise) 251 { 252 } 254 } 255 256 257 public void testCauseConstructor6() 258 { 259 IChainableException ce = createException( new Throwable () ); 260 try 261 { 262 ce.initCause( null ); 263 fail( "Did not throw IllegalStateException." ); 264 } 265 catch (IllegalStateException ise) 266 { 267 } 269 } 270 271 272 public void testCauseConstructor7() 273 { 274 IChainableException ce = createException( new Throwable () ); 275 try 276 { 277 ce.initCause( (Throwable )ce ); 280 fail( "Did not throw IllegalStateException." ); 281 } 282 catch (IllegalStateException iae) 283 { 284 } 286 } 287 288 289 290 291 292 293 296 297 private void assertIsRealChainableException( IChainableException ce ) 298 { 299 assertNotNull( ce ); 300 assertTrue( 301 "Class under test ("+ce.getClass()+") is not an exception.", 302 ce instanceof Throwable ); 303 } 304 305 306 307 310 311 public static InterfaceTestSuite suite() 312 { 313 InterfaceTestSuite suite = new InterfaceTestSuite( THIS_CLASS ); 314 315 return suite; 316 } 317 318 public static void main( String [] args ) 319 { 320 String [] name = { THIS_CLASS.getName() }; 321 322 325 junit.textui.TestRunner.main( name ); 326 } 327 328 329 333 protected void tearDown() throws Exception 334 { 335 337 338 super.tearDown(); 339 } 340 } 341 342 | Popular Tags |