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 ReentrantCircuitprivate Throwableprivate AtomicIntegerprivate static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidassertEquals(Object expected, Object actual) Asserts that theexpectedvalues equals theactualvaluevoidassertFalse(boolean condition) Asserts that theconditionis false.voidassertNotNull(Object object) Asserts that theobjectis not null.voidassertNull(Object object) Asserts that theobjectis null.<T> voidassertThat(T actual, org.hamcrest.Matcher<? super T> matcher) Asserts thatactualsatisfies the condition specified bymatcher.voidassertTrue(boolean condition) Asserts that theconditionis true.voidawait()Waits untilresume()is called, or the test is failed.voidawait(long delay) Waits until thedelayhas elapsed,resume()is called, or the test is failed.voidawait(long delay, int expectedResumes) voidWaits until thedelayhas elapsed,resume()is called, or the test is failed.voidvoidfail()Fails the current test.voidFails the current test for the givenreason.voidFails the current test with the givenreason, sets the number of expected resumes to 0, and throws thereasonas anAssertionErrorin the main test thread and in the current thread.private Stringvoidresume()Resumes the waiter when the expected number ofresume()calls have occurred.voidRethrows thefailurein the main test thread and in the current thread.private static voidprivate 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 theexpectedvalues equals theactualvalue- Throws:
AssertionError- when the assertion fails
-
assertFalse
public void assertFalse(boolean condition) Asserts that theconditionis false.- Throws:
AssertionError- when the assertion fails
-
assertNotNull
Asserts that theobjectis not null.- Throws:
AssertionError- when the assertion fails
-
assertNull
Asserts that theobjectis null.- Throws:
AssertionError- when the assertion fails
-
assertTrue
public void assertTrue(boolean condition) Asserts that theconditionis true.- Throws:
AssertionError- when the assertion fails
-
assertThat
public <T> void assertThat(T actual, org.hamcrest.Matcher<? super T> matcher) Asserts thatactualsatisfies 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 thedelayhas 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 thedelayhas 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
-
fail
-
fail
Fails the current test with the givenreason, sets the number of expected resumes to 0, and throws thereasonas anAssertionErrorin the main test thread and in the current thread.- Throws:
AssertionError- wrapping thereason
-
rethrow
Rethrows thefailurein 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
-
format
-