1717package org .springframework .test .web .servlet .samples .standalone ;
1818
1919import java .io .StringWriter ;
20- import java .nio .charset .StandardCharsets ;
20+ import java .nio .charset .Charset ;
2121import java .util .Collection ;
2222import java .util .concurrent .Callable ;
2323import java .util .concurrent .CompletableFuture ;
@@ -78,7 +78,7 @@ public void callable() throws Exception {
7878 public void streaming () throws Exception {
7979 this .mockMvc .perform (get ("/1" ).param ("streaming" , "true" ))
8080 .andExpect (request ().asyncStarted ())
81- .andDo (r -> r . getAsyncResult () ) // fetch async result similar to "asyncDispatch" builder
81+ .andDo (MvcResult :: getAsyncResult ) // fetch async result similar to "asyncDispatch" builder
8282 .andExpect (status ().isOk ())
8383 .andExpect (content ().string ("name=Joe" ));
8484 }
@@ -87,7 +87,7 @@ public void streaming() throws Exception {
8787 public void streamingSlow () throws Exception {
8888 this .mockMvc .perform (get ("/1" ).param ("streamingSlow" , "true" ))
8989 .andExpect (request ().asyncStarted ())
90- .andDo (r -> r . getAsyncResult () )
90+ .andDo (MvcResult :: getAsyncResult )
9191 .andExpect (status ().isOk ())
9292 .andExpect (content ().string ("name=Joe&someBoolean=true" ));
9393 }
@@ -96,7 +96,7 @@ public void streamingSlow() throws Exception {
9696 public void streamingJson () throws Exception {
9797 this .mockMvc .perform (get ("/1" ).param ("streamingJson" , "true" ))
9898 .andExpect (request ().asyncStarted ())
99- .andDo (r -> r . getAsyncResult () )
99+ .andDo (MvcResult :: getAsyncResult )
100100 .andExpect (status ().isOk ())
101101 .andExpect (content ().contentType (MediaType .APPLICATION_JSON_UTF8_VALUE ))
102102 .andExpect (content ().string ("{\" name\" :\" Joe\" ,\" someDouble\" :0.5}" ));
@@ -129,10 +129,7 @@ public void deferredResultWithImmediateValue() throws Exception {
129129 .andExpect (content ().string ("{\" name\" :\" Joe\" ,\" someDouble\" :0.0,\" someBoolean\" :false}" ));
130130 }
131131
132- /**
133- * SPR-13079
134- */
135- @ Test
132+ @ Test // SPR-13079
136133 public void deferredResultWithDelayedError () throws Exception {
137134 MvcResult mvcResult = this .mockMvc .perform (get ("/1" ).param ("deferredResultWithDelayedError" , "true" ))
138135 .andExpect (request ().asyncStarted ())
@@ -157,10 +154,7 @@ public void listenableFuture() throws Exception {
157154 .andExpect (content ().string ("{\" name\" :\" Joe\" ,\" someDouble\" :0.0,\" someBoolean\" :false}" ));
158155 }
159156
160- /**
161- * SPR-12597
162- */
163- @ Test
157+ @ Test // SPR-12597
164158 public void completableFutureWithImmediateValue () throws Exception {
165159 MvcResult mvcResult = this .mockMvc .perform (get ("/1" ).param ("completableFutureWithImmediateValue" , "true" ))
166160 .andExpect (request ().asyncStarted ())
@@ -172,10 +166,7 @@ public void completableFutureWithImmediateValue() throws Exception {
172166 .andExpect (content ().string ("{\" name\" :\" Joe\" ,\" someDouble\" :0.0,\" someBoolean\" :false}" ));
173167 }
174168
175- /**
176- * SPR-12735
177- */
178- @ Test
169+ @ Test // SPR-12735
179170 public void printAsyncResult () throws Exception {
180171 StringWriter writer = new StringWriter ();
181172
@@ -203,12 +194,9 @@ public void printAsyncResult() throws Exception {
203194 @ RequestMapping (path = "/{id}" , produces = "application/json" )
204195 private static class AsyncController {
205196
206- private final Collection <DeferredResult <Person >> deferredResults =
207- new CopyOnWriteArrayList <DeferredResult <Person >>();
208-
209- private final Collection <ListenableFutureTask <Person >> futureTasks =
210- new CopyOnWriteArrayList <ListenableFutureTask <Person >>();
197+ private final Collection <DeferredResult <Person >> deferredResults = new CopyOnWriteArrayList <>();
211198
199+ private final Collection <ListenableFutureTask <Person >> futureTasks = new CopyOnWriteArrayList <>();
212200
213201 @ RequestMapping (params = "callable" )
214202 public Callable <Person > getCallable () {
@@ -217,7 +205,7 @@ public Callable<Person> getCallable() {
217205
218206 @ RequestMapping (params = "streaming" )
219207 public StreamingResponseBody getStreaming () {
220- return os -> os .write ("name=Joe" .getBytes ());
208+ return os -> os .write ("name=Joe" .getBytes (Charset . forName ( "UTF-8" ) ));
221209 }
222210
223211 @ RequestMapping (params = "streamingSlow" )
@@ -226,7 +214,7 @@ public StreamingResponseBody getStreamingSlow() {
226214 os .write ("name=Joe" .getBytes ());
227215 try {
228216 Thread .sleep (200 );
229- os .write ("&someBoolean=true" .getBytes ());
217+ os .write ("&someBoolean=true" .getBytes (Charset . forName ( "UTF-8" ) ));
230218 }
231219 catch (InterruptedException e ) {
232220 /* no-op */
@@ -237,26 +225,26 @@ public StreamingResponseBody getStreamingSlow() {
237225 @ RequestMapping (params = "streamingJson" )
238226 public ResponseEntity <StreamingResponseBody > getStreamingJson () {
239227 return ResponseEntity .ok ().contentType (MediaType .APPLICATION_JSON_UTF8 )
240- .body (os -> os .write ("{\" name\" :\" Joe\" ,\" someDouble\" :0.5}" .getBytes (StandardCharsets . UTF_8 )));
228+ .body (os -> os .write ("{\" name\" :\" Joe\" ,\" someDouble\" :0.5}" .getBytes (Charset . forName ( "UTF-8" ) )));
241229 }
242230
243231 @ RequestMapping (params = "deferredResult" )
244232 public DeferredResult <Person > getDeferredResult () {
245- DeferredResult <Person > deferredResult = new DeferredResult <Person >();
233+ DeferredResult <Person > deferredResult = new DeferredResult <>();
246234 this .deferredResults .add (deferredResult );
247235 return deferredResult ;
248236 }
249237
250238 @ RequestMapping (params = "deferredResultWithImmediateValue" )
251239 public DeferredResult <Person > getDeferredResultWithImmediateValue () {
252- DeferredResult <Person > deferredResult = new DeferredResult <Person >();
240+ DeferredResult <Person > deferredResult = new DeferredResult <>();
253241 deferredResult .setResult (new Person ("Joe" ));
254242 return deferredResult ;
255243 }
256244
257245 @ RequestMapping (params = "deferredResultWithDelayedError" )
258246 public DeferredResult <Person > getDeferredResultWithDelayedError () {
259- final DeferredResult <Person > deferredResult = new DeferredResult <Person >();
247+ final DeferredResult <Person > deferredResult = new DeferredResult <>();
260248 new Thread () {
261249 public void run () {
262250 try {
@@ -273,14 +261,14 @@ public void run() {
273261
274262 @ RequestMapping (params = "listenableFuture" )
275263 public ListenableFuture <Person > getListenableFuture () {
276- ListenableFutureTask <Person > futureTask = new ListenableFutureTask <Person >(() -> new Person ("Joe" ));
264+ ListenableFutureTask <Person > futureTask = new ListenableFutureTask <>(() -> new Person ("Joe" ));
277265 this .futureTasks .add (futureTask );
278266 return futureTask ;
279267 }
280268
281269 @ RequestMapping (params = "completableFutureWithImmediateValue" )
282270 public CompletableFuture <Person > getCompletableFutureWithImmediateValue () {
283- CompletableFuture <Person > future = new CompletableFuture <Person >();
271+ CompletableFuture <Person > future = new CompletableFuture <>();
284272 future .complete (new Person ("Joe" ));
285273 return future ;
286274 }
@@ -291,7 +279,7 @@ public String errorHandler(Exception e) {
291279 return e .getMessage ();
292280 }
293281
294- public void onMessage (String name ) {
282+ void onMessage (String name ) {
295283 for (DeferredResult <Person > deferredResult : this .deferredResults ) {
296284 deferredResult .setResult (new Person (name ));
297285 this .deferredResults .remove (deferredResult );
0 commit comments