Class MockResponse<T>

  • Type Parameters:
    T - the body type
    All Implemented Interfaces:
    HttpResponse<T>

    public class MockResponse<T>
    extends BaseResponse<T>
    A Mock Response that can be used in testing.
    • Constructor Detail

      • MockResponse

        public MockResponse​(int status,
                            java.lang.String statusText,
                            T body)
        Construct a mock Response
        Parameters:
        status - the status of the response
        statusText - the status text
        body - the body
      • MockResponse

        public MockResponse​(int status,
                            java.lang.String statusText,
                            T body,
                            MockConfig config)
        Construct a mock Response
        Parameters:
        status - the status of the response
        statusText - the status text
        body - the body
        config - a mockConfig for post-processing options
    • Method Detail

      • ok

        public static <T> MockResponse<T> ok​(T body)
        Construct a simple successful (200 ok) response with a body
        Type Parameters:
        T - the type of body
        Parameters:
        body - the body
        Returns:
        a MockResponse;
      • bad

        public static <T> MockResponse<T> bad​(T body)
        Construct a simple failed (400 bad request) response with a body
        Type Parameters:
        T - the type of body
        Parameters:
        body - the body
        Returns:
        a MockResponse;
      • of

        public static <T> MockResponse<T> of​(int status,
                                             T body)
        Construct a response with a status and body. The status text is just the string of the status
        Type Parameters:
        T - the type of body
        Parameters:
        status - the status
        body - the body
        Returns:
        a MockResponse;
      • of

        public static <T> MockResponse<T> of​(int status,
                                             java.lang.String statusText,
                                             T body)
        Construct a response with a status and body. The status text is just the string of the status
        Type Parameters:
        T - the type of body
        Parameters:
        status - the status
        statusText - the status text
        body - the body
        Returns:
        a MockResponse;
      • config

        public MockConfig config()
        get the MockConfig for this MockResponse
        Returns:
        the config
      • withHeader

        public MockResponse<T> withHeader​(java.lang.String key,
                                          java.lang.String value)
        add a header value to the response
        Parameters:
        key - the header key
        value - the header value
        Returns:
        this MockResponse
      • failedToParse

        public MockResponse<T> failedToParse()
        Flag that there was a post-processing parsing error with the object Mapper this jams the body as a string into the parsing exception and sets a generic oops exception
        Returns:
        this MockResponse
      • failedToParse

        public MockResponse<T> failedToParse​(java.lang.Exception e,
                                             java.lang.String originalBody)
        Flag that there was a post-processing parsing error with the object Mapper
        Parameters:
        e - the exception thrown
        originalBody - the original body before the object mapper got involved.
        Returns:
        this MockResponse
      • withConfigOptions

        public MockResponse<T> withConfigOptions​(java.util.function.Consumer<MockConfig> c)
        Set some options on the current MockConfig.
        Parameters:
        c - a Consumer with options to set on the config
        Returns:
        this MockResponse