public class DefaultRequestExpectation extends 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 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 List<RequestMatcher> getRequestMatchers()
@Nullable protected ResponseCreator getResponseCreator()
public ResponseActions andExpect(RequestMatcher requestMatcher)
ResponseActions
andExpect
in interface ResponseActions
public void andRespond(ResponseCreator responseCreator)
ResponseActions
andRespond
in interface ResponseActions
responseCreator
- the creator of the responsepublic void match(ClientHttpRequest request) throws IOException
RequestMatcher
match
in interface RequestMatcher
request
- the request to make assertions onIOException
- in case of I/O errorspublic ClientHttpResponse createResponse(@Nullable ClientHttpRequest request) throws IOException
incrementAndValidate()
must be invoked independently.createResponse
in interface ResponseCreator
request
- the requestIOException
public boolean hasRemainingCount()
RequestExpectation
hasRemainingCount
in interface RequestExpectation
public void incrementAndValidate()
RequestExpectation
incrementAndValidate
in interface RequestExpectation
public boolean isSatisfied()
RequestExpectation
isSatisfied
in interface RequestExpectation