Class MockMessageHandler

All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>, Aware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Ordered, ExpressionCapable, Orderable, MessageProducer, HeaderPropagationAware, IntegrationPattern, NamedComponent, IntegrationManagement, TrackableComponent, MessageHandler, reactor.core.CoreSubscriber<Message<?>>

public class MockMessageHandler extends AbstractMessageProducingHandler
The AbstractMessageProducingHandler extension for the mocking purpose in tests.

The provided Consumers and Functions are applied to the incoming messages one at a time until the last, which is applied for all subsequent messages. The similar behavior exists in the Mockito.doReturn(Object toBeReturned, Object... toBeReturnedNext).

Typically is used as a chain of stub actions:

 
      MockIntegration.mockMessageHandler()
               .handleNext(...)
               .handleNext(...)
               .handleNextAndReply(...)
               .handleNextAndReply(...)
               .handleNext(...)
               .handleNextAndReply(...);
 
 
Since:
5.0
Author:
Artem Bilan, Christian Tzolov
  • Field Details

    • messageFunctions

      protected final List<Function<Message<?>,?>> messageFunctions
    • lastFunction

      protected Function<Message<?>,?> lastFunction
    • hasReplies

      protected boolean hasReplies
  • Constructor Details

    • MockMessageHandler

      protected MockMessageHandler(org.mockito.ArgumentCaptor<Message<?>> messageArgumentCaptor)
  • Method Details

    • handleNext

      public MockMessageHandler handleNext(Consumer<Message<?>> nextMessageConsumer)
      Add the Consumer to the stack to handle the next incoming message.
      Parameters:
      nextMessageConsumer - the Consumer to handle the next incoming message.
      Returns:
      this
    • handleNextAndReply

      public MockMessageHandler handleNextAndReply(Function<Message<?>,?> nextMessageFunction)
      Add the Function to the stack to handle the next incoming message and produce reply for it.
      Parameters:
      nextMessageFunction - the Function to handle the next incoming message.
      Returns:
      this
    • handleMessageInternal

      protected void handleMessageInternal(Message<?> message)
      Specified by:
      handleMessageInternal in class AbstractMessageHandler