@Override public ResponseActions expectRequest(ExpectedCount count, RequestMatcher matcher) { Assert.state(this.requests.isEmpty(), "Cannot add more expectations after actual requests are made"); RequestExpectation expectation = new DefaultRequestExpectation(count, matcher); this.expectations.add(expectation); return expectation; }
@Override public void incrementAndValidate() { getRequestCount().incrementAndValidate(); }
@Override public void match(ClientHttpRequest request) throws IOException { for (RequestMatcher matcher : getRequestMatchers()) { matcher.match(request); } }
@Override public ClientHttpResponse createResponse(ClientHttpRequest request) throws IOException { ResponseCreator responseCreator = getResponseCreator(); if (responseCreator == null) { throw new IllegalStateException("createResponse called before ResponseCreator was set"); } getRequestCount().incrementAndValidate(); return responseCreator.createResponse(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. Instead * {@link #incrementAndValidate()} must be invoked independently. */ @Override public ClientHttpResponse createResponse(@Nullable ClientHttpRequest request) throws IOException { ResponseCreator responseCreator = getResponseCreator(); Assert.state(responseCreator != null, "createResponse() called before ResponseCreator was set"); return responseCreator.createResponse(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. Instead * {@link #incrementAndValidate()} must be invoked independently. */ @Override public ClientHttpResponse createResponse(@Nullable ClientHttpRequest request) throws IOException { ResponseCreator responseCreator = getResponseCreator(); Assert.state(responseCreator != null, "createResponse() called before ResponseCreator was set"); return responseCreator.createResponse(request); }
@Test public void match() throws Exception { RequestExpectation expectation = new DefaultRequestExpectation(once(), requestTo("/foo")); expectation.match(createRequest(GET, "/foo")); }
@Override public boolean hasRemainingCount() { return getRequestCount().hasRemainingCount(); }
@Override public void match(ClientHttpRequest request) throws IOException { for (RequestMatcher matcher : getRequestMatchers()) { matcher.match(request); } }
@Test public void matchWithFailedExpectation() throws Exception { RequestExpectation expectation = new DefaultRequestExpectation(once(), requestTo("/foo")); expectation.andExpect(method(POST)); this.thrown.expectMessage("Unexpected HttpMethod expected:<POST> but was:<GET>"); expectation.match(createRequest(GET, "/foo")); }
@Override public boolean isSatisfied() { return getRequestCount().isSatisfied(); }
@Override public void match(ClientHttpRequest request) throws IOException { for (RequestMatcher matcher : getRequestMatchers()) { matcher.match(request); } }
@Test public void hasRemainingCount() { RequestExpectation expectation = new DefaultRequestExpectation(twice(), requestTo("/foo")); expectation.andRespond(withSuccess()); expectation.incrementAndValidate(); assertTrue(expectation.hasRemainingCount()); expectation.incrementAndValidate(); assertFalse(expectation.hasRemainingCount()); }
@Override public void incrementAndValidate() { getRequestCount().incrementAndValidate(); }
@Test public void isSatisfied() { RequestExpectation expectation = new DefaultRequestExpectation(twice(), requestTo("/foo")); expectation.andRespond(withSuccess()); expectation.incrementAndValidate(); assertFalse(expectation.isSatisfied()); expectation.incrementAndValidate(); assertTrue(expectation.isSatisfied()); }
@Override public boolean hasRemainingCount() { return getRequestCount().hasRemainingCount(); }
@Override public ResponseActions expectRequest(ExpectedCount count, RequestMatcher matcher) { Assert.state(this.requests.isEmpty(), "Cannot add more expectations after actual requests are made"); RequestExpectation expectation = new DefaultRequestExpectation(count, matcher); this.expectations.add(expectation); return expectation; }
@Override public boolean hasRemainingCount() { return getRequestCount().hasRemainingCount(); }
@Override public ResponseActions expectRequest(ExpectedCount count, RequestMatcher matcher) { Assert.state(getRequests().isEmpty(), "Cannot add more expectations after actual requests are made"); RequestExpectation expectation = new DefaultRequestExpectation(count, matcher); getExpectations().add(expectation); return expectation; }
@Override public boolean isSatisfied() { return getRequestCount().isSatisfied(); }