Skip to content

Commit eae079a

Browse files
committed
Polishing
1 parent 47e9360 commit eae079a

File tree

10 files changed

+42
-32
lines changed

10 files changed

+42
-32
lines changed

spring-test/src/main/java/org/springframework/mock/http/MockHttpInputMessage.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.mock.http;
1718

1819
import java.io.ByteArrayInputStream;
@@ -37,14 +38,15 @@ public class MockHttpInputMessage implements HttpInputMessage {
3738

3839

3940
public MockHttpInputMessage(byte[] contents) {
40-
this.body = (contents != null) ? new ByteArrayInputStream(contents) : null;
41+
this.body = (contents != null ? new ByteArrayInputStream(contents) : null);
4142
}
4243

4344
public MockHttpInputMessage(InputStream body) {
44-
Assert.notNull(body, "'body' must not be null");
45+
Assert.notNull(body, "InputStream must not be null");
4546
this.body = body;
4647
}
4748

49+
4850
@Override
4951
public HttpHeaders getHeaders() {
5052
return this.headers;
@@ -54,4 +56,5 @@ public HttpHeaders getHeaders() {
5456
public InputStream getBody() throws IOException {
5557
return this.body;
5658
}
59+
5760
}

spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpRequest.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,14 +33,14 @@
3333
*/
3434
public class MockClientHttpRequest extends MockHttpOutputMessage implements ClientHttpRequest {
3535

36-
private URI uri;
37-
3836
private HttpMethod httpMethod;
3937

40-
private boolean executed = false;
38+
private URI uri;
4139

4240
private ClientHttpResponse clientHttpResponse;
4341

42+
private boolean executed = false;
43+
4444

4545
/**
4646
* Default constructor.
@@ -56,22 +56,23 @@ public MockClientHttpRequest(HttpMethod httpMethod, URI uri) {
5656
this.uri = uri;
5757
}
5858

59-
@Override
60-
public URI getURI() {
61-
return this.uri;
62-
}
6359

64-
public void setURI(URI uri) {
65-
this.uri = uri;
60+
public void setMethod(HttpMethod httpMethod) {
61+
this.httpMethod = httpMethod;
6662
}
6763

6864
@Override
6965
public HttpMethod getMethod() {
7066
return this.httpMethod;
7167
}
7268

73-
public void setMethod(HttpMethod httpMethod) {
74-
this.httpMethod = httpMethod;
69+
public void setURI(URI uri) {
70+
this.uri = uri;
71+
}
72+
73+
@Override
74+
public URI getURI() {
75+
return this.uri;
7576
}
7677

7778
public void setResponse(ClientHttpResponse clientHttpResponse) {
@@ -96,14 +97,14 @@ public final ClientHttpResponse execute() throws IOException {
9697
/**
9798
* The default implementation returns the configured
9899
* {@link #setResponse(ClientHttpResponse) response}.
99-
*
100100
* <p>Override this method to execute the request and provide a response,
101101
* potentially different than the configured response.
102102
*/
103103
protected ClientHttpResponse executeInternal() throws IOException {
104104
return this.clientHttpResponse;
105105
}
106106

107+
107108
@Override
108109
public String toString() {
109110
StringBuilder sb = new StringBuilder();
@@ -114,7 +115,7 @@ public String toString() {
114115
sb.append(" ").append(this.uri);
115116
}
116117
if (!getHeaders().isEmpty()) {
117-
sb.append(", headers : ").append(getHeaders());
118+
sb.append(", headers: ").append(getHeaders());
118119
}
119120
if (sb.length() == 0) {
120121
sb.append("Not yet initialized");

spring-test/src/main/java/org/springframework/test/web/client/response/DefaultResponseCreator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ public class DefaultResponseCreator implements ResponseCreator {
5353
* Use static factory methods in {@link MockRestResponseCreators}.
5454
*/
5555
protected DefaultResponseCreator(HttpStatus statusCode) {
56-
Assert.notNull(statusCode);
56+
Assert.notNull(statusCode, "HttpStatus must not be null");
5757
this.statusCode = statusCode;
5858
}
5959

6060

6161
@Override
6262
public ClientHttpResponse createResponse(ClientHttpRequest request) throws IOException {
6363
MockClientHttpResponse response;
64-
if (this.contentResource != null ){
64+
if (this.contentResource != null) {
6565
InputStream stream = this.contentResource.getInputStream();
6666
response = new MockClientHttpResponse(stream, this.statusCode);
6767
}

spring-test/src/test/java/org/springframework/test/web/client/match/XpathRequestMatchersTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,12 +35,14 @@ public class XpathRequestMatchersTests {
3535

3636
private MockClientHttpRequest request;
3737

38+
3839
@Before
3940
public void setUp() throws IOException {
4041
this.request = new MockClientHttpRequest();
4142
this.request.getBody().write(RESPONSE_CONTENT.getBytes());
4243
}
4344

45+
4446
@Test
4547
public void testNodeMatcher() throws Exception {
4648
new XpathRequestMatchers("/foo/bar", null).node(Matchers.notNullValue()).match(this.request);

spring-test/src/test/java/org/springframework/test/web/client/response/ResponseCreatorsTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.test.web.client.response;
1718

1819
import java.net.URI;

spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatchersIntegrationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
* Examples of defining expectations on request content and content type.
4040
*
4141
* @author Rossen Stoyanchev
42-
*
4342
* @see JsonPathRequestMatchersIntegrationTests
4443
* @see XmlContentRequestMatchersIntegrationTests
4544
* @see XpathRequestMatchersIntegrationTests
@@ -50,6 +49,7 @@ public class ContentRequestMatchersIntegrationTests {
5049

5150
private RestTemplate restTemplate;
5251

52+
5353
@Before
5454
public void setup() {
5555
List<HttpMessageConverter<?>> converters = new ArrayList<>();
@@ -62,6 +62,7 @@ public void setup() {
6262
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
6363
}
6464

65+
6566
@Test
6667
public void contentType() throws Exception {
6768
this.mockServer.expect(content().contentType("application/json;charset=UTF-8")).andRespond(withSuccess());

spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/HeaderRequestMatchersIntegrationTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ public class HeaderRequestMatchersIntegrationTests {
4444

4545
private static final String RESPONSE_BODY = "{\"name\" : \"Ludwig van Beethoven\", \"someDouble\" : \"1.6035\"}";
4646

47+
4748
private MockRestServiceServer mockServer;
4849

4950
private RestTemplate restTemplate;
5051

52+
5153
@Before
5254
public void setup() {
5355
List<HttpMessageConverter<?>> converters = new ArrayList<>();
@@ -60,9 +62,9 @@ public void setup() {
6062
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
6163
}
6264

65+
6366
@Test
6467
public void testString() throws Exception {
65-
6668
this.mockServer.expect(requestTo("/person/1"))
6769
.andExpect(header("Accept", "application/json, application/*+json"))
6870
.andRespond(withSuccess(RESPONSE_BODY, MediaType.APPLICATION_JSON));
@@ -73,7 +75,6 @@ public void testString() throws Exception {
7375

7476
@Test
7577
public void testStringContains() throws Exception {
76-
7778
this.mockServer.expect(requestTo("/person/1"))
7879
.andExpect(header("Accept", containsString("json")))
7980
.andRespond(withSuccess(RESPONSE_BODY, MediaType.APPLICATION_JSON));

spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatchersIntegrationTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.net.URI;
2020
import java.net.URISyntaxException;
2121
import java.util.Arrays;
22+
import java.util.Collections;
2223

2324
import org.junit.After;
2425
import org.junit.Test;
@@ -56,7 +57,9 @@ public class JsonPathRequestMatchersIntegrationTests {
5657
people.add("performers", new Person("Yehudi Menuhin"));
5758
}
5859

59-
private final RestTemplate restTemplate = new RestTemplate(Arrays.asList(new MappingJackson2HttpMessageConverter()));
60+
61+
private final RestTemplate restTemplate =
62+
new RestTemplate(Collections.singletonList(new MappingJackson2HttpMessageConverter()));
6063

6164
private final MockRestServiceServer mockServer = MockRestServiceServer.createServer(this.restTemplate);
6265

spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/XmlContentRequestMatchersIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class XmlContentRequestMatchersIntegrationTests {
5757
"<composer><name>Robert Schumann</name><someBoolean>false</someBoolean><someDouble>NaN</someDouble></composer>" +
5858
"</composers></people>";
5959

60+
6061
private MockRestServiceServer mockServer;
6162

6263
private RestTemplate restTemplate;
@@ -66,7 +67,6 @@ public class XmlContentRequestMatchersIntegrationTests {
6667

6768
@Before
6869
public void setup() {
69-
7070
List<Person> composers = Arrays.asList(
7171
new Person("Johann Sebastian Bach").setSomeDouble(21),
7272
new Person("Johannes Brahms").setSomeDouble(.0025),
@@ -97,7 +97,6 @@ public void testXmlEqualTo() throws Exception {
9797

9898
@Test
9999
public void testHamcrestNodeMatcher() throws Exception {
100-
101100
this.mockServer.expect(requestTo("/composers"))
102101
.andExpect(content().contentType("application/xml"))
103102
.andExpect(content().node(hasXPath("/people/composers/composer[1]")))
@@ -128,4 +127,5 @@ public List<Person> getComposers() {
128127
return this.composers;
129128
}
130129
}
130+
131131
}

spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/XpathRequestMatchersIntegrationTests.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ public class XpathRequestMatchersIntegrationTests {
5353
private static final Map<String, String> NS =
5454
Collections.singletonMap("ns", "http://example.org/music/people");
5555

56+
5657
private MockRestServiceServer mockServer;
5758

5859
private RestTemplate restTemplate;
5960

6061
private PeopleWrapper people;
6162

63+
6264
@Before
6365
public void setup() {
64-
6566
List<Person> composers = Arrays.asList(
6667
new Person("Johann Sebastian Bach").setSomeDouble(21),
6768
new Person("Johannes Brahms").setSomeDouble(.0025),
@@ -83,9 +84,9 @@ public void setup() {
8384
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
8485
}
8586

87+
8688
@Test
8789
public void testExists() throws Exception {
88-
8990
String composer = "/ns:people/composers/composer[%s]";
9091
String performer = "/ns:people/performers/performer[%s]";
9192

@@ -105,7 +106,6 @@ public void testExists() throws Exception {
105106

106107
@Test
107108
public void testDoesNotExist() throws Exception {
108-
109109
String composer = "/ns:people/composers/composer[%s]";
110110
String performer = "/ns:people/performers/performer[%s]";
111111

@@ -123,7 +123,6 @@ public void testDoesNotExist() throws Exception {
123123

124124
@Test
125125
public void testString() throws Exception {
126-
127126
String composerName = "/ns:people/composers/composer[%s]/name";
128127
String performerName = "/ns:people/performers/performer[%s]/name";
129128

@@ -146,7 +145,6 @@ public void testString() throws Exception {
146145

147146
@Test
148147
public void testNumber() throws Exception {
149-
150148
String composerDouble = "/ns:people/composers/composer[%s]/someDouble";
151149

152150
this.mockServer.expect(requestTo("/composers"))
@@ -180,7 +178,6 @@ public void testBoolean() throws Exception {
180178

181179
@Test
182180
public void testNodeCount() throws Exception {
183-
184181
this.mockServer.expect(requestTo("/composers"))
185182
.andExpect(content().contentType("application/xml"))
186183
.andExpect(xpath("/ns:people/composers/composer", NS).nodeCount(4))
@@ -223,4 +220,5 @@ public List<Person> getPerformers() {
223220
return this.performers;
224221
}
225222
}
223+
226224
}

0 commit comments

Comments
 (0)