Package net.jodah.concurrentunit
Class Waiter
java.lang.Object
net.jodah.concurrentunit.Waiter
Waits on a test, carrying out assertions, until being resumed.
Copyright 2010-2016 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License
Copyright 2010-2016 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License
- Author:
- Jonathan Halterman
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
assertEquals
(double expected, double actual, double delta) Asserts that theexpected
values equals theactual
value.void
assertEquals
(Object expected, Object actual) Asserts that theexpected
values equals theactual
value.void
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.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.
-
Constructor Details
-
Waiter
public Waiter()Creates a new Waiter.
-
-
Method Details
-
assertEquals
Asserts that theexpected
values equals theactual
value.- Parameters:
expected
- the expected valueactual
- the actual value- Throws:
AssertionError
- when the assertion fails
-
assertEquals
public void assertEquals(double expected, double actual, double delta) Asserts that theexpected
values equals theactual
value.- Parameters:
expected
- the expected valueactual
- the actual valuedelta
- the allowed tolerance- Throws:
AssertionError
- when the assertion fails
-
assertFalse
public void assertFalse(boolean condition) Asserts that thecondition
is false.- Parameters:
condition
- boolean to test to be false- Throws:
AssertionError
- when the assertion fails
-
assertNotNull
Asserts that theobject
is not null.- Parameters:
object
- the object to test- Throws:
AssertionError
- when the assertion fails
-
assertNull
Asserts that theobject
is null.- Parameters:
object
- the object to test- Throws:
AssertionError
- when the assertion fails
-
assertTrue
public void assertTrue(boolean condition) Asserts that thecondition
is true.- Parameters:
condition
- boolean to test to be 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
.- Type Parameters:
T
- the type of the actual- Parameters:
actual
- the value to testmatcher
- the condition- 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
- as a result of failure
-
fail
Fails the current test for the givenreason
.- Parameters:
reason
- the reason for failure- Throws:
AssertionError
- wrapping the reason
-
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.- Parameters:
reason
- the reason for failure- 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.- Parameters:
rethrownFailure
- the reason for failure throws Throwable thefailure
-