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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidassertEquals(double expected, double actual, double delta) Asserts that theexpectedvalues equals theactualvalue.voidassertEquals(Object expected, Object actual) Asserts that theexpectedvalues equals theactualvalue.voidassertFalse(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.voidresume()Resumes the waiter when the expected number ofresume()calls have occurred.voidRethrows thefailurein the main test thread and in the current thread.
-
Constructor Details
-
Waiter
public Waiter()Creates a new Waiter.
-
-
Method Details
-
assertEquals
Asserts that theexpectedvalues equals theactualvalue.- 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 theexpectedvalues equals theactualvalue.- 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 theconditionis false.- Parameters:
condition- boolean to test to be false- Throws:
AssertionError- when the assertion fails
-
assertNotNull
Asserts that theobjectis not null.- Parameters:
object- the object to test- Throws:
AssertionError- when the assertion fails
-
assertNull
Asserts that theobjectis null.- Parameters:
object- the object to test- Throws:
AssertionError- when the assertion fails
-
assertTrue
public void assertTrue(boolean condition) Asserts that theconditionis 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 thatactualsatisfies 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 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
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 thereasonas anAssertionErrorin the main test thread and in the current thread.- Parameters:
reason- the reason for failure- 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.- Parameters:
rethrownFailure- the reason for failure throws Throwable thefailure
-