Improve exception message
Issue: SPR-12230
(cherry picked from commit 7f4bf41)
This commit is contained in:
committed by
Juergen Hoeller
parent
a09bc9b1c1
commit
2d0a677117
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.test.web.client;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -95,28 +96,24 @@ public class MockRestServiceServer {
|
||||
private MockRestServiceServer() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a {@code MockRestServiceServer} and set up the given
|
||||
* {@code RestTemplate} with a mock {@link ClientHttpRequestFactory}.
|
||||
*
|
||||
* @param restTemplate the RestTemplate to set up for mock testing
|
||||
* @return the created mock server
|
||||
*/
|
||||
public static MockRestServiceServer createServer(RestTemplate restTemplate) {
|
||||
Assert.notNull(restTemplate, "'restTemplate' must not be null");
|
||||
|
||||
MockRestServiceServer mockServer = new MockRestServiceServer();
|
||||
RequestMatcherClientHttpRequestFactory factory = mockServer.new RequestMatcherClientHttpRequestFactory();
|
||||
|
||||
restTemplate.setRequestFactory(factory);
|
||||
|
||||
return mockServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@code MockRestServiceServer} and set up the given
|
||||
* {@code RestGatewaySupport} with a mock {@link ClientHttpRequestFactory}.
|
||||
*
|
||||
* @param restGateway the REST gateway to set up for mock testing
|
||||
* @return the created mock server
|
||||
*/
|
||||
@@ -125,14 +122,12 @@ public class MockRestServiceServer {
|
||||
return createServer(restGateway.getRestTemplate());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set up a new HTTP request expectation. The returned {@link ResponseActions}
|
||||
* is used to set up further expectations and to define the response.
|
||||
*
|
||||
* <p>This method may be invoked multiple times before starting the test, i.e.
|
||||
* before using the {@code RestTemplate}, to set up expectations for multiple
|
||||
* requests.
|
||||
*
|
||||
* <p>This method may be invoked multiple times before starting the test, i.e. before
|
||||
* using the {@code RestTemplate}, to set up expectations for multiple requests.
|
||||
* @param requestMatcher a request expectation, see {@link MockRestRequestMatchers}
|
||||
* @return used to set up further expectations or to define a response
|
||||
*/
|
||||
@@ -146,7 +141,6 @@ public class MockRestServiceServer {
|
||||
/**
|
||||
* Verify that all expected requests set up via
|
||||
* {@link #expect(RequestMatcher)} were indeed performed.
|
||||
*
|
||||
* @throws AssertionError when some expectations were not met
|
||||
*/
|
||||
public void verify() {
|
||||
@@ -158,7 +152,6 @@ public class MockRestServiceServer {
|
||||
|
||||
private String getVerifyMessage() {
|
||||
StringBuilder sb = new StringBuilder("Further request(s) expected\n");
|
||||
|
||||
if (this.actualRequests.size() > 0) {
|
||||
sb.append("The following ");
|
||||
}
|
||||
@@ -171,7 +164,6 @@ public class MockRestServiceServer {
|
||||
sb.append(request.toString()).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -193,7 +185,7 @@ public class MockRestServiceServer {
|
||||
this.requestIterator = MockRestServiceServer.this.expectedRequests.iterator();
|
||||
}
|
||||
if (!this.requestIterator.hasNext()) {
|
||||
throw new AssertionError("No further requests expected");
|
||||
throw new AssertionError("No further requests expected: HTTP " + httpMethod + " " + uri);
|
||||
}
|
||||
|
||||
RequestMatcherClientHttpRequest request = this.requestIterator.next();
|
||||
@@ -201,7 +193,6 @@ public class MockRestServiceServer {
|
||||
request.setMethod(httpMethod);
|
||||
|
||||
MockRestServiceServer.this.actualRequests.add(request);
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,25 +13,25 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.test.web.client;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.anything;
|
||||
package org.springframework.test.web.client;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.ClientHttpRequest;
|
||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.test.web.client.MockRestServiceServer;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
|
||||
|
||||
/**
|
||||
* Tests for {@link MockClientHttpRequestFactory}.
|
||||
* Tests for
|
||||
* {@link org.springframework.test.web.client.MockMvcClientHttpRequestFactory}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
@@ -66,7 +66,7 @@ public class MockClientHttpRequestFactoryTests {
|
||||
this.factory.createRequest(new URI("/foo"), HttpMethod.GET);
|
||||
}
|
||||
catch (AssertionError error) {
|
||||
assertEquals("No further requests expected", error.getMessage());
|
||||
assertEquals("No further requests expected: HTTP GET /foo", error.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user