/** * Return a matching expectation, or {@code null} if none match. */ @Nullable public RequestExpectation findExpectation(ClientHttpRequest request) throws IOException { for (RequestExpectation expectation : this.expectations) { try { expectation.match(request); return expectation; } catch (AssertionError error) { // We're looking to find a match or return null.. } } return null; }
@Override protected RequestExpectation matchRequest(ClientHttpRequest request) throws IOException { RequestExpectation expectation = this.repeatExpectations.findExpectation(request); if (expectation == null) { if (this.expectationIterator == null || !this.expectationIterator.hasNext()) { throw createUnexpectedRequestError(request); } expectation = this.expectationIterator.next(); expectation.match(request); } this.repeatExpectations.update(expectation); return expectation; }
@Test public void match() throws Exception { RequestExpectation expectation = new DefaultRequestExpectation(once(), requestTo("/foo")); expectation.match(createRequest(GET, "/foo")); }
@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")); }
/** * Return a matching expectation, or {@code null} if none match. */ @Nullable public RequestExpectation findExpectation(ClientHttpRequest request) throws IOException { for (RequestExpectation expectation : this.expectations) { try { expectation.match(request); return expectation; } catch (AssertionError error) { // We're looking to find a match or return null.. } } return null; }
/** * Return a matching expectation, or {@code null} if none match. */ public RequestExpectation findExpectation(ClientHttpRequest request) throws IOException { for (RequestExpectation expectation : getExpectations()) { try { expectation.match(request); return expectation; } catch (AssertionError error) { // We're looking to find a match or return null.. } } return null; }
@Override protected RequestExpectation matchRequest(ClientHttpRequest request) throws IOException { RequestExpectation expectation = this.repeatExpectations.findExpectation(request); if (expectation == null) { if (this.expectationIterator == null || !this.expectationIterator.hasNext()) { throw createUnexpectedRequestError(request); } expectation = this.expectationIterator.next(); expectation.match(request); } this.repeatExpectations.update(expectation); return expectation; }
@Override public ClientHttpResponse validateRequestInternal(ClientHttpRequest request) throws IOException { RequestExpectation expectation = this.repeatExpectations.findExpectation(request); if (expectation == null) { if (!this.expectationIterator.hasNext()) { throw createUnexpectedRequestError(request); } expectation = this.expectationIterator.next(); expectation.match(request); } ClientHttpResponse response = expectation.createResponse(request); this.repeatExpectations.update(expectation); return response; }