public class AsyncVerifier
extends java.lang.Object
assert
or call to fail()
the main threads call to waitForTest()
will
throw an exception to indicate the test as a failure.
This class also provides a way to control the flow of a unit test by blocking main test thread
until signalComplete()
is called from the other thread.
Modifier and Type | Class and Description |
---|---|
static class |
AsyncVerifier.TestFailure
Exception to represent a failure in a test assertion.
|
Constructor and Description |
---|
AsyncVerifier()
Constructs a new
AsyncVerifier . |
Modifier and Type | Method and Description |
---|---|
void |
assertEquals(java.lang.Object o1,
java.lang.Object o2)
Verifies that the passed in values are equal using the o1.equals(o2) relationship.
|
void |
assertFalse(boolean condition)
Verifies that the passed in condition is false.
|
void |
assertNotNull(java.lang.Object o)
Verifies that the passed in object is not null.
|
void |
assertNull(java.lang.Object o)
Verifies that the passed in object is null.
|
void |
assertTrue(boolean condition)
Verifies that the passed in condition is true.
|
void |
fail()
Marks a failure with no cause.
|
void |
fail(java.lang.String message)
Marks a failure with a specified message.
|
void |
fail(java.lang.Throwable cause)
Marks a failure with a specified throwable cause.
|
void |
signalComplete()
Call to indicate that this thread has finished, and should notify the waiting main test
thread that the test may be complete.
|
void |
waitForTest()
Waits for a default of 10 seconds, or until signalComplete has been called once, or until a
failure occurs.
|
void |
waitForTest(long timeoutInMs)
Waits a specified amount of time, or until signalComplete has been called once, or until a
failure occurs.
|
void |
waitForTest(long timeoutInMs,
int signalCount)
Waits a specified amount of time, or until signalComplete has been called a specified amount
of times, or until a failure occurs.
|
public AsyncVerifier()
AsyncVerifier
.public void waitForTest() throws java.lang.InterruptedException, java.util.concurrent.TimeoutException
java.lang.InterruptedException
- Thrown if thread is interrupted while waitingjava.util.concurrent.TimeoutException
- Thrown if timeout occurs without signalComplete being calledpublic void waitForTest(long timeoutInMs) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException
timeoutInMs
- Timeout to wait for signalComplete action to occurjava.lang.InterruptedException
- Thrown if thread is interrupted while waitingjava.util.concurrent.TimeoutException
- Thrown if timeout occurs without signalComplete being calledpublic void waitForTest(long timeoutInMs, int signalCount) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException
If waitForTest()
is being called multiple times on the same instance, the
signalComplete count is NOT reset. So you must either create new instances, or pass in a
larger value for the expected signalComplete count.
timeoutInMs
- Timeout to wait for signalComplete action to occursignalCount
- Amount of signalComplete calls to expect before unblockingjava.lang.InterruptedException
- Thrown if thread is interrupted while waitingjava.util.concurrent.TimeoutException
- Thrown if timeout occurs without signalComplete being calledpublic void signalComplete()
public void assertTrue(boolean condition)
waitForTest()
.condition
- condition to verify is true
public void assertFalse(boolean condition)
waitForTest()
.condition
- condition to verify is false
public void assertNull(java.lang.Object o)
waitForTest()
.o
- Object to verify is null
public void assertNotNull(java.lang.Object o)
waitForTest()
.o
- Object to verify is not null
public void assertEquals(java.lang.Object o1, java.lang.Object o2)
waitForTest()
.o1
- First object to compare againsto2
- Second object to compare againstpublic void fail()
waitForTest()
.public void fail(java.lang.String message)
waitForTest()
.message
- Message to be provided in failure exceptionpublic void fail(java.lang.Throwable cause)
waitForTest()
.cause
- Throwable cause to be provided in failure exception