Package net.jodah.concurrentunit
Class Waiter
java.lang.Object
net.jodah.concurrentunit.Waiter
Waits on a test, carrying out assertions, until being resumed.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ReentrantCircuit
private Throwable
private AtomicInteger
private static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
assertEquals
(Object expected, Object actual) Asserts that theexpected
values equals theactual
valuevoid
assertFalse
(boolean condition) Asserts that thecondition
is false.void
assertNotNull
(Object object) Asserts that theobject
is not null.void
assertNull
(Object object) Asserts that theobject
is null.<T> void
assertThat
(T actual, org.hamcrest.Matcher<? super T> matcher) Asserts thatactual
satisfies the condition specified bymatcher
.void
assertTrue
(boolean condition) Asserts that thecondition
is true.void
await()
Waits untilresume()
is called, or the test is failed.void
await
(long delay) Waits until thedelay
has elapsed,resume()
is called, or the test is failed.void
await
(long delay, int expectedResumes) void
Waits until thedelay
has elapsed,resume()
is called, or the test is failed.void
void
fail()
Fails the current test.void
Fails the current test for the givenreason
.void
Fails the current test with the givenreason
, sets the number of expected resumes to 0, and throws thereason
as anAssertionError
in the main test thread and in the current thread.private String
void
resume()
Resumes the waiter when the expected number ofresume()
calls have occurred.void
Rethrows thefailure
in the main test thread and in the current thread.private static void
private static <T extends Throwable>
void
-
Field Details
-
TIMEOUT_MESSAGE
- See Also:
-
remainingResumes
-
circuit
-
failure
-
-
Constructor Details
-
Waiter
public Waiter()Creates a new Waiter.
-
-
Method Details
-
assertEquals
Asserts that theexpected
values equals theactual
value- Throws:
AssertionError
- when the assertion fails
-
assertFalse
public void assertFalse(boolean condition) Asserts that thecondition
is false.- Throws:
AssertionError
- when the assertion fails
-
assertNotNull
Asserts that theobject
is not null.- Throws:
AssertionError
- when the assertion fails
-
assertNull
Asserts that theobject
is null.- Throws:
AssertionError
- when the assertion fails
-
assertTrue
public void assertTrue(boolean condition) Asserts that thecondition
is true.- Throws:
AssertionError
- when the assertion fails
-
assertThat
public <T> void assertThat(T actual, org.hamcrest.Matcher<? super T> matcher) Asserts thatactual
satisfies the condition specified bymatcher
.- Throws:
AssertionError
- when the assertion fails
-
await
Waits untilresume()
is called, or the test is failed.- Throws:
TimeoutException
- if the operation times out while waitingInterruptedException
- if the operations is interrupted while waitingAssertionError
- if any assertion fails while waiting
-
await
Waits until thedelay
has elapsed,resume()
is called, or the test is failed.- Parameters:
delay
- Delay to wait in milliseconds- Throws:
TimeoutException
- if the operation times out while waitingInterruptedException
- if the operations is interrupted while waitingAssertionError
- if any assertion fails while waiting
-
await
Waits until thedelay
has elapsed,resume()
is called, or the test is failed.- Parameters:
delay
- Delay to wait fortimeUnit
- TimeUnit to delay for- Throws:
TimeoutException
- if the operation times out while waitingInterruptedException
- if the operations is interrupted while waitingAssertionError
- if any assertion fails while waiting
-
await
- Parameters:
delay
- Delay to wait for in millisecondsexpectedResumes
- Number of timesresume()
is expected to be called before the awaiting thread is resumed- Throws:
TimeoutException
- if the operation times out while waitingInterruptedException
- if the operations is interrupted while waitingAssertionError
- if any assertion fails while waiting
-
await
public void await(long delay, TimeUnit timeUnit, int expectedResumes) throws TimeoutException, InterruptedException - Parameters:
delay
- Delay to wait fortimeUnit
- TimeUnit to delay forexpectedResumes
- Number of timesresume()
is expected to be called before the awaiting thread is resumed- Throws:
TimeoutException
- if the operation times out while waitingInterruptedException
- if the operations is interrupted while waitingAssertionError
- if any assertion fails while waiting
-
resume
public void resume()Resumes the waiter when the expected number ofresume()
calls have occurred. -
fail
public void fail()Fails the current test.- Throws:
AssertionError
-
fail
Fails the current test for the givenreason
.- Throws:
AssertionError
-
fail
Fails the current test with the givenreason
, sets the number of expected resumes to 0, and throws thereason
as anAssertionError
in the main test thread and in the current thread.- Throws:
AssertionError
- wrapping thereason
-
rethrow
Rethrows thefailure
in the main test thread and in the current thread. Differs fromfail(Throwable)
which wraps a failure in an AssertionError before throwing.- Throws:
Throwable
- thefailure
-
sneakyThrow
-
sneakyThrow2
- Throws:
T
-
format
-