Skip to content

Commit e828be9

Browse files
committed
Polishing
1 parent 52447ef commit e828be9

File tree

7 files changed

+53
-66
lines changed

7 files changed

+53
-66
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-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: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,7 @@
5050
import org.springframework.util.concurrent.ListenableFuture;
5151
import org.springframework.util.concurrent.ListenableFutureCallback;
5252

53-
import static org.junit.Assert.assertArrayEquals;
54-
import static org.junit.Assert.assertEquals;
55-
import static org.junit.Assert.assertFalse;
56-
import static org.junit.Assert.assertNotNull;
57-
import static org.junit.Assert.assertNull;
58-
import static org.junit.Assert.assertSame;
59-
import static org.junit.Assert.assertTrue;
60-
import static org.junit.Assert.fail;
53+
import static org.junit.Assert.*;
6154

6255
/**
6356
* @author Arjen Poutsma
@@ -185,7 +178,7 @@ public void headForHeadersCallbackWithLambdas() throws Exception {
185178
@Test
186179
public void postForLocation() throws Exception {
187180
HttpHeaders entityHeaders = new HttpHeaders();
188-
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-15")));
181+
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-1")));
189182
HttpEntity<String> entity = new HttpEntity<>(helloWorld, entityHeaders);
190183
Future<URI> locationFuture = template.postForLocation(baseUrl + "/{method}", entity, "post");
191184
URI location = locationFuture.get();
@@ -195,7 +188,7 @@ public void postForLocation() throws Exception {
195188
@Test
196189
public void postForLocationCallback() throws Exception {
197190
HttpHeaders entityHeaders = new HttpHeaders();
198-
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-15")));
191+
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-1")));
199192
HttpEntity<String> entity = new HttpEntity<>(helloWorld, entityHeaders);
200193
final URI expected = new URI(baseUrl + "/post/1");
201194
ListenableFuture<URI> locationFuture = template.postForLocation(baseUrl + "/{method}", entity, "post");
@@ -215,7 +208,7 @@ public void onFailure(Throwable ex) {
215208
@Test
216209
public void postForLocationCallbackWithLambdas() throws Exception {
217210
HttpHeaders entityHeaders = new HttpHeaders();
218-
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-15")));
211+
entityHeaders.setContentType(new MediaType("text", "plain", Charset.forName("ISO-8859-1")));
219212
HttpEntity<String> entity = new HttpEntity<>(helloWorld, entityHeaders);
220213
final URI expected = new URI(baseUrl + "/post/1");
221214
ListenableFuture<URI> locationFuture = template.postForLocation(baseUrl + "/{method}", entity, "post");

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import com.fasterxml.jackson.annotation.JsonTypeInfo;
2929
import com.fasterxml.jackson.annotation.JsonTypeName;
30+
import com.fasterxml.jackson.annotation.JsonView;
3031
import org.junit.Test;
3132

3233
import org.springframework.core.ParameterizedTypeReference;
@@ -44,8 +45,6 @@
4445
import org.springframework.util.LinkedMultiValueMap;
4546
import org.springframework.util.MultiValueMap;
4647

47-
import com.fasterxml.jackson.annotation.JsonView;
48-
4948
import static org.junit.Assert.*;
5049

5150
/**
@@ -264,9 +263,12 @@ public void jsonPostForObjectWithJacksonTypeInfoList() throws URISyntaxException
264263
assertTrue(content.contains("\"type\":\"bar\""));
265264
}
266265

266+
267267
public interface MyJacksonView1 {};
268+
268269
public interface MyJacksonView2 {};
269270

271+
270272
public static class MySampleBean {
271273

272274
@JsonView(MyJacksonView1.class)
@@ -311,6 +313,7 @@ public void setWithout(String without) {
311313
}
312314
}
313315

316+
314317
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
315318
public static class ParentClass {
316319

@@ -332,6 +335,7 @@ public void setParentProperty(String parentProperty) {
332335
}
333336
}
334337

338+
335339
@JsonTypeName("foo")
336340
public static class Foo extends ParentClass {
337341

@@ -343,6 +347,7 @@ public Foo(String parentProperty) {
343347
}
344348
}
345349

350+
346351
@JsonTypeName("bar")
347352
public static class Bar extends ParentClass {
348353

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
}

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartIntegrationTests.java

Lines changed: 9 additions & 10 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.
@@ -30,7 +30,6 @@
3030
import org.eclipse.jetty.server.Server;
3131
import org.eclipse.jetty.servlet.ServletContextHandler;
3232
import org.eclipse.jetty.servlet.ServletHolder;
33-
3433
import org.junit.AfterClass;
3534
import org.junit.Assert;
3635
import org.junit.Before;
@@ -116,6 +115,13 @@ public static void startServer() throws Exception {
116115
baseUrl = "http://localhost:" + connector.getLocalPort();
117116
}
118117

118+
@AfterClass
119+
public static void stopServer() throws Exception {
120+
if (server != null) {
121+
server.stop();
122+
}
123+
}
124+
119125
@Before
120126
public void setUp() {
121127
ByteArrayHttpMessageConverter emptyBodyConverter = new ByteArrayHttpMessageConverter();
@@ -134,13 +140,6 @@ public void setUp() {
134140
restTemplate.setMessageConverters(Collections.singletonList(converter));
135141
}
136142

137-
@AfterClass
138-
public static void stopServer() throws Exception {
139-
if (server != null) {
140-
server.stop();
141-
}
142-
}
143-
144143

145144
@Test
146145
public void commonsMultipartResolver() throws Exception {
@@ -172,7 +171,7 @@ public void standardMultipartResolverWithEncodedFileName() throws Exception {
172171
RequestEntity<byte[]> requestEntity =
173172
RequestEntity.post(new URI(baseUrl + "/standard-resolver/spr13319"))
174173
.contentType(new MediaType(MediaType.MULTIPART_FORM_DATA, params))
175-
.body(content.getBytes(Charset.forName("us-ascii")));
174+
.body(content.getBytes(Charset.forName("US-ASCII")));
176175

177176
ByteArrayHttpMessageConverter converter = new ByteArrayHttpMessageConverter();
178177
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.MULTIPART_FORM_DATA));

0 commit comments

Comments
 (0)