Class MockClient
java.lang.Object
kong.unirest.core.MockClient
- All Implemented Interfaces:
Client
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionassertThat(HttpMethod method, String path) Assert a specific method and path were invokedstatic voidclear()Clears any MockClient from the primary instancestatic voidclear(UnirestInstance unirest) Clears any MockClient from the instancereturn 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.static MockClientregister()Creates a new MockClient and registers it on the primary static UnirestInstancestatic MockClientregister(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 requestvoidreset()Reset all expectationsvoidVerify that all Expectations were invokedwebsocket(WebSocketRequest request, WebSocket.Listener listener) Create a websocket connection
-
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:ClientMake a request- Specified by:
requestin 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
-
request
public <T> CompletableFuture<HttpResponse<T>> request(HttpRequest request, Function<RawResponse, HttpResponse<T>> transformer, CompletableFuture<HttpResponse<T>> callback, Class<?> resultTypes) Description copied from interface:ClientMake a Async request- Specified by:
requestin 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:ClientCreate 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.
-
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
-