|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
JSR166TestCase
public class JSR166TestCase
Base class for JSR166 Junit TCK tests. Defines some constants, utility methods and classes, as well as a simple framework for helping to make sure that assertions failing in generated threads cause the associated test that generated them to itself fail (which JUnit does not otherwise arrange). The rules for creating such tests are:
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.
| Field Summary | |
|---|---|
static java.lang.Integer |
eight
|
protected static boolean |
expensiveTests
|
static java.lang.Integer |
five
|
static java.lang.Integer |
four
|
static long |
LONG_DELAY_MS
|
static java.lang.Integer |
m1
|
static java.lang.Integer |
m10
|
static java.lang.Integer |
m2
|
static java.lang.Integer |
m3
|
static java.lang.Integer |
m4
|
static java.lang.Integer |
m5
|
static java.lang.Integer |
m6
|
static long |
MEDIUM_DELAY_MS
|
static java.lang.Integer |
nine
|
static java.lang.Integer |
one
|
static java.lang.Integer |
seven
|
static long |
SHORT_DELAY_MS
|
static java.lang.Integer |
six
|
static int |
SIZE
The number of elements to place in collections, arrays, etc. |
static long |
SMALL_DELAY_MS
|
static java.lang.String |
TEST_STRING
|
static java.lang.Integer |
three
|
static java.lang.Integer |
two
|
static java.lang.Integer |
zero
|
| Constructor Summary | |
|---|---|
JSR166TestCase()
|
|
| Method Summary | |
|---|---|
void |
assertThreadJoinTimesOut(java.lang.Thread thread,
long timeoutMillis)
Checks that thread does not terminate within timeoutMillis milliseconds (that is, Thread.join times out). |
java.lang.Runnable |
awaiter(java.util.concurrent.CountDownLatch latch)
|
void |
checkEmpty(java.util.concurrent.BlockingQueue q)
|
static void |
delay(long ms)
Delays, via Thread.sleep for the given millisecond delay, but if the sleep is shorter than specified, may re-sleep or yield until time elapses. |
protected long |
getShortDelay()
Returns the shortest timed delay. |
void |
joinPool(java.util.concurrent.ExecutorService exec)
Waits out termination of a thread pool or fails doing so. |
java.util.concurrent.Callable<java.lang.String> |
latchAwaitingStringTask(java.util.concurrent.CountDownLatch latch)
|
static void |
main(java.lang.String[] args)
Runs all JSR166 unit tests using junit.textui.TestRunner |
static junit.framework.TestSuite |
newTestSuite(java.lang.Object... suiteOrClasses)
|
static java.security.Policy |
permissivePolicy()
Returns a policy containing all the permissions we ever need. |
java.lang.Runnable |
possiblyInterruptedRunnable(long timeoutMillis)
|
protected void |
runTest()
|
protected void |
runTestProfiled()
|
void |
runWithoutPermissions(java.lang.Runnable r)
Runs a runnable without any permissions. |
void |
runWithPermissions(java.lang.Runnable r,
java.security.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(java.lang.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(java.lang.Object x,
java.lang.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(java.lang.Object x)
Just like assertNull(x), but additionally recording (using threadRecordFailure) any AssertionFailedError thrown, so that the current testcase will fail. |
void |
threadAssertSame(java.lang.Object x,
java.lang.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(java.lang.String reason)
Just like fail(reason), but additionally recording (using threadRecordFailure) any AssertionFailedError thrown, so that the current testcase will fail. |
void |
threadRecordFailure(java.lang.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(java.lang.String exceptionName)
Calls threadFail with message "should throw" + exceptionName. |
void |
threadUnexpectedException(java.lang.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)
|
| Methods inherited from class junit.framework.TestCase |
|---|
countTestCases, createResult, getName, run, run, runBare, setName, toString |
| Methods inherited from class junit.framework.Assert |
|---|
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, fail, fail, failNotEquals, failNotSame, failSame, format |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
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 java.lang.Integer zero
public static final java.lang.Integer one
public static final java.lang.Integer two
public static final java.lang.Integer three
public static final java.lang.Integer four
public static final java.lang.Integer five
public static final java.lang.Integer six
public static final java.lang.Integer seven
public static final java.lang.Integer eight
public static final java.lang.Integer nine
public static final java.lang.Integer m1
public static final java.lang.Integer m2
public static final java.lang.Integer m3
public static final java.lang.Integer m4
public static final java.lang.Integer m5
public static final java.lang.Integer m6
public static final java.lang.Integer m10
public static final java.lang.String TEST_STRING
| Constructor Detail |
|---|
public JSR166TestCase()
| Method Detail |
|---|
protected void runTest()
throws java.lang.Throwable
runTest in class junit.framework.TestCasejava.lang.Throwable
protected void runTestProfiled()
throws java.lang.Throwable
java.lang.Throwablepublic static void main(java.lang.String[] args)
public static junit.framework.TestSuite newTestSuite(java.lang.Object... suiteOrClasses)
public static junit.framework.Test suite()
protected long getShortDelay()
protected void setDelays()
public void threadRecordFailure(java.lang.Throwable t)
public void setUp()
setUp in class junit.framework.TestCase
public void tearDown()
throws java.lang.Exception
tearDown in class junit.framework.TestCasejava.lang.Exceptionpublic void threadFail(java.lang.String reason)
public void threadAssertTrue(boolean b)
public void threadAssertFalse(boolean b)
public void threadAssertNull(java.lang.Object x)
public void threadAssertEquals(long x,
long y)
public void threadAssertEquals(java.lang.Object x,
java.lang.Object y)
public void threadAssertSame(java.lang.Object x,
java.lang.Object y)
public void threadShouldThrow()
public void threadShouldThrow(java.lang.String exceptionName)
public void threadUnexpectedException(java.lang.Throwable t)
threadRecordFailure(java.lang.Throwable),
then rethrows the exception, wrapping it in an
AssertionFailedError if necessary.
public static void delay(long ms)
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic void joinPool(java.util.concurrent.ExecutorService exec)
public void assertThreadJoinTimesOut(java.lang.Thread thread,
long timeoutMillis)
public void shouldThrow()
public void shouldThrow(java.lang.String exceptionName)
public void runWithPermissions(java.lang.Runnable r,
java.security.Permission... permissions)
public void runWithoutPermissions(java.lang.Runnable r)
public static java.security.Policy permissivePolicy()
public java.util.concurrent.Callable<java.lang.String> latchAwaitingStringTask(java.util.concurrent.CountDownLatch latch)
public java.lang.Runnable awaiter(java.util.concurrent.CountDownLatch latch)
public java.lang.Runnable possiblyInterruptedRunnable(long timeoutMillis)
public static JSR166TestCase.TrackedRunnable trackedRunnable(long timeoutMillis)
public void checkEmpty(java.util.concurrent.BlockingQueue q)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||