Skip to content

Commit 5b0722e

Browse files
committed
Polishing
(cherry picked from commit e828be9)
1 parent 2adbfb6 commit 5b0722e

File tree

8 files changed

+61
-79
lines changed

8 files changed

+61
-79
lines changed

spring-messaging/src/test/java/org/springframework/messaging/converter/MappingJackson2MessageConverterTests.java

Lines changed: 18 additions & 13 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.
@@ -199,6 +199,20 @@ public void toMessageJsonView() throws Exception {
199199
}
200200

201201

202+
203+
@JsonView(MyJacksonView1.class)
204+
public JacksonViewBean jsonViewResponse() {
205+
JacksonViewBean bean = new JacksonViewBean();
206+
bean.setWithView1("with");
207+
bean.setWithView2("with");
208+
bean.setWithoutView("with");
209+
return bean;
210+
}
211+
212+
public void jsonViewPayload(@JsonView(MyJacksonView2.class) JacksonViewBean payload) {
213+
}
214+
215+
202216
public static class MyBean {
203217

204218
private String string;
@@ -262,9 +276,12 @@ public void setArray(String[] array) {
262276
}
263277
}
264278

279+
265280
public interface MyJacksonView1 {};
281+
266282
public interface MyJacksonView2 {};
267283

284+
268285
public static class JacksonViewBean {
269286

270287
@JsonView(MyJacksonView1.class)
@@ -300,16 +317,4 @@ public void setWithoutView(String withoutView) {
300317
}
301318
}
302319

303-
@JsonView(MyJacksonView1.class)
304-
public JacksonViewBean jsonViewResponse() {
305-
JacksonViewBean bean = new JacksonViewBean();
306-
bean.setWithView1("with");
307-
bean.setWithView2("with");
308-
bean.setWithoutView("with");
309-
return bean;
310-
}
311-
312-
public void jsonViewPayload(@JsonView(MyJacksonView2.class) JacksonViewBean payload) {
313-
}
314-
315320
}

spring-messaging/src/test/java/org/springframework/messaging/core/GenericMessagingTemplateTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 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.
@@ -66,7 +66,6 @@ public void setup() {
6666

6767
@Test
6868
public void sendAndReceive() {
69-
7069
SubscribableChannel channel = new ExecutorSubscribableChannel(this.executor);
7170
channel.subscribe(new MessageHandler() {
7271
@Override
@@ -82,7 +81,6 @@ public void handleMessage(Message<?> message) throws MessagingException {
8281

8382
@Test
8483
public void sendAndReceiveTimeout() throws InterruptedException {
85-
8684
final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();
8785
final CountDownLatch latch = new CountDownLatch(1);
8886

@@ -118,8 +116,9 @@ public void handleMessage(Message<?> message) throws MessagingException {
118116
assertNull(this.template.convertSendAndReceive(channel, "request", String.class));
119117
assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
120118

121-
if (failure.get() != null) {
122-
throw new AssertionError(failure.get());
119+
Throwable ex = failure.get();
120+
if (ex != null) {
121+
throw new AssertionError(ex);
123122
}
124123
}
125124

@@ -138,11 +137,13 @@ public void convertAndSendWithSimpMessageHeaders() {
138137
assertFalse(accessor.isMutable());
139138
}
140139

140+
141141
private class TestDestinationResolver implements DestinationResolver<MessageChannel> {
142142

143143
@Override
144144
public MessageChannel resolveDestination(String name) throws DestinationResolutionException {
145145
return messageChannel;
146146
}
147147
}
148+
148149
}

spring-test/src/main/java/org/springframework/test/util/JsonPathExpectationsHelper.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,18 @@
2222
import java.util.List;
2323
import java.util.Map;
2424

25+
import com.jayway.jsonpath.InvalidPathException;
26+
import com.jayway.jsonpath.JsonPath;
2527
import org.hamcrest.Matcher;
2628

2729
import org.springframework.util.Assert;
2830
import org.springframework.util.ObjectUtils;
2931
import org.springframework.util.ReflectionUtils;
3032
import org.springframework.util.StringUtils;
3133

32-
import com.jayway.jsonpath.InvalidPathException;
33-
import com.jayway.jsonpath.JsonPath;
34-
35-
import static org.hamcrest.MatcherAssert.assertThat;
36-
import static org.hamcrest.core.IsInstanceOf.instanceOf;
37-
import static org.springframework.test.util.AssertionErrors.assertEquals;
38-
import static org.springframework.test.util.AssertionErrors.assertTrue;
39-
import static org.springframework.test.util.AssertionErrors.fail;
34+
import static org.hamcrest.MatcherAssert.*;
35+
import static org.hamcrest.core.IsInstanceOf.*;
36+
import static org.springframework.test.util.AssertionErrors.*;
4037

4138
/**
4239
* A helper class for applying assertions via JSON path expressions.
@@ -257,9 +254,6 @@ private Object evaluateJsonPath(String content) throws ParseException {
257254
catch (InvalidPathException ex) {
258255
throw new AssertionError(message + ex.getMessage());
259256
}
260-
catch (ArrayIndexOutOfBoundsException ex) {
261-
throw new AssertionError(message + ex.getMessage());
262-
}
263257
catch (IndexOutOfBoundsException ex) {
264258
throw new AssertionError(message + ex.getMessage());
265259
}

spring-web/src/test/java/org/springframework/http/converter/ObjectToStringHttpMessageConverterTests.java

Lines changed: 1 addition & 8 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.
@@ -123,28 +123,21 @@ public void writeAcceptCharsetTurnedOff() throws IOException {
123123
@Test
124124
public void read() throws IOException {
125125
MockHttpServletRequest request = new MockHttpServletRequest();
126-
127126
request.setContentType(MediaType.TEXT_PLAIN_VALUE);
128127

129128
Short shortValue = Short.valueOf((short) 781);
130-
131129
request.setContent(shortValue.toString().getBytes(
132130
StringHttpMessageConverter.DEFAULT_CHARSET));
133-
134131
assertEquals(shortValue, this.converter.read(Short.class, new ServletServerHttpRequest(request)));
135132

136133
Float floatValue = Float.valueOf(123);
137-
138134
request.setCharacterEncoding("UTF-16");
139135
request.setContent(floatValue.toString().getBytes("UTF-16"));
140-
141136
assertEquals(floatValue, this.converter.read(Float.class, new ServletServerHttpRequest(request)));
142137

143138
Long longValue = Long.valueOf(55819182821331L);
144-
145139
request.setCharacterEncoding("UTF-8");
146140
request.setContent(longValue.toString().getBytes("UTF-8"));
147-
148141
assertEquals(longValue, this.converter.read(Long.class, new ServletServerHttpRequest(request)));
149142
}
150143

spring-web/src/test/java/org/springframework/web/client/AsyncRestTemplateIntegrationTests.java

Lines changed: 8 additions & 9 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.
@@ -49,14 +49,14 @@
4949
*/
5050
public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCase {
5151

52-
private final AsyncRestTemplate template = new AsyncRestTemplate(new HttpComponentsAsyncClientHttpRequestFactory());
52+
private final AsyncRestTemplate template = new AsyncRestTemplate(
53+
new HttpComponentsAsyncClientHttpRequestFactory());
5354

5455

5556
@Test
5657
public void getEntity() throws Exception {
57-
Future<ResponseEntity<String>> futureEntity =
58-
template.getForEntity(baseUrl + "/{method}", String.class, "get");
59-
ResponseEntity<String> entity = futureEntity.get();
58+
Future<ResponseEntity<String>> future = template.getForEntity(baseUrl + "/{method}", String.class, "get");
59+
ResponseEntity<String> entity = future.get();
6060
assertEquals("Invalid content", helloWorld, entity.getBody());
6161
assertFalse("No headers", entity.getHeaders().isEmpty());
6262
assertEquals("Invalid content-type", textContentType, entity.getHeaders().getContentType());
@@ -65,10 +65,9 @@ public void getEntity() throws Exception {
6565

6666
@Test
6767
public void multipleFutureGets() throws Exception {
68-
Future<ResponseEntity<String>> futureEntity =
69-
template.getForEntity(baseUrl + "/{method}", String.class, "get");
70-
futureEntity.get();
71-
futureEntity.get();
68+
Future<ResponseEntity<String>> future = template.getForEntity(baseUrl + "/{method}", String.class, "get");
69+
future.get();
70+
future.get();
7271
}
7372

7473
@Test

spring-web/src/test/java/org/springframework/web/client/RestTemplateIntegrationTests.java

Lines changed: 6 additions & 6 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.
@@ -23,6 +23,7 @@
2323
import java.util.EnumSet;
2424
import java.util.Set;
2525

26+
import com.fasterxml.jackson.annotation.JsonView;
2627
import org.junit.Test;
2728

2829
import org.springframework.core.io.ClassPathResource;
@@ -38,8 +39,6 @@
3839
import org.springframework.util.LinkedMultiValueMap;
3940
import org.springframework.util.MultiValueMap;
4041

41-
import com.fasterxml.jackson.annotation.JsonView;
42-
4342
import static org.junit.Assert.*;
4443

4544
/**
@@ -235,17 +234,18 @@ public void jsonPostForObjectWithJacksonView() throws URISyntaxException {
235234
assertFalse(s.contains("\"without\":\"without\""));
236235
}
237236

238-
// SPR-12123
239-
240-
@Test
237+
@Test // SPR-12123
241238
public void serverPort() {
242239
String s = template.getForObject("http://localhost:{port}/get", String.class, port);
243240
assertEquals("Invalid content", helloWorld, s);
244241
}
245242

243+
246244
public interface MyJacksonView1 {};
245+
247246
public interface MyJacksonView2 {};
248247

248+
249249
public static class MySampleBean {
250250

251251
@JsonView(MyJacksonView1.class)

spring-web/src/test/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequestTests.java

Lines changed: 8 additions & 17 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.
@@ -18,7 +18,6 @@
1818

1919
import java.net.URI;
2020
import java.nio.charset.Charset;
21-
2221
import javax.servlet.http.HttpServletRequest;
2322
import javax.servlet.http.HttpServletRequestWrapper;
2423

@@ -33,9 +32,7 @@
3332
import org.springframework.util.FileCopyUtils;
3433
import org.springframework.web.multipart.MultipartFile;
3534

36-
import static org.junit.Assert.assertArrayEquals;
37-
import static org.junit.Assert.assertEquals;
38-
import static org.junit.Assert.assertNotNull;
35+
import static org.junit.Assert.*;
3936

4037
/**
4138
* @author Rossen Stoyanchev
@@ -89,9 +86,7 @@ public void getBody() throws Exception {
8986
assertArrayEquals(bytes, result);
9087
}
9188

92-
// SPR-13317
93-
94-
@Test
89+
@Test // SPR-13317
9590
public void getBodyWithWrappedRequest() throws Exception {
9691
byte[] bytes = "content".getBytes("UTF-8");
9792
MultipartFile part = new MockMultipartFile("part", "", "application/json", bytes);
@@ -103,43 +98,39 @@ public void getBodyWithWrappedRequest() throws Exception {
10398
assertArrayEquals(bytes, result);
10499
}
105100

106-
// SPR-13096
107-
108-
@Test
101+
@Test // SPR-13096
109102
public void getBodyViaRequestParameter() throws Exception {
110103
MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest() {
111-
112104
@Override
113105
public HttpHeaders getMultipartHeaders(String paramOrFileName) {
114106
HttpHeaders headers = new HttpHeaders();
115107
headers.setContentType(new MediaType("application", "octet-stream", Charset.forName("iso-8859-1")));
116108
return headers;
117109
}
118110
};
111+
119112
byte[] bytes = {(byte) 0xC4};
120-
mockRequest.setParameter("part", new String(bytes, Charset.forName("iso-8859-1")));
113+
mockRequest.setParameter("part", new String(bytes, Charset.forName("ISO-8859-1")));
121114
ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part");
122-
123115
byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
124116
assertArrayEquals(bytes, result);
125117
}
126118

127119
@Test
128120
public void getBodyViaRequestParameterWithRequestEncoding() throws Exception {
129121
MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest() {
130-
131122
@Override
132123
public HttpHeaders getMultipartHeaders(String paramOrFileName) {
133124
HttpHeaders headers = new HttpHeaders();
134125
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
135126
return headers;
136127
}
137128
};
129+
138130
byte[] bytes = {(byte) 0xC4};
139-
mockRequest.setParameter("part", new String(bytes, Charset.forName("iso-8859-1")));
131+
mockRequest.setParameter("part", new String(bytes, Charset.forName("ISO-8859-1")));
140132
mockRequest.setCharacterEncoding("iso-8859-1");
141133
ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part");
142-
143134
byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
144135
assertArrayEquals(bytes, result);
145136
}

0 commit comments

Comments
 (0)