Skip to content

Commit 4627545

Browse files
committed
Polishing
(cherry picked from commit eae079a)
1 parent e2ba7c9 commit 4627545

File tree

10 files changed

+58
-48
lines changed

10 files changed

+58
-48
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
@@ -56,15 +56,15 @@ public class DefaultResponseCreator implements ResponseCreator {
5656
* Use static factory methods in {@link MockRestResponseCreators}.
5757
*/
5858
protected DefaultResponseCreator(HttpStatus statusCode) {
59-
Assert.notNull(statusCode);
59+
Assert.notNull(statusCode, "HttpStatus must not be null");
6060
this.statusCode = statusCode;
6161
}
6262

6363

6464
@Override
6565
public ClientHttpResponse createResponse(ClientHttpRequest request) throws IOException {
6666
MockClientHttpResponse response;
67-
if (this.contentResource != null ){
67+
if (this.contentResource != null) {
6868
InputStream stream = this.contentResource.getInputStream();
6969
response = new MockClientHttpResponse(stream, this.statusCode);
7070
}

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

Lines changed: 10 additions & 8 deletions
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,18 +35,20 @@ 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);
4749
}
4850

49-
@Test(expected=AssertionError.class)
51+
@Test(expected = AssertionError.class)
5052
public void testNodeMatcherNoMatch() throws Exception {
5153
new XpathRequestMatchers("/foo/bar", null).node(Matchers.nullValue()).match(this.request);
5254
}
@@ -56,7 +58,7 @@ public void testExists() throws Exception {
5658
new XpathRequestMatchers("/foo/bar", null).exists().match(this.request);
5759
}
5860

59-
@Test(expected=AssertionError.class)
61+
@Test(expected = AssertionError.class)
6062
public void testExistsNoMatch() throws Exception {
6163
new XpathRequestMatchers("/foo/Bar", null).exists().match(this.request);
6264
}
@@ -66,7 +68,7 @@ public void testDoesNotExist() throws Exception {
6668
new XpathRequestMatchers("/foo/Bar", null).doesNotExist().match(this.request);
6769
}
6870

69-
@Test(expected=AssertionError.class)
71+
@Test(expected = AssertionError.class)
7072
public void testDoesNotExistNoMatch() throws Exception {
7173
new XpathRequestMatchers("/foo/bar", null).doesNotExist().match(this.request);
7274
}
@@ -76,7 +78,7 @@ public void testNodeCount() throws Exception {
7678
new XpathRequestMatchers("/foo/bar", null).nodeCount(2).match(this.request);
7779
}
7880

79-
@Test(expected=AssertionError.class)
81+
@Test(expected = AssertionError.class)
8082
public void testNodeCountNoMatch() throws Exception {
8183
new XpathRequestMatchers("/foo/bar", null).nodeCount(1).match(this.request);
8284
}
@@ -86,7 +88,7 @@ public void testString() throws Exception {
8688
new XpathRequestMatchers("/foo/bar[1]", null).string("111").match(this.request);
8789
}
8890

89-
@Test(expected=AssertionError.class)
91+
@Test(expected = AssertionError.class)
9092
public void testStringNoMatch() throws Exception {
9193
new XpathRequestMatchers("/foo/bar[1]", null).string("112").match(this.request);
9294
}
@@ -96,7 +98,7 @@ public void testNumber() throws Exception {
9698
new XpathRequestMatchers("/foo/bar[1]", null).number(111.0).match(this.request);
9799
}
98100

99-
@Test(expected=AssertionError.class)
101+
@Test(expected = AssertionError.class)
100102
public void testNumberNoMatch() throws Exception {
101103
new XpathRequestMatchers("/foo/bar[1]", null).number(111.1).match(this.request);
102104
}
@@ -106,7 +108,7 @@ public void testBoolean() throws Exception {
106108
new XpathRequestMatchers("/foo/bar[2]", null).booleanValue(true).match(this.request);
107109
}
108110

109-
@Test(expected=AssertionError.class)
111+
@Test(expected = AssertionError.class)
110112
public void testBooleanNoMatch() throws Exception {
111113
new XpathRequestMatchers("/foo/bar[2]", null).booleanValue(false).match(this.request);
112114
}

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: 3 additions & 2 deletions
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,9 +49,10 @@ public class ContentRequestMatchersIntegrationTests {
5049

5150
private RestTemplate restTemplate;
5251

52+
5353
@Before
5454
public void setup() {
55-
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
55+
List<HttpMessageConverter<?>> converters = new ArrayList<>();
5656
converters.add(new StringHttpMessageConverter());
5757
converters.add(new MappingJackson2HttpMessageConverter());
5858

@@ -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: 5 additions & 4 deletions
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.
@@ -44,13 +44,15 @@ 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() {
53-
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
55+
List<HttpMessageConverter<?>> converters = new ArrayList<>();
5456
converters.add(new StringHttpMessageConverter());
5557
converters.add(new MappingJackson2HttpMessageConverter());
5658

@@ -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: 6 additions & 3 deletions
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.
@@ -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;
@@ -45,7 +46,7 @@
4546
*/
4647
public class JsonPathRequestMatchersIntegrationTests {
4748

48-
private static final MultiValueMap<String, Person> people = new LinkedMultiValueMap<String, Person>();
49+
private static final MultiValueMap<String, Person> people = new LinkedMultiValueMap<>();
4950

5051
static {
5152
people.add("composers", new Person("Johann Sebastian Bach"));
@@ -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: 4 additions & 4 deletions
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.
@@ -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),
@@ -75,7 +75,7 @@ public void setup() {
7575

7676
this.people = new PeopleWrapper(composers);
7777

78-
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
78+
List<HttpMessageConverter<?>> converters = new ArrayList<>();
7979
converters.add(new Jaxb2RootElementHttpMessageConverter());
8080

8181
this.restTemplate = new RestTemplate();
@@ -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
}

0 commit comments

Comments
 (0)