250 |
|
throw (RuntimeException) t; |
251 |
|
else if (t instanceof Exception) |
252 |
|
throw (Exception) t; |
253 |
< |
else |
254 |
< |
throw new AssertionError(t); |
253 |
> |
else { |
254 |
> |
AssertionFailedError afe = |
255 |
> |
new AssertionFailedError(t.toString()); |
256 |
> |
afe.initCause(t); |
257 |
> |
throw afe; |
258 |
> |
} |
259 |
|
} |
260 |
|
} |
261 |
|
|
262 |
|
/** |
263 |
|
* Just like fail(reason), but additionally recording (using |
264 |
< |
* threadRecordFailure) any AssertionError thrown, so that the current |
265 |
< |
* testcase will fail. |
264 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
265 |
> |
* the current testcase will fail. |
266 |
|
*/ |
267 |
|
public void threadFail(String reason) { |
268 |
|
try { |
269 |
|
fail(reason); |
270 |
< |
} catch (Throwable t) { |
270 |
> |
} catch (AssertionFailedError t) { |
271 |
|
threadRecordFailure(t); |
272 |
|
fail(reason); |
273 |
|
} |
275 |
|
|
276 |
|
/** |
277 |
|
* Just like assertTrue(b), but additionally recording (using |
278 |
< |
* threadRecordFailure) any AssertionError thrown, so that the current |
279 |
< |
* testcase will fail. |
278 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
279 |
> |
* the current testcase will fail. |
280 |
|
*/ |
281 |
|
public void threadAssertTrue(boolean b) { |
282 |
|
try { |
283 |
|
assertTrue(b); |
284 |
< |
} catch (AssertionError t) { |
284 |
> |
} catch (AssertionFailedError t) { |
285 |
|
threadRecordFailure(t); |
286 |
|
throw t; |
287 |
|
} |
289 |
|
|
290 |
|
/** |
291 |
|
* Just like assertFalse(b), but additionally recording (using |
292 |
< |
* threadRecordFailure) any AssertionError thrown, so that the |
293 |
< |
* current testcase will fail. |
292 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
293 |
> |
* the current testcase will fail. |
294 |
|
*/ |
295 |
|
public void threadAssertFalse(boolean b) { |
296 |
|
try { |
297 |
|
assertFalse(b); |
298 |
< |
} catch (AssertionError t) { |
298 |
> |
} catch (AssertionFailedError t) { |
299 |
|
threadRecordFailure(t); |
300 |
|
throw t; |
301 |
|
} |
303 |
|
|
304 |
|
/** |
305 |
|
* Just like assertNull(x), but additionally recording (using |
306 |
< |
* threadRecordFailure) any AssertionError thrown, so that the |
307 |
< |
* current testcase will fail. |
306 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
307 |
> |
* the current testcase will fail. |
308 |
|
*/ |
309 |
|
public void threadAssertNull(Object x) { |
310 |
|
try { |
311 |
|
assertNull(x); |
312 |
< |
} catch (AssertionError t) { |
312 |
> |
} catch (AssertionFailedError t) { |
313 |
|
threadRecordFailure(t); |
314 |
|
throw t; |
315 |
|
} |
317 |
|
|
318 |
|
/** |
319 |
|
* Just like assertEquals(x, y), but additionally recording (using |
320 |
< |
* threadRecordFailure) any AssertionError thrown, so that the |
321 |
< |
* current testcase will fail. |
320 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
321 |
> |
* the current testcase will fail. |
322 |
|
*/ |
323 |
|
public void threadAssertEquals(long x, long y) { |
324 |
|
try { |
325 |
|
assertEquals(x, y); |
326 |
< |
} catch (AssertionError t) { |
326 |
> |
} catch (AssertionFailedError t) { |
327 |
|
threadRecordFailure(t); |
328 |
|
throw t; |
329 |
|
} |
331 |
|
|
332 |
|
/** |
333 |
|
* Just like assertEquals(x, y), but additionally recording (using |
334 |
< |
* threadRecordFailure) any AssertionError thrown, so that the |
335 |
< |
* current testcase will fail. |
334 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
335 |
> |
* the current testcase will fail. |
336 |
|
*/ |
337 |
|
public void threadAssertEquals(Object x, Object y) { |
338 |
|
try { |
339 |
|
assertEquals(x, y); |
340 |
< |
} catch (AssertionError t) { |
340 |
> |
} catch (AssertionFailedError t) { |
341 |
|
threadRecordFailure(t); |
342 |
|
throw t; |
343 |
+ |
} catch (Throwable t) { |
344 |
+ |
threadUnexpectedException(t); |
345 |
|
} |
346 |
|
} |
347 |
|
|
348 |
|
/** |
349 |
|
* Just like assertSame(x, y), but additionally recording (using |
350 |
< |
* threadRecordFailure) any AssertionError thrown, so that the |
351 |
< |
* current testcase will fail. |
350 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
351 |
> |
* the current testcase will fail. |
352 |
|
*/ |
353 |
|
public void threadAssertSame(Object x, Object y) { |
354 |
|
try { |
355 |
|
assertSame(x, y); |
356 |
< |
} catch (AssertionError t) { |
356 |
> |
} catch (AssertionFailedError t) { |
357 |
|
threadRecordFailure(t); |
358 |
|
throw t; |
359 |
|
} |
374 |
|
} |
375 |
|
|
376 |
|
/** |
377 |
< |
* Calls threadFail with message "Unexpected exception" + ex. |
377 |
> |
* Records the given exception using {@link #threadRecordFailure}, |
378 |
> |
* then rethrows the exception, wrapping it in an |
379 |
> |
* AssertionFailedError if necessary. |
380 |
|
*/ |
381 |
|
public void threadUnexpectedException(Throwable t) { |
382 |
|
threadRecordFailure(t); |
383 |
|
t.printStackTrace(); |
376 |
– |
// Rethrow, wrapping in an AssertionError if necessary |
384 |
|
if (t instanceof RuntimeException) |
385 |
|
throw (RuntimeException) t; |
386 |
|
else if (t instanceof Error) |
387 |
|
throw (Error) t; |
388 |
|
else { |
389 |
< |
AssertionError ae = new AssertionError("unexpected exception: " + t); |
389 |
> |
AssertionFailedError afe = |
390 |
> |
new AssertionFailedError("unexpected exception: " + t); |
391 |
|
t.initCause(t); |
392 |
< |
throw ae; |
392 |
> |
throw afe; |
393 |
|
} |
394 |
|
} |
395 |
|
|
424 |
|
} |
425 |
|
|
426 |
|
/** |
419 |
– |
* Fails with message "Unexpected exception: " + ex. |
420 |
– |
*/ |
421 |
– |
public void unexpectedException(Throwable ex) { |
422 |
– |
ex.printStackTrace(); |
423 |
– |
fail("Unexpected exception: " + ex); |
424 |
– |
} |
425 |
– |
|
426 |
– |
|
427 |
– |
/** |
427 |
|
* The number of elements to place in collections, arrays, etc. |
428 |
|
*/ |
429 |
|
public static final int SIZE = 20; |
544 |
|
} |
545 |
|
|
546 |
|
/** |
547 |
< |
* Returns a new started Thread running the given runnable. |
547 |
> |
* Returns a new started daemon Thread running the given runnable. |
548 |
|
*/ |
549 |
|
Thread newStartedThread(Runnable runnable) { |
550 |
|
Thread t = new Thread(runnable); |
551 |
+ |
t.setDaemon(true); |
552 |
|
t.start(); |
553 |
|
return t; |
554 |
|
} |
716 |
|
} |
717 |
|
} |
718 |
|
|
719 |
– |
public class SmallInterruptedRunnable extends CheckedInterruptedRunnable { |
720 |
– |
protected void realRun() throws InterruptedException { |
721 |
– |
Thread.sleep(SMALL_DELAY_MS); |
722 |
– |
} |
723 |
– |
} |
724 |
– |
|
719 |
|
public class MediumRunnable extends CheckedRunnable { |
720 |
|
protected void realRun() throws Throwable { |
721 |
|
Thread.sleep(MEDIUM_DELAY_MS); |