Class StubClient

  • All Implemented Interfaces:
    com.spotify.apollo.Client, Closeable, AutoCloseable

    public class StubClient
    extends Object
    implements com.spotify.apollo.Client, Closeable
    A stub (http://www.martinfowler.com/articles/mocksArentStubs.html) client that allows you to preconfigure responses to certain messages, as well as verify whether expected messages are sent. When evaluating how to respond, request/response mapping rules are evaluated in the order they were added. Use the clear() method to clear previous request/response mappings.
    • Method Detail

      • send

        public CompletionStage<com.spotify.apollo.Response<okio.ByteString>> send​(com.spotify.apollo.Request request)
        Specified by:
        send in interface com.spotify.apollo.Client
      • sentRequests

        public List<com.spotify.apollo.Request> sentRequests()
        Returns all the requests sent to this stub client.
      • clearRequests

        public void clearRequests()
        Clears the requests and responses tracked by this client.
      • requestsAndResponses

        public List<StubClient.RequestResponsePair> requestsAndResponses()
        Returns all the requests sent to this stub client, together with their associated responses.
      • clear

        public void clear()
        Clears the previously setup request to response mappings, but not the history of sent messages.
      • respond

        public StubClient.StubbedResponseBuilder respond​(com.spotify.apollo.Response<okio.ByteString> response)
        Configure a constant (i.e., all matching requests will always result in the same response) response for some request. The returned builder allows configuration of payload (default no payload) and delay before the response is sent (default 0).
      • respond

        public StubClient.StubbedResponseBuilder respond​(ResponseSource responseSource)
        Configure a response source for matching requests. Each time a request is sent that matches the to-be-specified criteria, the supplied ResponseSource will be invoked and its result returned as a response.