public class JSR166TestCase
extends TestCase
threadFail(java.lang.String)
, threadAssertTrue(boolean)
, threadAssertEquals(long, long)
, or threadAssertNull(java.lang.Object)
, (not
fail
, assertTrue
, etc.) It is OK (but not
particularly recommended) for other code to use these forms too.
Only the most typically used JUnit assertion methods are defined
this way, but enough to live with.
setUp()
or tearDown()
, make sure
to invoke super.setUp
and super.tearDown
within
them. These methods are used to clear and check for thread
assertion failures.
SHORT_DELAY_MS
, SMALL_DELAY_MS
, MEDIUM_DELAY_MS
,
LONG_DELAY_MS
. The idea here is that a SHORT is always
discriminable from zero time, and always allows enough time for the
small amounts of computation (creating a thread, calling a few
methods, etc) needed to reach a timeout point. Similarly, a SMALL
is always discriminable as larger than SHORT and smaller than
MEDIUM. And so on. These constants are set to conservative values,
but even so, if there is ever any doubt, they can all be increased
in one spot to rerun tests on slower platforms.
fail
to do so) before returning from the
method. The joinPool
method can be used to do this when
using Executors.
Other notes
main
of this class (JSR166TestCase)
runs all JSR166 unit tests.
Modifier and Type | Field and Description |
---|---|
static Integer |
eight |
protected static boolean |
expensiveTests |
static Integer |
five |
static Integer |
four |
static double |
JAVA_CLASS_VERSION |
static String |
JAVA_SPECIFICATION_VERSION |
static long |
LONG_DELAY_MS |
static Integer |
m1 |
static Integer |
m10 |
static Integer |
m2 |
static Integer |
m3 |
static Integer |
m4 |
static Integer |
m5 |
static Integer |
m6 |
static long |
MEDIUM_DELAY_MS |
static Integer |
nine |
static Integer |
one |
static Integer |
seven |
static long |
SHORT_DELAY_MS |
static Integer |
six |
static int |
SIZE
The number of elements to place in collections, arrays, etc.
|
static long |
SMALL_DELAY_MS |
static String |
TEST_STRING |
protected static boolean |
testImplementationDetails
If true, also run tests that are not part of the official tck
because they test unspecified implementation details.
|
static Integer |
three |
static Integer |
two |
static Integer |
zero |
Constructor and Description |
---|
JSR166TestCase() |
JSR166TestCase(String name) |
Modifier and Type | Method and Description |
---|---|
static void |
addNamedTestClasses(TestSuite suite,
String... testClassNames) |
void |
assertIteratorExhausted(Iterator<?> it) |
void |
assertThrows(Class<? extends Throwable> expectedExceptionClass,
Runnable... throwingActions) |
static boolean |
atLeastJava10() |
static boolean |
atLeastJava6() |
static boolean |
atLeastJava7() |
static boolean |
atLeastJava8() |
static boolean |
atLeastJava9() |
void |
await(CountDownLatch latch) |
void |
await(CountDownLatch latch,
long timeoutMillis) |
void |
await(Semaphore semaphore) |
jsr166.JSR166TestCase.LatchAwaiter |
awaiter(CountDownLatch latch) |
Runnable |
countDowner(CountDownLatch latch) |
protected long |
getShortDelay()
Returns the shortest timed delay.
|
static <ExtraData> |
jdk8ParameterizedTestSuite(Class<? extends JSR166TestCase> testClass,
Class<ExtraData> dataClass,
ExtraData data)
Returns junit-style testSuite for the jdk8 extension of the
given test class, but parameterized by passing extra data to
each test.
|
Callable<String> |
latchAwaitingStringTask(CountDownLatch latch) |
static TestSuite |
newTestSuite(Object... suiteOrClasses)
Runs all unit tests in the given test suite.
|
static <ExtraData> |
parameterizedTestSuite(Class<? extends JSR166TestCase> testClass,
Class<ExtraData> dataClass,
ExtraData data)
Returns junit-style testSuite for the given test class, but
parameterized by passing extra data to each test.
|
static Policy |
permissivePolicy()
Returns a policy containing all the permissions we ever need.
|
Runnable |
possiblyInterruptedRunnable(long timeoutMillis) |
void |
runBare() |
protected void |
runTest() |
protected void |
runTestProfiled() |
void |
runWithoutPermissions(Runnable r)
Runs a runnable without any permissions.
|
void |
runWithPermissions(Runnable r,
Permission... permissions)
Runs Runnable r with a security policy that permits precisely
the specified permissions.
|
void |
runWithSecurityManagerWithPermissions(Runnable r,
Permission... permissions)
Runs Runnable r with a security policy that permits precisely
the specified permissions.
|
protected void |
setDelays()
Sets delays as multiples of SHORT_DELAY.
|
void |
setUp() |
void |
shouldThrow()
Fails with message "should throw exception".
|
void |
shouldThrow(String exceptionName)
Fails with message "should throw " + exceptionName.
|
void |
tearDown()
Extra checks that get done for all test cases.
|
static ArrayList<String> |
testMethodNames(Class<?> testClass)
Returns list of junit-style test method names in given class.
|
void |
threadAssertEquals(long x,
long y)
Just like assertEquals(x, y), but additionally recording (using
threadRecordFailure) any AssertionFailedError thrown, so that
the current testcase will fail.
|
void |
threadAssertEquals(Object x,
Object y)
Just like assertEquals(x, y), but additionally recording (using
threadRecordFailure) any AssertionFailedError thrown, so that
the current testcase will fail.
|
void |
threadAssertFalse(boolean b)
Just like assertFalse(b), but additionally recording (using
threadRecordFailure) any AssertionFailedError thrown, so that
the current testcase will fail.
|
void |
threadAssertNull(Object x)
Just like assertNull(x), but additionally recording (using
threadRecordFailure) any AssertionFailedError thrown, so that
the current testcase will fail.
|
void |
threadAssertSame(Object x,
Object y)
Just like assertSame(x, y), but additionally recording (using
threadRecordFailure) any AssertionFailedError thrown, so that
the current testcase will fail.
|
void |
threadAssertTrue(boolean b)
Just like assertTrue(b), but additionally recording (using
threadRecordFailure) any AssertionFailedError thrown, so that
the current testcase will fail.
|
void |
threadFail(String reason)
Just like fail(reason), but additionally recording (using
threadRecordFailure) any AssertionFailedError thrown, so that
the current testcase will fail.
|
void |
threadRecordFailure(Throwable t)
Records an exception so that it can be rethrown later in the test
harness thread, triggering a test case failure.
|
void |
threadShouldThrow()
Calls threadFail with message "should throw exception".
|
void |
threadShouldThrow(String exceptionName)
Calls threadFail with message "should throw" + exceptionName.
|
void |
threadUnexpectedException(Throwable t)
Records the given exception using
threadRecordFailure(java.lang.Throwable) ,
then rethrows the exception, wrapping it in an
AssertionFailedError if necessary. |
static JSR166TestCase.TrackedRunnable |
trackedRunnable(long timeoutMillis) |
protected static final boolean expensiveTests
protected static final boolean testImplementationDetails
public static final double JAVA_CLASS_VERSION
public static final String JAVA_SPECIFICATION_VERSION
public static long SHORT_DELAY_MS
public static long SMALL_DELAY_MS
public static long MEDIUM_DELAY_MS
public static long LONG_DELAY_MS
public static final int SIZE
public static final Integer zero
public static final Integer one
public static final Integer two
public static final Integer three
public static final Integer four
public static final Integer five
public static final Integer six
public static final Integer seven
public static final Integer eight
public static final Integer nine
public static final Integer m1
public static final Integer m2
public static final Integer m3
public static final Integer m4
public static final Integer m5
public static final Integer m6
public static final Integer m10
public static final String TEST_STRING
public JSR166TestCase()
public JSR166TestCase(String name)
public static TestSuite newTestSuite(Object... suiteOrClasses)
public static void addNamedTestClasses(TestSuite suite, String... testClassNames)
public static boolean atLeastJava6()
public static boolean atLeastJava7()
public static boolean atLeastJava8()
public static boolean atLeastJava9()
public static boolean atLeastJava10()
public static ArrayList<String> testMethodNames(Class<?> testClass)
public static <ExtraData> Test parameterizedTestSuite(Class<? extends JSR166TestCase> testClass, Class<ExtraData> dataClass, ExtraData data)
public static <ExtraData> Test jdk8ParameterizedTestSuite(Class<? extends JSR166TestCase> testClass, Class<ExtraData> dataClass, ExtraData data)
protected long getShortDelay()
protected void setDelays()
public void threadRecordFailure(Throwable t)
public void setUp()
public void tearDown() throws Exception
Exception
public void threadFail(String reason)
public void threadAssertTrue(boolean b)
public void threadAssertFalse(boolean b)
public void threadAssertNull(Object x)
public void threadAssertEquals(long x, long y)
public void threadAssertEquals(Object x, Object y)
public void threadAssertSame(Object x, Object y)
public void threadShouldThrow()
public void threadShouldThrow(String exceptionName)
public void threadUnexpectedException(Throwable t)
threadRecordFailure(java.lang.Throwable)
,
then rethrows the exception, wrapping it in an
AssertionFailedError if necessary.public void shouldThrow()
public void shouldThrow(String exceptionName)
public void runWithPermissions(Runnable r, Permission... permissions)
public void runWithSecurityManagerWithPermissions(Runnable r, Permission... permissions)
public void runWithoutPermissions(Runnable r)
public static Policy permissivePolicy()
public Callable<String> latchAwaitingStringTask(CountDownLatch latch)
public Runnable countDowner(CountDownLatch latch)
public jsr166.JSR166TestCase.LatchAwaiter awaiter(CountDownLatch latch)
public void await(CountDownLatch latch, long timeoutMillis)
public void await(CountDownLatch latch)
public void await(Semaphore semaphore)
public Runnable possiblyInterruptedRunnable(long timeoutMillis)
public static JSR166TestCase.TrackedRunnable trackedRunnable(long timeoutMillis)
public void assertThrows(Class<? extends Throwable> expectedExceptionClass, Runnable... throwingActions)
public void assertIteratorExhausted(Iterator<?> it)