Package kong.unirest.core
Class MockClient
java.lang.Object
kong.unirest.core.MockClient
- All Implemented Interfaces:
Client
A Mock client for unirest to make requests against
This implements both sync and async clients
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionassertThat
(HttpMethod method, String path) Assert a specific method and path were invokedstatic void
clear()
Clears any MockClient from the primary instancestatic void
clear
(UnirestInstance unirest) Clears any MockClient from the instanceprivate Routes
createNewPath
(HttpRequest request) return this status for any request that doesn't match a expectationexpect
(HttpMethod method) Expect ANY call to a path with this methodexpect
(HttpMethod method, String path) Start an expectation chain.findByPath
(HttpMethod get, Path path) private Routes
findExpecation
(HttpRequest request) static MockClient
register()
Creates a new MockClient and registers it on the primary static UnirestInstancestatic MockClient
register
(UnirestInstance unirest) Creates a new MockClient and registers it on the Unirest instance<T> HttpResponse
<T> request
(HttpRequest request, Function<RawResponse, HttpResponse<T>> transformer, Class<?> resultType) Make a request<T> CompletableFuture
<HttpResponse<T>> request
(HttpRequest request, Function<RawResponse, HttpResponse<T>> transformer, CompletableFuture<HttpResponse<T>> callback, Class<?> resultTypes) Make a Async requestvoid
reset()
Reset all expectationsvoid
Verify that all Expectations were invokedwebsocket
(WebSocketRequest request, WebSocket.Listener listener) Create a websocket connection
-
Field Details
-
config
-
routes
-
remoteSocket
-
defaultResponse
-
-
Constructor Details
-
MockClient
-
-
Method Details
-
register
Creates a new MockClient and registers it on the primary static UnirestInstance- Returns:
- the Mock Client
-
register
Creates a new MockClient and registers it on the Unirest instance- Parameters:
unirest
- an instance of Unirest- Returns:
- the Mock Client
-
clear
public static void clear()Clears any MockClient from the primary instance -
clear
Clears any MockClient from the instance- Parameters:
unirest
- the instance to clear the mocks from
-
request
public <T> HttpResponse<T> request(HttpRequest request, Function<RawResponse, HttpResponse<T>> transformer, Class<?> resultType) Description copied from interface:Client
Make a request- Specified by:
request
in interfaceClient
- Type Parameters:
T
- The type of the body- Parameters:
request
- the prepared request objecttransformer
- the function to transform the responseresultType
- the final body result type. This is a hint to downstream systems to make up for type erasure.- Returns:
- a HttpResponse with a transformed body
-
findExpecation
-
createNewPath
-
request
public <T> CompletableFuture<HttpResponse<T>> request(HttpRequest request, Function<RawResponse, HttpResponse<T>> transformer, CompletableFuture<HttpResponse<T>> callback, Class<?> resultTypes) Description copied from interface:Client
Make a Async request- Specified by:
request
in interfaceClient
- Type Parameters:
T
- The type of the body- Parameters:
request
- the prepared request objecttransformer
- the function to transform the responsecallback
- the CompletableFuture that will handle the eventual responseresultTypes
- the final body result type. This is a hint to downstream systems to make up for type erasure.- Returns:
- a CompletableFuture of a response
-
websocket
Description copied from interface:Client
Create a websocket connection -
serversSocket
-
getClient
-
expect
Start an expectation chain.- Parameters:
method
- the Http methodpath
- the base path- Returns:
- an Expectation which can have additional criteria added to it.
-
expect
Expect ANY call to a path with this method- Parameters:
method
- the Http Method- Returns:
- this expectation builder
-
assertThat
Assert a specific method and path were invoked- Parameters:
method
- the Http methodpath
- the base path- Returns:
- an Assert object which can have additional criteria chained to it.
-
findByPath
-
verifyAll
public void verifyAll()Verify that all Expectations were invoked -
reset
public void reset()Reset all expectations -
defaultResponse
return this status for any request that doesn't match a expectation
-