Polishing

This commit is contained in:
Juergen Hoeller
2016-08-09 12:12:42 +02:00
parent e8562bb3af
commit 6924f00f8c
12 changed files with 77 additions and 95 deletions

View File

@@ -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;
}
public HttpHeaders getHeaders() {
return this.headers;
}

View File

@@ -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,20 +56,21 @@ public class MockClientHttpRequest extends MockHttpOutputMessage implements Clie
this.uri = uri;
}
public URI getURI() {
return this.uri;
}
public void setURI(URI uri) {
this.uri = uri;
public void setMethod(HttpMethod httpMethod) {
this.httpMethod = httpMethod;
}
public HttpMethod getMethod() {
return this.httpMethod;
}
public void setMethod(HttpMethod httpMethod) {
this.httpMethod = httpMethod;
public void setURI(URI uri) {
this.uri = uri;
}
public URI getURI() {
return this.uri;
}
public void setResponse(ClientHttpResponse clientHttpResponse) {
@@ -93,7 +94,6 @@ public class MockClientHttpRequest extends MockHttpOutputMessage implements Clie
/**
* The default implementation returns the configured
* {@link #setResponse(ClientHttpResponse) response}.
*
* <p>Override this method to execute the request and provide a response,
* potentially different than the configured response.
*/
@@ -101,6 +101,7 @@ public class MockClientHttpRequest extends MockHttpOutputMessage implements Clie
return this.clientHttpResponse;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
@@ -111,7 +112,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");

View File

@@ -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.client;
import java.io.IOException;
@@ -39,7 +40,7 @@ public class MockClientHttpResponse extends MockHttpInputMessage implements Clie
*/
public MockClientHttpResponse(byte[] body, HttpStatus statusCode) {
super(body);
Assert.notNull(statusCode, "statisCode is required");
Assert.notNull(statusCode, "HttpStatus is required");
this.status = statusCode;
}
@@ -48,10 +49,11 @@ public class MockClientHttpResponse extends MockHttpInputMessage implements Clie
*/
public MockClientHttpResponse(InputStream body, HttpStatus statusCode) {
super(body);
Assert.notNull(statusCode, "statisCode is required");
Assert.notNull(statusCode, "HttpStatus is required");
this.status = statusCode;
}
public HttpStatus getStatusCode() throws IOException {
return this.status;
}