public class DefaultRequestExpectation extends java.lang.Object implements RequestExpectation
RequestExpectation that simply delegates
to the request matchers and the response creator it contains.| Modifier and Type | Class and Description |
|---|---|
protected static class |
DefaultRequestExpectation.RequestCount
Helper class that keeps track of actual vs expected request count.
|
| Constructor and Description |
|---|
DefaultRequestExpectation(ExpectedCount expectedCount,
RequestMatcher requestMatcher)
Create a new request expectation that should be called a number of times
as indicated by
RequestCount. |
| Modifier and Type | Method and Description |
|---|---|
ResponseActions |
andExpect(RequestMatcher requestMatcher)
Add a request expectation.
|
void |
andRespond(ResponseCreator responseCreator)
Define the response.
|
ClientHttpResponse |
createResponse(ClientHttpRequest request)
Note that as of 5.0.3, the creation of the response, which may block
intentionally, is separated from request count tracking, and this
method no longer increments the count transparently.
|
protected DefaultRequestExpectation.RequestCount |
getRequestCount() |
protected java.util.List<RequestMatcher> |
getRequestMatchers() |
protected ResponseCreator |
getResponseCreator() |
boolean |
hasRemainingCount()
Whether there is a remaining count of invocations for this expectation.
|
void |
incrementAndValidate()
Increase the matched request count and check we haven't passed the max count.
|
boolean |
isSatisfied()
Whether the requirements for this request expectation have been met.
|
void |
match(ClientHttpRequest request)
Match the given request against specific expectations.
|
public DefaultRequestExpectation(ExpectedCount expectedCount, RequestMatcher requestMatcher)
RequestCount.expectedCount - the expected request expectedCountprotected DefaultRequestExpectation.RequestCount getRequestCount()
protected java.util.List<RequestMatcher> getRequestMatchers()
@Nullable protected ResponseCreator getResponseCreator()
public ResponseActions andExpect(RequestMatcher requestMatcher)
ResponseActionsandExpect in interface ResponseActionspublic void andRespond(ResponseCreator responseCreator)
ResponseActionsandRespond in interface ResponseActionsresponseCreator - the creator of the responsepublic void match(ClientHttpRequest request) throws java.io.IOException
RequestMatchermatch in interface RequestMatcherrequest - the request to make assertions onjava.io.IOException - in case of I/O errorspublic ClientHttpResponse createResponse(@Nullable ClientHttpRequest request) throws java.io.IOException
incrementAndValidate() must be invoked independently.createResponse in interface ResponseCreatorrequest - the requestjava.io.IOExceptionpublic boolean hasRemainingCount()
RequestExpectationhasRemainingCount in interface RequestExpectationpublic void incrementAndValidate()
RequestExpectationincrementAndValidate in interface RequestExpectationpublic boolean isSatisfied()
RequestExpectationisSatisfied in interface RequestExpectation