265 |
|
public static boolean atLeastJava6() { return JAVA_CLASS_VERSION >= 50.0; } |
266 |
|
public static boolean atLeastJava7() { return JAVA_CLASS_VERSION >= 51.0; } |
267 |
|
public static boolean atLeastJava8() { return JAVA_CLASS_VERSION >= 52.0; } |
268 |
< |
public static boolean atLeastJava9() { |
269 |
< |
// As of 2014-05, java9 still uses 52.0 class file version |
270 |
< |
return JAVA_SPECIFICATION_VERSION.startsWith("1.9"); |
271 |
< |
} |
268 |
> |
public static boolean atLeastJava9() { return JAVA_CLASS_VERSION >= 53.0; } |
269 |
|
|
270 |
|
/** |
271 |
|
* Collects all JSR166 unit tests as one suite. |
561 |
|
public void threadAssertEquals(Object x, Object y) { |
562 |
|
try { |
563 |
|
assertEquals(x, y); |
564 |
< |
} catch (AssertionFailedError t) { |
565 |
< |
threadRecordFailure(t); |
566 |
< |
throw t; |
567 |
< |
} catch (Throwable t) { |
568 |
< |
threadUnexpectedException(t); |
564 |
> |
} catch (AssertionFailedError fail) { |
565 |
> |
threadRecordFailure(fail); |
566 |
> |
throw fail; |
567 |
> |
} catch (Throwable fail) { |
568 |
> |
threadUnexpectedException(fail); |
569 |
|
} |
570 |
|
} |
571 |
|
|
577 |
|
public void threadAssertSame(Object x, Object y) { |
578 |
|
try { |
579 |
|
assertSame(x, y); |
580 |
< |
} catch (AssertionFailedError t) { |
581 |
< |
threadRecordFailure(t); |
582 |
< |
throw t; |
580 |
> |
} catch (AssertionFailedError fail) { |
581 |
> |
threadRecordFailure(fail); |
582 |
> |
throw fail; |
583 |
|
} |
584 |
|
} |
585 |
|
|
649 |
|
" did not terminate in a timely manner"); |
650 |
|
} catch (SecurityException ok) { |
651 |
|
// Allowed in case test doesn't have privs |
652 |
< |
} catch (InterruptedException ie) { |
652 |
> |
} catch (InterruptedException fail) { |
653 |
|
fail("Unexpected InterruptedException"); |
654 |
|
} |
655 |
|
} |
680 |
|
// No need to optimize the failing case via Thread.join. |
681 |
|
delay(millis); |
682 |
|
assertTrue(thread.isAlive()); |
683 |
< |
} catch (InterruptedException ie) { |
683 |
> |
} catch (InterruptedException fail) { |
684 |
|
fail("Unexpected InterruptedException"); |
685 |
|
} |
686 |
|
} |
702 |
|
delay(millis); |
703 |
|
for (Thread thread : threads) |
704 |
|
assertTrue(thread.isAlive()); |
705 |
< |
} catch (InterruptedException ie) { |
705 |
> |
} catch (InterruptedException fail) { |
706 |
|
fail("Unexpected InterruptedException"); |
707 |
|
} |
708 |
|
} |
724 |
|
future.get(timeoutMillis, MILLISECONDS); |
725 |
|
shouldThrow(); |
726 |
|
} catch (TimeoutException success) { |
727 |
< |
} catch (Exception e) { |
728 |
< |
threadUnexpectedException(e); |
727 |
> |
} catch (Exception fail) { |
728 |
> |
threadUnexpectedException(fail); |
729 |
|
} finally { future.cancel(true); } |
730 |
|
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
731 |
|
} |
881 |
|
void sleep(long millis) { |
882 |
|
try { |
883 |
|
delay(millis); |
884 |
< |
} catch (InterruptedException ie) { |
884 |
> |
} catch (InterruptedException fail) { |
885 |
|
AssertionFailedError afe = |
886 |
|
new AssertionFailedError("Unexpected InterruptedException"); |
887 |
< |
afe.initCause(ie); |
887 |
> |
afe.initCause(fail); |
888 |
|
throw afe; |
889 |
|
} |
890 |
|
} |
976 |
|
void awaitTermination(Thread t, long timeoutMillis) { |
977 |
|
try { |
978 |
|
t.join(timeoutMillis); |
979 |
< |
} catch (InterruptedException ie) { |
980 |
< |
threadUnexpectedException(ie); |
979 |
> |
} catch (InterruptedException fail) { |
980 |
> |
threadUnexpectedException(fail); |
981 |
|
} finally { |
982 |
|
if (t.getState() != Thread.State.TERMINATED) { |
983 |
|
t.interrupt(); |
1003 |
|
public final void run() { |
1004 |
|
try { |
1005 |
|
realRun(); |
1006 |
< |
} catch (Throwable t) { |
1007 |
< |
threadUnexpectedException(t); |
1006 |
> |
} catch (Throwable fail) { |
1007 |
> |
threadUnexpectedException(fail); |
1008 |
|
} |
1009 |
|
} |
1010 |
|
} |
1058 |
|
threadShouldThrow("InterruptedException"); |
1059 |
|
} catch (InterruptedException success) { |
1060 |
|
threadAssertFalse(Thread.interrupted()); |
1061 |
< |
} catch (Throwable t) { |
1062 |
< |
threadUnexpectedException(t); |
1061 |
> |
} catch (Throwable fail) { |
1062 |
> |
threadUnexpectedException(fail); |
1063 |
|
} |
1064 |
|
} |
1065 |
|
} |
1070 |
|
public final T call() { |
1071 |
|
try { |
1072 |
|
return realCall(); |
1073 |
< |
} catch (Throwable t) { |
1074 |
< |
threadUnexpectedException(t); |
1073 |
> |
} catch (Throwable fail) { |
1074 |
> |
threadUnexpectedException(fail); |
1075 |
|
return null; |
1076 |
|
} |
1077 |
|
} |
1088 |
|
return result; |
1089 |
|
} catch (InterruptedException success) { |
1090 |
|
threadAssertFalse(Thread.interrupted()); |
1091 |
< |
} catch (Throwable t) { |
1092 |
< |
threadUnexpectedException(t); |
1091 |
> |
} catch (Throwable fail) { |
1092 |
> |
threadUnexpectedException(fail); |
1093 |
|
} |
1094 |
|
return null; |
1095 |
|
} |
1129 |
|
public void await(CountDownLatch latch) { |
1130 |
|
try { |
1131 |
|
assertTrue(latch.await(LONG_DELAY_MS, MILLISECONDS)); |
1132 |
< |
} catch (Throwable t) { |
1133 |
< |
threadUnexpectedException(t); |
1132 |
> |
} catch (Throwable fail) { |
1133 |
> |
threadUnexpectedException(fail); |
1134 |
|
} |
1135 |
|
} |
1136 |
|
|
1137 |
|
public void await(Semaphore semaphore) { |
1138 |
|
try { |
1139 |
|
assertTrue(semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS)); |
1140 |
< |
} catch (Throwable t) { |
1141 |
< |
threadUnexpectedException(t); |
1140 |
> |
} catch (Throwable fail) { |
1141 |
> |
threadUnexpectedException(fail); |
1142 |
|
} |
1143 |
|
} |
1144 |
|
|
1332 |
|
@Override protected final void compute() { |
1333 |
|
try { |
1334 |
|
realCompute(); |
1335 |
< |
} catch (Throwable t) { |
1336 |
< |
threadUnexpectedException(t); |
1335 |
> |
} catch (Throwable fail) { |
1336 |
> |
threadUnexpectedException(fail); |
1337 |
|
} |
1338 |
|
} |
1339 |
|
} |
1347 |
|
@Override protected final T compute() { |
1348 |
|
try { |
1349 |
|
return realCompute(); |
1350 |
< |
} catch (Throwable t) { |
1351 |
< |
threadUnexpectedException(t); |
1350 |
> |
} catch (Throwable fail) { |
1351 |
> |
threadUnexpectedException(fail); |
1352 |
|
return null; |
1353 |
|
} |
1354 |
|
} |
1372 |
|
public int await() { |
1373 |
|
try { |
1374 |
|
return super.await(2 * LONG_DELAY_MS, MILLISECONDS); |
1375 |
< |
} catch (TimeoutException e) { |
1375 |
> |
} catch (TimeoutException timedOut) { |
1376 |
|
throw new AssertionFailedError("timed out"); |
1377 |
< |
} catch (Exception e) { |
1377 |
> |
} catch (Exception fail) { |
1378 |
|
AssertionFailedError afe = |
1379 |
< |
new AssertionFailedError("Unexpected exception: " + e); |
1380 |
< |
afe.initCause(e); |
1379 |
> |
new AssertionFailedError("Unexpected exception: " + fail); |
1380 |
> |
afe.initCause(fail); |
1381 |
|
throw afe; |
1382 |
|
} |
1383 |
|
} |
1405 |
|
q.remove(); |
1406 |
|
shouldThrow(); |
1407 |
|
} catch (NoSuchElementException success) {} |
1408 |
< |
} catch (InterruptedException ie) { |
1412 |
< |
threadUnexpectedException(ie); |
1413 |
< |
} |
1408 |
> |
} catch (InterruptedException fail) { threadUnexpectedException(fail); } |
1409 |
|
} |
1410 |
|
|
1411 |
|
void assertSerialEquals(Object x, Object y) { |
1424 |
|
oos.flush(); |
1425 |
|
oos.close(); |
1426 |
|
return bos.toByteArray(); |
1427 |
< |
} catch (Throwable t) { |
1428 |
< |
threadUnexpectedException(t); |
1427 |
> |
} catch (Throwable fail) { |
1428 |
> |
threadUnexpectedException(fail); |
1429 |
|
return new byte[0]; |
1430 |
|
} |
1431 |
|
} |
1438 |
|
T clone = (T) ois.readObject(); |
1439 |
|
assertSame(o.getClass(), clone.getClass()); |
1440 |
|
return clone; |
1441 |
< |
} catch (Throwable t) { |
1442 |
< |
threadUnexpectedException(t); |
1441 |
> |
} catch (Throwable fail) { |
1442 |
> |
threadUnexpectedException(fail); |
1443 |
|
return null; |
1444 |
|
} |
1445 |
|
} |
1471 |
|
shouldThrow(); |
1472 |
|
} catch (NoSuchElementException success) {} |
1473 |
|
assertFalse(it.hasNext()); |
1474 |
< |
} |
1474 |
> |
} |
1475 |
|
} |