Class Waiter

java.lang.Object
net.jodah.concurrentunit.Waiter

public class Waiter extends Object
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
Author:
Jonathan Halterman
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new Waiter.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    assertEquals(double expected, double actual, double delta)
    Asserts that the expected values equals the actual value.
    void
    assertEquals(Object expected, Object actual)
    Asserts that the expected values equals the actual value.
    void
    assertFalse(boolean condition)
    Asserts that the condition is false.
    void
    Asserts that the object is not null.
    void
    Asserts that the object is null.
    <T> void
    assertThat(T actual, org.hamcrest.Matcher<? super T> matcher)
    Asserts that actual satisfies the condition specified by matcher.
    void
    assertTrue(boolean condition)
    Asserts that the condition is true.
    void
    Waits until resume() is called, or the test is failed.
    void
    await(long delay)
    Waits until the delay has elapsed, resume() is called, or the test is failed.
    void
    await(long delay, int expectedResumes)
    Waits until the delay has elapsed, resume() is called expectedResumes times, or the test is failed.
    void
    await(long delay, TimeUnit timeUnit)
    Waits until the delay has elapsed, resume() is called, or the test is failed.
    void
    await(long delay, TimeUnit timeUnit, int expectedResumes)
    Waits until the delay has elapsed, resume() is called expectedResumes times, or the test is failed.
    void
    Fails the current test.
    void
    fail(String reason)
    Fails the current test for the given reason.
    void
    fail(Throwable reason)
    Fails the current test with the given reason, sets the number of expected resumes to 0, and throws the reason as an AssertionError in the main test thread and in the current thread.
    void
    Resumes the waiter when the expected number of resume() calls have occurred.
    void
    rethrow(Throwable rethrownFailure)
    Rethrows the failure in the main test thread and in the current thread.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Waiter

      public Waiter()
      Creates a new Waiter.
  • Method Details

    • assertEquals

      public void assertEquals(Object expected, Object actual)
      Asserts that the expected values equals the actual value.
      Parameters:
      expected - the expected value
      actual - the actual value
      Throws:
      AssertionError - when the assertion fails
    • assertEquals

      public void assertEquals(double expected, double actual, double delta)
      Asserts that the expected values equals the actual value.
      Parameters:
      expected - the expected value
      actual - the actual value
      delta - the allowed tolerance
      Throws:
      AssertionError - when the assertion fails
    • assertFalse

      public void assertFalse(boolean condition)
      Asserts that the condition is false.
      Parameters:
      condition - boolean to test to be false
      Throws:
      AssertionError - when the assertion fails
    • assertNotNull

      public void assertNotNull(Object object)
      Asserts that the object is not null.
      Parameters:
      object - the object to test
      Throws:
      AssertionError - when the assertion fails
    • assertNull

      public void assertNull(Object object)
      Asserts that the object is null.
      Parameters:
      object - the object to test
      Throws:
      AssertionError - when the assertion fails
    • assertTrue

      public void assertTrue(boolean condition)
      Asserts that the condition 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 that actual satisfies the condition specified by matcher.
      Type Parameters:
      T - the type of the actual
      Parameters:
      actual - the value to test
      matcher - the condition
      Throws:
      AssertionError - when the assertion fails
    • await

      public void await() throws TimeoutException, InterruptedException
      Waits until resume() is called, or the test is failed.
      Throws:
      TimeoutException - if the operation times out while waiting
      InterruptedException - if the operations is interrupted while waiting
      AssertionError - if any assertion fails while waiting
    • await

      public void await(long delay) throws TimeoutException, InterruptedException
      Waits until the delay 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 waiting
      InterruptedException - if the operations is interrupted while waiting
      AssertionError - if any assertion fails while waiting
    • await

      public void await(long delay, TimeUnit timeUnit) throws TimeoutException, InterruptedException
      Waits until the delay has elapsed, resume() is called, or the test is failed.
      Parameters:
      delay - Delay to wait for
      timeUnit - TimeUnit to delay for
      Throws:
      TimeoutException - if the operation times out while waiting
      InterruptedException - if the operations is interrupted while waiting
      AssertionError - if any assertion fails while waiting
    • await

      public void await(long delay, int expectedResumes) throws TimeoutException, InterruptedException
      Waits until the delay has elapsed, resume() is called expectedResumes times, or the test is failed.
      Parameters:
      delay - Delay to wait for in milliseconds
      expectedResumes - Number of times resume() is expected to be called before the awaiting thread is resumed
      Throws:
      TimeoutException - if the operation times out while waiting
      InterruptedException - if the operations is interrupted while waiting
      AssertionError - if any assertion fails while waiting
    • await

      public void await(long delay, TimeUnit timeUnit, int expectedResumes) throws TimeoutException, InterruptedException
      Waits until the delay has elapsed, resume() is called expectedResumes times, or the test is failed.
      Parameters:
      delay - Delay to wait for
      timeUnit - TimeUnit to delay for
      expectedResumes - Number of times resume() is expected to be called before the awaiting thread is resumed
      Throws:
      TimeoutException - if the operation times out while waiting
      InterruptedException - if the operations is interrupted while waiting
      AssertionError - if any assertion fails while waiting
    • resume

      public void resume()
      Resumes the waiter when the expected number of resume() calls have occurred.
    • fail

      public void fail()
      Fails the current test.
      Throws:
      AssertionError - as a result of failure
    • fail

      public void fail(String reason)
      Fails the current test for the given reason.
      Parameters:
      reason - the reason for failure
      Throws:
      AssertionError - wrapping the reason
    • fail

      public void fail(Throwable reason)
      Fails the current test with the given reason, sets the number of expected resumes to 0, and throws the reason as an AssertionError in the main test thread and in the current thread.
      Parameters:
      reason - the reason for failure
      Throws:
      AssertionError - wrapping the reason
    • rethrow

      public void rethrow(Throwable rethrownFailure)
      Rethrows the failure in the main test thread and in the current thread. Differs from fail(Throwable) which wraps a failure in an AssertionError before throwing.
      Parameters:
      rethrownFailure - the reason for failure throws Throwable the failure