public class JSR166TestCase
extends junit.framework.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 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 |
static Integer |
three |
static Integer |
two |
static Integer |
zero |
Constructor and Description |
---|
JSR166TestCase() |
Modifier and Type | Method and Description |
---|---|
Runnable |
awaiter(CountDownLatch latch) |
void |
checkEmpty(BlockingQueue q) |
protected long |
getShortDelay()
Returns the shortest timed delay.
|
void |
joinPool(ExecutorService exec)
Waits out termination of a thread pool or fails doing so.
|
Callable<String> |
latchAwaitingStringTask(CountDownLatch latch) |
static void |
main(String[] args)
Runs all JSR166 unit tests using junit.textui.TestRunner
|
static junit.framework.TestSuite |
newTestSuite(Object... suiteOrClasses) |
static Policy |
permissivePolicy()
Returns a policy containing all the permissions we ever need.
|
Runnable |
possiblyInterruptedRunnable(long timeoutMillis) |
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.
|
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.
|
static junit.framework.Test |
suite()
Collects all JSR166 unit tests as one suite.
|
void |
tearDown()
Triggers test case failure if any thread assertions have failed,
by rethrowing, in the test harness thread, any exception recorded
earlier by threadRecordFailure.
|
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) |
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, setName, toString
protected static final boolean expensiveTests
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
protected void runTest() throws Throwable
runTest
in class junit.framework.TestCase
Throwable
public static void main(String[] args)
public static junit.framework.TestSuite newTestSuite(Object... suiteOrClasses)
public static junit.framework.Test suite()
protected long getShortDelay()
protected void setDelays()
public void threadRecordFailure(Throwable t)
public void setUp()
setUp
in class junit.framework.TestCase
public void tearDown() throws Exception
tearDown
in class junit.framework.TestCase
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 joinPool(ExecutorService exec)
public void shouldThrow()
public void shouldThrow(String exceptionName)
public void runWithPermissions(Runnable r, Permission... permissions)
public void runWithoutPermissions(Runnable r)
public static Policy permissivePolicy()
public Callable<String> latchAwaitingStringTask(CountDownLatch latch)
public Runnable awaiter(CountDownLatch latch)
public Runnable possiblyInterruptedRunnable(long timeoutMillis)
public static JSR166TestCase.TrackedRunnable trackedRunnable(long timeoutMillis)
public void checkEmpty(BlockingQueue q)
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.