diff --git a/spring-test/src/main/java/org/springframework/mock/http/MockHttpInputMessage.java b/spring-test/src/main/java/org/springframework/mock/http/MockHttpInputMessage.java index 7e4bf5686a..4c7881cdf0 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/MockHttpInputMessage.java +++ b/spring-test/src/main/java/org/springframework/mock/http/MockHttpInputMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2016 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.mock.http; import java.io.ByteArrayInputStream; @@ -37,14 +38,15 @@ public class MockHttpInputMessage implements HttpInputMessage { public MockHttpInputMessage(byte[] contents) { - this.body = (contents != null) ? new ByteArrayInputStream(contents) : null; + this.body = (contents != null ? new ByteArrayInputStream(contents) : null); } public MockHttpInputMessage(InputStream body) { - Assert.notNull(body, "'body' must not be null"); + Assert.notNull(body, "InputStream must not be null"); this.body = body; } + @Override public HttpHeaders getHeaders() { return this.headers; @@ -54,4 +56,5 @@ public class MockHttpInputMessage implements HttpInputMessage { public InputStream getBody() throws IOException { return this.body; } + } diff --git a/spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpRequest.java b/spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpRequest.java index c6896d277c..dcb48225ae 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpRequest.java +++ b/spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2016 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. @@ -33,14 +33,14 @@ import org.springframework.mock.http.MockHttpOutputMessage; */ public class MockClientHttpRequest extends MockHttpOutputMessage implements ClientHttpRequest { - private URI uri; - private HttpMethod httpMethod; - private boolean executed = false; + private URI uri; private ClientHttpResponse clientHttpResponse; + private boolean executed = false; + /** * Default constructor. @@ -56,13 +56,9 @@ public class MockClientHttpRequest extends MockHttpOutputMessage implements Clie this.uri = uri; } - @Override - public URI getURI() { - return this.uri; - } - public void setURI(URI uri) { - this.uri = uri; + public void setMethod(HttpMethod httpMethod) { + this.httpMethod = httpMethod; } @Override @@ -70,8 +66,13 @@ public class MockClientHttpRequest extends MockHttpOutputMessage implements Clie return this.httpMethod; } - public void setMethod(HttpMethod httpMethod) { - this.httpMethod = httpMethod; + public void setURI(URI uri) { + this.uri = uri; + } + + @Override + public URI getURI() { + return this.uri; } public void setResponse(ClientHttpResponse clientHttpResponse) { @@ -96,7 +97,6 @@ public class MockClientHttpRequest extends MockHttpOutputMessage implements Clie /** * The default implementation returns the configured * {@link #setResponse(ClientHttpResponse) response}. - * *
Override this method to execute the request and provide a response,
* potentially different than the configured response.
*/
@@ -104,6 +104,7 @@ public class MockClientHttpRequest extends MockHttpOutputMessage implements Clie
return this.clientHttpResponse;
}
+
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
@@ -114,7 +115,7 @@ public class MockClientHttpRequest extends MockHttpOutputMessage implements Clie
sb.append(" ").append(this.uri);
}
if (!getHeaders().isEmpty()) {
- sb.append(", headers : ").append(getHeaders());
+ sb.append(", headers: ").append(getHeaders());
}
if (sb.length() == 0) {
sb.append("Not yet initialized");
diff --git a/spring-test/src/main/java/org/springframework/test/web/client/response/DefaultResponseCreator.java b/spring-test/src/main/java/org/springframework/test/web/client/response/DefaultResponseCreator.java
index 31632947d6..4a7a9f7e11 100644
--- a/spring-test/src/main/java/org/springframework/test/web/client/response/DefaultResponseCreator.java
+++ b/spring-test/src/main/java/org/springframework/test/web/client/response/DefaultResponseCreator.java
@@ -53,7 +53,7 @@ public class DefaultResponseCreator implements ResponseCreator {
* Use static factory methods in {@link MockRestResponseCreators}.
*/
protected DefaultResponseCreator(HttpStatus statusCode) {
- Assert.notNull(statusCode);
+ Assert.notNull(statusCode, "HttpStatus must not be null");
this.statusCode = statusCode;
}
@@ -61,7 +61,7 @@ public class DefaultResponseCreator implements ResponseCreator {
@Override
public ClientHttpResponse createResponse(ClientHttpRequest request) throws IOException {
MockClientHttpResponse response;
- if (this.contentResource != null ){
+ if (this.contentResource != null) {
InputStream stream = this.contentResource.getInputStream();
response = new MockClientHttpResponse(stream, this.statusCode);
}
diff --git a/spring-test/src/test/java/org/springframework/test/web/client/match/XpathRequestMatchersTests.java b/spring-test/src/test/java/org/springframework/test/web/client/match/XpathRequestMatchersTests.java
index 9900f3f7c7..e22eea7244 100644
--- a/spring-test/src/test/java/org/springframework/test/web/client/match/XpathRequestMatchersTests.java
+++ b/spring-test/src/test/java/org/springframework/test/web/client/match/XpathRequestMatchersTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2016 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.
@@ -35,12 +35,14 @@ public class XpathRequestMatchersTests {
private MockClientHttpRequest request;
+
@Before
public void setUp() throws IOException {
this.request = new MockClientHttpRequest();
this.request.getBody().write(RESPONSE_CONTENT.getBytes());
}
+
@Test
public void testNodeMatcher() throws Exception {
new XpathRequestMatchers("/foo/bar", null).node(Matchers.notNullValue()).match(this.request);
diff --git a/spring-test/src/test/java/org/springframework/test/web/client/response/ResponseCreatorsTests.java b/spring-test/src/test/java/org/springframework/test/web/client/response/ResponseCreatorsTests.java
index c30917f04e..bdba8fe409 100644
--- a/spring-test/src/test/java/org/springframework/test/web/client/response/ResponseCreatorsTests.java
+++ b/spring-test/src/test/java/org/springframework/test/web/client/response/ResponseCreatorsTests.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.test.web.client.response;
import java.net.URI;
diff --git a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatchersIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatchersIntegrationTests.java
index 4837d5bce9..e8072d4772 100644
--- a/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatchersIntegrationTests.java
+++ b/spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatchersIntegrationTests.java
@@ -39,7 +39,6 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
* Examples of defining expectations on request content and content type.
*
* @author Rossen Stoyanchev
- *
* @see JsonPathRequestMatchersIntegrationTests
* @see XmlContentRequestMatchersIntegrationTests
* @see XpathRequestMatchersIntegrationTests
@@ -50,6 +49,7 @@ public class ContentRequestMatchersIntegrationTests {
private RestTemplate restTemplate;
+
@Before
public void setup() {
List