Polishing

This commit is contained in:
Juergen Hoeller 2016-08-26 13:27:33 +02:00
parent a8f7f75f64
commit 14046575b0
6 changed files with 23 additions and 18 deletions

View File

@ -16,7 +16,6 @@
package org.springframework.util; package org.springframework.util;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
import java.util.Properties; import java.util.Properties;

View File

@ -19,7 +19,6 @@ package org.springframework.messaging.simp.annotation.support;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.Principal; import java.security.Principal;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,7 +17,6 @@
package org.springframework.messaging.simp.annotation.support; package org.springframework.messaging.simp.annotation.support;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.Principal; import java.security.Principal;

View File

@ -17,6 +17,7 @@
package org.springframework.test.web.servlet.samples.standalone; package org.springframework.test.web.servlet.samples.standalone;
import java.io.StringWriter; import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.util.Collection; import java.util.Collection;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -39,7 +40,6 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult; import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody; import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
@ -154,10 +154,7 @@ public class AsyncTests {
.andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}")); .andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"));
} }
/** @Test // SPR-12597
* SPR-12597
*/
@Test
public void completableFutureWithImmediateValue() throws Exception { public void completableFutureWithImmediateValue() throws Exception {
MvcResult mvcResult = this.mockMvc.perform(get("/1").param("completableFutureWithImmediateValue", "true")) MvcResult mvcResult = this.mockMvc.perform(get("/1").param("completableFutureWithImmediateValue", "true"))
.andExpect(request().asyncStarted()) .andExpect(request().asyncStarted())
@ -169,10 +166,7 @@ public class AsyncTests {
.andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}")); .andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"));
} }
/** @Test // SPR-12735
* SPR-12735
*/
@Test
public void printAsyncResult() throws Exception { public void printAsyncResult() throws Exception {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
@ -204,7 +198,6 @@ public class AsyncTests {
private final Collection<ListenableFutureTask<Person>> futureTasks = new CopyOnWriteArrayList<>(); private final Collection<ListenableFutureTask<Person>> futureTasks = new CopyOnWriteArrayList<>();
@RequestMapping(params = "callable") @RequestMapping(params = "callable")
public Callable<Person> getCallable() { public Callable<Person> getCallable() {
return () -> new Person("Joe"); return () -> new Person("Joe");
@ -212,7 +205,7 @@ public class AsyncTests {
@RequestMapping(params = "streaming") @RequestMapping(params = "streaming")
public StreamingResponseBody getStreaming() { public StreamingResponseBody getStreaming() {
return os -> os.write("name=Joe".getBytes(UTF_8)); return os -> os.write("name=Joe".getBytes(StandardCharsets.UTF_8));
} }
@RequestMapping(params = "streamingSlow") @RequestMapping(params = "streamingSlow")
@ -221,7 +214,7 @@ public class AsyncTests {
os.write("name=Joe".getBytes()); os.write("name=Joe".getBytes());
try { try {
Thread.sleep(200); Thread.sleep(200);
os.write("&someBoolean=true".getBytes(UTF_8)); os.write("&someBoolean=true".getBytes(StandardCharsets.UTF_8));
} }
catch (InterruptedException e) { catch (InterruptedException e) {
/* no-op */ /* no-op */
@ -232,7 +225,7 @@ public class AsyncTests {
@RequestMapping(params = "streamingJson") @RequestMapping(params = "streamingJson")
public ResponseEntity<StreamingResponseBody> getStreamingJson() { public ResponseEntity<StreamingResponseBody> getStreamingJson() {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON_UTF8) return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON_UTF8)
.body(os -> os.write("{\"name\":\"Joe\",\"someDouble\":0.5}".getBytes(UTF_8))); .body(os -> os.write("{\"name\":\"Joe\",\"someDouble\":0.5}".getBytes(StandardCharsets.UTF_8)));
} }
@RequestMapping(params = "deferredResult") @RequestMapping(params = "deferredResult")

View File

@ -933,18 +933,21 @@ public class MvcNamespaceTests {
public @interface IsoDate { public @interface IsoDate {
} }
@NumberFormat(style = NumberFormat.Style.PERCENT) @NumberFormat(style = NumberFormat.Style.PERCENT)
@Target({ElementType.PARAMETER}) @Target({ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface PercentNumber { public @interface PercentNumber {
} }
@Validated(MyGroup.class) @Validated(MyGroup.class)
@Target({ElementType.PARAMETER}) @Target({ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface MyValid { public @interface MyValid {
} }
@Controller @Controller
public static class TestController { public static class TestController {
@ -955,13 +958,16 @@ public class MvcNamespaceTests {
private boolean recordedValidationError; private boolean recordedValidationError;
@RequestMapping @RequestMapping
public void testBind(@RequestParam @IsoDate Date date, @RequestParam(required = false) @PercentNumber Double percent, @MyValid TestBean bean, BindingResult result) { public void testBind(@RequestParam @IsoDate Date date,
@RequestParam(required = false) @PercentNumber Double percent,
@MyValid TestBean bean, BindingResult result) {
this.date = date; this.date = date;
this.percent = percent; this.percent = percent;
this.recordedValidationError = (result.getErrorCount() == 1); this.recordedValidationError = (result.getErrorCount() == 1);
} }
} }
public static class TestValidator implements Validator { public static class TestValidator implements Validator {
boolean validatorInvoked; boolean validatorInvoked;
@ -977,10 +983,12 @@ public class MvcNamespaceTests {
} }
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface MyGroup { public @interface MyGroup {
} }
private static class TestBean { private static class TestBean {
@NotNull(groups = MyGroup.class) @NotNull(groups = MyGroup.class)
@ -997,6 +1005,7 @@ public class MvcNamespaceTests {
} }
} }
private static class TestMockServletContext extends MockServletContext { private static class TestMockServletContext extends MockServletContext {
@Override @Override
@ -1015,12 +1024,15 @@ public class MvcNamespaceTests {
} }
} }
public static class TestCallableProcessingInterceptor extends CallableProcessingInterceptorAdapter { public static class TestCallableProcessingInterceptor extends CallableProcessingInterceptorAdapter {
} }
public static class TestDeferredResultProcessingInterceptor extends DeferredResultProcessingInterceptorAdapter { public static class TestDeferredResultProcessingInterceptor extends DeferredResultProcessingInterceptorAdapter {
} }
public static class TestPathMatcher implements PathMatcher { public static class TestPathMatcher implements PathMatcher {
@Override @Override
@ -1059,9 +1071,11 @@ public class MvcNamespaceTests {
} }
} }
public static class TestPathHelper extends UrlPathHelper { public static class TestPathHelper extends UrlPathHelper {
} }
public static class TestCacheManager implements CacheManager { public static class TestCacheManager implements CacheManager {
@Override @Override

View File

@ -62,6 +62,7 @@ public class GroovyMarkupViewTests {
this.servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.webAppContext); this.servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.webAppContext);
} }
@Test @Test
public void missingGroovyMarkupConfig() throws Exception { public void missingGroovyMarkupConfig() throws Exception {
GroovyMarkupView view = new GroovyMarkupView(); GroovyMarkupView view = new GroovyMarkupView();