1 26 27 package net.sourceforge.groboutils.mbtf.v1.engine; 28 29 import org.easymock.EasyMock; 30 import org.easymock.MockControl; 31 import net.sourceforge.groboutils.junit.v1.iftc.*; 32 import junit.framework.Test; 33 import junit.framework.TestCase; 34 import junit.framework.TestSuite; 35 36 import net.sourceforge.groboutils.mbtf.v1.*; 37 38 45 public class ErrorsImplJDK13UTest extends TestCase 46 { 47 50 private static final Class THIS_CLASS = ErrorsImplJDK13UTest.class; 51 52 public ErrorsImplJDK13UTest( String name ) 53 { 54 super( name ); 55 } 56 57 58 61 private MockControl phControl; 62 private IPathHistory mockPH; 63 64 65 69 protected void setUp() throws Exception 70 { 71 super.setUp(); 72 73 this.phControl = EasyMock.controlFor( IPathHistory.class ); 75 this.mockPH = (IPathHistory)this.phControl.getMock(); 76 } 77 78 79 82 83 public void testConstructor1() 84 { 85 ErrorsImpl ei = new ErrorsImpl(); 86 assertEquals( 87 "# of errors not zero", 88 ei.getErrors().length, 89 0 ); 90 assertEquals( 91 "# of warnings not zero", 92 ei.getWarnings().length, 93 0 ); 94 assertTrue( 95 "default path halt state wrong", 96 !ei.isHaltPath() ); 97 assertTrue( 98 "default test halt state wrong", 99 !ei.isHaltTests() ); 100 } 101 102 103 public void testHalt1() 104 { 105 ErrorsImpl ei = new ErrorsImpl(); 106 String msg = "msg"; 107 108 try 109 { 110 ei.halt( msg ); 111 fail("did not throw exception"); 112 } 113 catch (TestHaltRuntimeException thre) 114 { 115 } 117 118 assertErrors( ei, msg, null, null ); 119 assertTrue( 120 "path halt not set right", 121 ei.isHaltPath() ); 122 assertTrue( 123 "test halt not set right", 124 ei.isHaltTests() ); 125 } 126 127 128 public void testHalt2() 129 { 130 String msg = "msg"; 131 ErrorsImpl ei = new ErrorsImpl(); 132 this.mockPH.copy(); 133 this.phControl.setReturnValue( this.mockPH, 1 ); 134 this.phControl.activate(); 135 136 137 ei.setCurrentPathHistory( this.mockPH ); 138 try 139 { 140 ei.halt( msg ); 141 fail("did not throw exception"); 142 } 143 catch (TestHaltRuntimeException thre) 144 { 145 } 147 assertTrue( 148 "path halt not set right", 149 ei.isHaltPath() ); 150 assertTrue( 151 "test halt not set right", 152 ei.isHaltTests() ); 153 assertErrors( ei, msg, this.mockPH, null ); 154 155 this.phControl.verify(); 156 } 157 158 159 public void testAddFailure1() 160 { 161 String msg = "msg 2"; 162 ErrorsImpl ei = new ErrorsImpl(); 163 164 ei.addFailure( msg ); 165 166 assertTrue( 167 "path halt not set right", 168 ei.isHaltPath() ); 169 assertTrue( 170 "test halt not set right", 171 !ei.isHaltTests() ); 172 assertErrors( ei, msg, null, null ); 173 } 174 175 176 public void testAddFailure2() 177 { 178 String msg = "msg < >"; 179 ErrorsImpl ei = new ErrorsImpl(); 180 this.mockPH.copy(); 181 this.phControl.setReturnValue( this.mockPH, 1 ); 182 this.phControl.activate(); 183 184 185 ei.setCurrentPathHistory( this.mockPH ); 186 ei.addFailure( msg ); 187 188 assertTrue( 189 "path halt not set right", 190 ei.isHaltPath() ); 191 assertTrue( 192 "test halt not set right", 193 !ei.isHaltTests() ); 194 assertErrors( ei, msg, this.mockPH, null ); 195 196 this.phControl.verify(); 197 } 198 199 200 public void testAddFailure3() 201 { 202 String msg = "msg 2"; 203 Throwable t = new Throwable ("ignore"); 204 ErrorsImpl ei = new ErrorsImpl(); 205 206 ei.addFailure( msg, t ); 207 208 assertTrue( 209 "path halt not set right", 210 ei.isHaltPath() ); 211 assertTrue( 212 "test halt not set right", 213 !ei.isHaltTests() ); 214 assertErrors( ei, msg, null, t ); 215 } 216 217 218 public void testAddFailure4() 219 { 220 String msg = "msg < >"; 221 Throwable t = new Throwable ("ignore"); 222 ErrorsImpl ei = new ErrorsImpl(); 223 this.mockPH.copy(); 224 this.phControl.setReturnValue( this.mockPH, 1 ); 225 this.phControl.activate(); 226 227 228 ei.setCurrentPathHistory( this.mockPH ); 229 ei.addFailure( msg, t ); 230 231 assertTrue( 232 "path halt not set right", 233 ei.isHaltPath() ); 234 assertTrue( 235 "test halt not set right", 236 !ei.isHaltTests() ); 237 assertErrors( ei, msg, this.mockPH, t ); 238 239 this.phControl.verify(); 240 } 241 242 243 244 245 public void testAddError1() 246 { 247 String msg = "msg 2"; 248 ErrorsImpl ei = new ErrorsImpl(); 249 250 ei.addError( msg ); 251 252 assertTrue( 253 "path halt not set right", 254 !ei.isHaltPath() ); 255 assertTrue( 256 "test halt not set right", 257 !ei.isHaltTests() ); 258 assertErrors( ei, msg, null, null ); 259 } 260 261 262 public void testAddError2() 263 { 264 String msg = "msg < >"; 265 ErrorsImpl ei = new ErrorsImpl(); 266 this.mockPH.copy(); 267 this.phControl.setReturnValue( this.mockPH, 1 ); 268 this.phControl.activate(); 269 270 271 ei.setCurrentPathHistory( this.mockPH ); 272 ei.addError( msg ); 273 274 assertTrue( 275 "path halt not set right", 276 !ei.isHaltPath() ); 277 assertTrue( 278 "test halt not set right", 279 !ei.isHaltTests() ); 280 assertErrors( ei, msg, this.mockPH, null ); 281 282 this.phControl.verify(); 283 } 284 285 286 public void testAddError3() 287 { 288 String msg = "msg 2"; 289 Throwable t = new Throwable ("ignore"); 290 ErrorsImpl ei = new ErrorsImpl(); 291 292 ei.addError( msg, t ); 293 294 assertTrue( 295 "path halt not set right", 296 !ei.isHaltPath() ); 297 assertTrue( 298 "test halt not set right", 299 !ei.isHaltTests() ); 300 assertErrors( ei, msg, null, t ); 301 } 302 303 304 public void testAddError4() 305 { 306 String msg = "msg < >"; 307 Throwable t = new Throwable ("ignore"); 308 ErrorsImpl ei = new ErrorsImpl(); 309 this.mockPH.copy(); 310 this.phControl.setReturnValue( this.mockPH, 1 ); 311 this.phControl.activate(); 312 313 314 ei.setCurrentPathHistory( this.mockPH ); 315 ei.addError( msg, t ); 316 317 assertTrue( 318 "path halt not set right", 319 !ei.isHaltPath() ); 320 assertTrue( 321 "test halt not set right", 322 !ei.isHaltTests() ); 323 assertErrors( ei, msg, this.mockPH, t ); 324 325 this.phControl.verify(); 326 } 327 328 329 330 333 334 protected void assertErrors( ErrorsImpl ei, String msg, IPathHistory hist, 335 Throwable t ) 336 { 337 IError e[] = ei.getErrors(); 338 assertErrorType( e, msg, hist, t ); 339 } 340 341 342 protected void assertErrorType( IError[] e, String msg, 343 IPathHistory hist, Throwable t ) 344 { 345 assertNotNull( 346 "error array is null", 347 e ); 348 assertEquals( 349 "did not add error correctly", 350 e.length, 351 1 ); 352 assertNotNull( 353 "error contents are null", 354 e[0] ); 355 assertEquals( 356 "path history is not correct", 357 e[0].getPathHistory(), 358 hist ); 359 assertEquals( 360 "throwable is not correct", 361 e[0].getThrowable(), 362 t ); 363 assertEquals( 364 "message not right.", 365 e[0].getMessage(), 366 msg ); 367 } 368 369 372 373 public static Test suite() 374 { 375 InterfaceTestSuite suite = IErrorsUTestI.suite(); 376 377 suite.addFactory( new CxFactory( "A" ) { 379 public Object createImplObject() { 380 return new ErrorsImpl(); 381 } 382 } ); 383 return suite; 384 } 385 386 public static void main( String [] args ) 387 { 388 String [] name = { THIS_CLASS.getName() }; 389 390 393 junit.textui.TestRunner.main( name ); 394 } 395 396 397 401 protected void tearDown() throws Exception 402 { 403 405 super.tearDown(); 406 } 407 } 408 | Popular Tags |