Class MockRawResponse

java.lang.Object
kong.unirest.core.MockRawResponse
All Implemented Interfaces:
RawResponse

public class MockRawResponse extends Object implements RawResponse
  • Field Details

    • response

      private final String response
    • responseHeaders

      private final Headers responseHeaders
    • status

      private final int status
    • statusMessage

      private final String statusMessage
    • config

      private final Config config
    • summary

      private final HttpRequestSummary summary
  • Constructor Details

  • Method Details

    • getStatus

      public int getStatus()
      Description copied from interface: RawResponse
      Returns the status code for this response.
      Specified by:
      getStatus in interface RawResponse
      Returns:
      the response code
    • getStatusText

      public String getStatusText()
      Description copied from interface: RawResponse
      Returns the status text for this response.
      Specified by:
      getStatusText in interface RawResponse
      Returns:
      the response text
    • getHeaders

      public Headers getHeaders()
      Description copied from interface: RawResponse
      Returns the received response headers.
      Specified by:
      getHeaders in interface RawResponse
      Returns:
      the response headers
    • getContent

      public InputStream getContent()
      Description copied from interface: RawResponse
      Returns the body content of the response as a InputStream. Like most InputStreams it can only be read once. If you read the response though some other method like getContentAsBytes() or getBodyAsString() it will read this method and consume the InputStream
      Specified by:
      getContent in interface RawResponse
      Returns:
      the content
    • getContentAsBytes

      public byte[] getContentAsBytes()
      Description copied from interface: RawResponse
      Returns the body as bytes. This consumes the entire InputStream. Warning: Calling this on very large responses will place all data in memory and could create OutOfMemory errors
      Specified by:
      getContentAsBytes in interface RawResponse
      Returns:
      the content as bytes
    • getContentAsString

      public String getContentAsString()
      Description copied from interface: RawResponse
      Returns the body as UTF-8 String. This consumes the entire InputStream. Warning: Calling this on very large responses will place all data in memory and could create OutOfMemory errors Using this method with a binary response will make you sad
      Specified by:
      getContentAsString in interface RawResponse
      Returns:
      the content as a UTF-8 String
    • getContentAsString

      public String getContentAsString(String charset)
      Description copied from interface: RawResponse
      Returns the body as UTF-8 String. This consumes the entire InputStream. Warning: Calling this on very large responses will place all data in memory and could create OutOfMemory errors Using this method with a binary response will make you sad
      Specified by:
      getContentAsString in interface RawResponse
      Parameters:
      charset - the charset for the String
      Returns:
      the content as a string in the provided charset.
    • tryGetCharset

      private Charset tryGetCharset(String charset)
    • getContentReader

      public InputStreamReader getContentReader()
      Description copied from interface: RawResponse
      Returns the body content of the response as a InputStreamReader. Like most InputStreams it can only be read once. If you read the response though some other method like getContentAsBytes() or getBodyAsString() it will read this method and consume the InputStream
      Specified by:
      getContentReader in interface RawResponse
      Returns:
      the content
    • hasContent

      public boolean hasContent()
      Description copied from interface: RawResponse
      Indicates that the response has content
      Specified by:
      hasContent in interface RawResponse
      Returns:
      boolean indicating that the response has content.
    • getContentType

      public String getContentType()
      Description copied from interface: RawResponse
      Returns the mime type of the response content as indicated by the Content-Type header or a empty string if none is supplied (e.g. application/json)
      Specified by:
      getContentType in interface RawResponse
      Returns:
      the Content-Type
    • getEncoding

      public String getEncoding()
      Description copied from interface: RawResponse
      Returns the encoding of the response as indicated by the Content-Encoding header or returns a empty string if none provided.
      Specified by:
      getEncoding in interface RawResponse
      Returns:
      the encoding
    • getConfig

      public Config getConfig()
      Description copied from interface: RawResponse
      Returns the current config for this request/response
      Specified by:
      getConfig in interface RawResponse
      Returns:
      the config
    • toSummary

      public HttpResponseSummary toSummary()
      Description copied from interface: RawResponse
      returns a lightweight read only summary of the response.
      Specified by:
      toSummary in interface RawResponse
      Returns:
      the response summary
    • getRequestSummary

      public HttpRequestSummary getRequestSummary()
      Description copied from interface: RawResponse
      returns a lightweight read only summary of the request.
      Specified by:
      getRequestSummary in interface RawResponse
      Returns:
      the request summary