Class Waiter

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

public class Waiter extends Object
Waits on a test, carrying out assertions, until being resumed.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final ReentrantCircuit
     
    private Throwable
     
     
    private static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new Waiter.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    private String
    format(Object expected, Object actual)
     
    void
    Resumes the waiter when the expected number of resume() calls have occurred.
    void
    rethrow(Throwable failure)
    Rethrows the failure in the main test thread and in the current thread.
    private static void
     
    private static <T extends Throwable>
    void
     

    Methods inherited from class java.lang.Object

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

  • 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
      Throws:
      AssertionError - when the assertion fails
    • assertFalse

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

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

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

      public void assertTrue(boolean condition)
      Asserts that the condition is 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.
      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
    • fail

      public void fail(String reason)
      Fails the current test for the given reason.
      Throws:
      AssertionError
    • 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.
      Throws:
      AssertionError - wrapping the reason
    • rethrow

      public void rethrow(Throwable failure)
      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.
      Throws:
      Throwable - the failure
    • sneakyThrow

      private static void sneakyThrow(Throwable t)
    • sneakyThrow2

      private static <T extends Throwable> void sneakyThrow2(Throwable t) throws T
      Throws:
      T
    • format

      private String format(Object expected, Object actual)