Class StreamAsserts

java.lang.Object
com.totvs.tjf.test.support.StreamAsserts

public final class StreamAsserts extends Object
Asserts helper to validates collector queues using a fluent api.
  • Method Summary

    Modifier and Type
    Method
    Description
    assertThatQueue(BlockingQueue<org.springframework.messaging.Message<?>> queue)
    Creates an instance of StreamAsserts to assert the supplied queue.
    protected String
    getMessageTypes(Collection<org.springframework.messaging.Message<?>> messages)
    Concatenate the messages types to be displayed in the assertions.
    protected String
    getType(org.springframework.messaging.Message<?> message)
    Lookup for the message type in the Message header.
    has(int total)
    Assert that the queue of expected Message is empty, otherwise, fails.
    void
    Assert that the queue of expected Message is empty, otherwise, fails.
    protected void
    validate(String expected, String actual)
    Assert that expected and actual are equal.
    void
    withType(Class<?> type)
    Assert that the supplied class type is the same type of the Message.
    void
    Assert that the supplied type is the same type of the Message.
    void
    withTypes(Class<?>... types)
    Assert that the supplied class type is the same types of the Message in the queue.
    void
    withTypes(String... types)
    Assert that the supplied class type is the same types of the Message in the queue.

    Methods inherited from class java.lang.Object

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

    • assertThatQueue

      public static StreamAsserts assertThatQueue(BlockingQueue<org.springframework.messaging.Message<?>> queue)
      Creates an instance of StreamAsserts to assert the supplied queue.
      Parameters:
      queue - to be asserted.
      Returns:
      instance of StreamAsserts.
    • isEmpty

      public void isEmpty()
      Assert that the queue of expected Message is empty, otherwise, fails.
    • has

      public StreamAsserts has(int total)
      Assert that the queue of expected Message is empty, otherwise, fails.
      Parameters:
      total - of messages expected.
      Returns:
      itself.
    • withType

      public void withType(Class<?> type)
      Assert that the supplied class type is the same type of the Message.

      When supplied the class type the assertions considerer the class simple name as the message type to be expected.

      Note: When looking for a single type, only the first Message in the queue is considered.

      Parameters:
      type - class to be expected.
    • withType

      public void withType(String type)
      Assert that the supplied type is the same type of the Message.

      Note: When looking for a single type, only the first Message in the queue is considered.

      Parameters:
      type - to be expected.
    • withTypes

      public void withTypes(Class<?>... types)
      Assert that the supplied class type is the same types of the Message in the queue.

      When supplied the class type the assertions considerer the class simple name as the message type to be expected.

      Note: The assertion expect the supplied types still in the same order as the Message was published in the queue.

      Parameters:
      types - to be expected.
    • withTypes

      public void withTypes(String... types)
      Assert that the supplied class type is the same types of the Message in the queue.

      Note: The assertion expect the supplied types still in the same order as the Message was published in the queue.

      Parameters:
      types - to be expected.
    • validate

      protected void validate(String expected, String actual)
      Assert that expected and actual are equal.

      If both are null, they are considered equal.

    • getType

      protected String getType(org.springframework.messaging.Message<?> message)
      Lookup for the message type in the Message header.

      Note: the header type obeys the following sequence of headers to lookup for:

      • cloudEvents:type
      • type
      Parameters:
      message - to be verified.
      Returns:
      the type specified in the Message header.
    • getMessageTypes

      protected String getMessageTypes(Collection<org.springframework.messaging.Message<?>> messages)
      Concatenate the messages types to be displayed in the assertions.
      Parameters:
      messages - to lookup for the types.
      Returns:
      the concatenated types found in the queue.