Class MockTransport

java.lang.Object
com.framed.core.remote.MockTransport
All Implemented Interfaces:
Transport

public class MockTransport extends Object implements Transport
A mock implementation of the Transport interface for testing purposes.

This class simulates message sending and publishing without actual network communication. It stores sent messages in memory and immediately dispatches them to registered handlers.

Features:

  • Constructor Details

    • MockTransport

      public MockTransport()
  • Method Details

    • send

      public void send(String host, int port, String address, Object message)
      Simulates sending a message to a specific host and port. Adds the message to sentMessages and dispatches it to registered handlers.
      Specified by:
      send in interface Transport
      Parameters:
      host - the target host (ignored in mock)
      port - the target port (ignored in mock)
      address - the logical address for the message
      message - the message to send
    • publish

      public void publish(String host, int port, String address, Object message)
      Simulates publishing a message to all subscribers of the specified address. Adds the message to sentMessages and dispatches it to registered handlers.
      Specified by:
      publish in interface Transport
      Parameters:
      host - the target host (ignored in mock)
      port - the target port (ignored in mock)
      address - the logical address for the message
      message - the message to broadcast
    • start

      public void start()
      No-op for mock implementation.
      Specified by:
      start in interface Transport
    • shutdown

      public void shutdown()
      No-op for mock implementation.
      Specified by:
      shutdown in interface Transport
    • register

      public void register(String address, Consumer<Object> handler)
      Registers a handler for messages received on the specified address.
      Specified by:
      register in interface Transport
      Parameters:
      address - the address to listen on
      handler - the handler to process messages
    • getSentMessages

      public List<String> getSentMessages()
      Returns the list of sent and published messages for verification.
      Returns:
      a list of message logs in the format "SEND:address:message" or "PUBLISH:address:message"