提交 e0883f5e 编写于 作者: J Juergen Hoeller

Polishing

上级 59006391
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -255,7 +255,7 @@ class TypeConverterDelegate {
}
}
String trimmedValue = ((String) convertedValue).trim();
if (requiredType.isEnum() && "".equals(trimmedValue)) {
if (requiredType.isEnum() && trimmedValue.isEmpty()) {
// It's an empty enum identifier: reset the enum value to null.
return null;
}
......@@ -569,8 +569,7 @@ class TypeConverterDelegate {
return original;
}
int i = 0;
for (; it.hasNext(); i++) {
for (int i = 0; it.hasNext(); i++) {
Object element = it.next();
String indexedPropertyName = buildIndexedPropertyName(propertyName, i);
Object convertedElement = convertIfNecessary(indexedPropertyName, null, element,
......
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -49,7 +49,7 @@ public class DefaultNamespaceHandlerResolverTests {
}
@Test
public void testNonExistentHandlerClass() throws Exception {
public void testNonExistentHandlerClass() {
String mappingPath = "org/springframework/beans/factory/xml/support/nonExistent.properties";
try {
new DefaultNamespaceHandlerResolver(getClass().getClassLoader(), mappingPath);
......@@ -61,29 +61,18 @@ public class DefaultNamespaceHandlerResolverTests {
}
@Test
public void testResolveInvalidHandler() throws Exception {
String mappingPath = "org/springframework/beans/factory/xml/support/invalid.properties";
try {
new DefaultNamespaceHandlerResolver(getClass().getClassLoader(), mappingPath);
fail("Should not be able to map a class that doesn't implement NamespaceHandler");
}
catch (Throwable expected) {
}
}
@Test
public void testCtorWithNullClassLoaderArgument() throws Exception {
public void testCtorWithNullClassLoaderArgument() {
// simply must not bail...
new DefaultNamespaceHandlerResolver(null);
}
@Test(expected=IllegalArgumentException.class)
public void testCtorWithNullClassLoaderArgumentAndNullMappingLocationArgument() throws Exception {
@Test(expected = IllegalArgumentException.class)
public void testCtorWithNullClassLoaderArgumentAndNullMappingLocationArgument() {
new DefaultNamespaceHandlerResolver(null, null);
}
@Test
public void testCtorWithNonExistentMappingLocationArgument() throws Exception {
public void testCtorWithNonExistentMappingLocationArgument() {
// simply must not bail; we don't want non-existent resources to result in an Exception
new DefaultNamespaceHandlerResolver(null, "738trbc bobabloobop871");
}
......
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -31,10 +31,10 @@ import static org.junit.Assert.*;
* @author Arjen Poutsma
* @author Dave Syer
*/
public final class ResourceEditorTests {
public class ResourceEditorTests {
@Test
public void sunnyDay() throws Exception {
public void sunnyDay() {
PropertyEditor editor = new ResourceEditor();
editor.setAsText("classpath:org/springframework/core/io/ResourceEditorTests.class");
Resource resource = (Resource) editor.getValue();
......@@ -43,19 +43,19 @@ public final class ResourceEditorTests {
}
@Test(expected = IllegalArgumentException.class)
public void ctorWithNullCtorArgs() throws Exception {
public void ctorWithNullCtorArgs() {
new ResourceEditor(null, null);
}
@Test
public void setAndGetAsTextWithNull() throws Exception {
public void setAndGetAsTextWithNull() {
PropertyEditor editor = new ResourceEditor();
editor.setAsText(null);
assertEquals("", editor.getAsText());
}
@Test
public void setAndGetAsTextWithWhitespaceResource() throws Exception {
public void setAndGetAsTextWithWhitespaceResource() {
PropertyEditor editor = new ResourceEditor();
editor.setAsText(" ");
assertEquals("", editor.getAsText());
......@@ -75,14 +75,12 @@ public final class ResourceEditorTests {
}
}
@Test(expected=IllegalArgumentException.class)
@Test(expected = IllegalArgumentException.class)
public void testStrictSystemPropertyReplacement() {
PropertyEditor editor = new ResourceEditor(new DefaultResourceLoader(), new StandardEnvironment(), false);
System.setProperty("test.prop", "foo");
try {
editor.setAsText("${test.prop}-${bar}");
Resource resolved = (Resource) editor.getValue();
assertEquals("foo-${bar}", resolved.getFilename());
}
finally {
System.getProperties().remove("test.prop");
......
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -32,7 +32,7 @@ import static org.junit.Assert.*;
public class ResourceArrayPropertyEditorTests {
@Test
public void testVanillaResource() throws Exception {
public void testVanillaResource() {
PropertyEditor editor = new ResourceArrayPropertyEditor();
editor.setAsText("classpath:org/springframework/core/io/support/ResourceArrayPropertyEditor.class");
Resource[] resources = (Resource[]) editor.getValue();
......@@ -41,7 +41,7 @@ public class ResourceArrayPropertyEditorTests {
}
@Test
public void testPatternResource() throws Exception {
public void testPatternResource() {
// N.B. this will sometimes fail if you use classpath: instead of classpath*:.
// The result depends on the classpath - if test-classes are segregated from classes
// and they come first on the classpath (like in Maven) then it breaks, if classes
......@@ -67,7 +67,7 @@ public class ResourceArrayPropertyEditorTests {
}
}
@Test(expected=IllegalArgumentException.class)
@Test(expected = IllegalArgumentException.class)
public void testStrictSystemPropertyReplacement() {
PropertyEditor editor = new ResourceArrayPropertyEditor(
new PathMatchingResourcePatternResolver(), new StandardEnvironment(),
......@@ -75,8 +75,6 @@ public class ResourceArrayPropertyEditorTests {
System.setProperty("test.prop", "foo");
try {
editor.setAsText("${test.prop}-${bar}");
Resource[] resources = (Resource[]) editor.getValue();
assertEquals("foo-${bar}", resources[0].getFilename());
}
finally {
System.getProperties().remove("test.prop");
......
......@@ -266,8 +266,8 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
if (contentType != null) {
return MediaType.MULTIPART_FORM_DATA.includes(contentType);
}
for (String name : map.keySet()) {
for (Object value : map.get(name)) {
for (List<?> values : map.values()) {
for (Object value : values) {
if (value != null && !(value instanceof String)) {
return true;
}
......
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -54,7 +54,7 @@ public class DeferredResult<T> {
private static final Log logger = LogFactory.getLog(DeferredResult.class);
private final Long timeout;
private final Long timeoutValue;
private final Object timeoutResult;
......@@ -77,25 +77,25 @@ public class DeferredResult<T> {
}
/**
* Create a DeferredResult with a timeout value.
* Create a DeferredResult with a custom timeout value.
* <p>By default not set in which case the default configured in the MVC
* Java Config or the MVC namespace is used, or if that's not set, then the
* timeout depends on the default of the underlying server.
* @param timeout timeout value in milliseconds
* @param timeoutValue timeout value in milliseconds
*/
public DeferredResult(Long timeout) {
this(timeout, RESULT_NONE);
public DeferredResult(Long timeoutValue) {
this(timeoutValue, RESULT_NONE);
}
/**
* Create a DeferredResult with a timeout value and a default result to use
* in case of timeout.
* @param timeout timeout value in milliseconds (ignored if {@code null})
* @param timeoutValue timeout value in milliseconds (ignored if {@code null})
* @param timeoutResult the result to use
*/
public DeferredResult(Long timeout, Object timeoutResult) {
public DeferredResult(Long timeoutValue, Object timeoutResult) {
this.timeoutValue = timeoutValue;
this.timeoutResult = timeoutResult;
this.timeout = timeout;
}
......@@ -134,7 +134,7 @@ public class DeferredResult<T> {
* Return the configured timeout value in milliseconds.
*/
final Long getTimeoutValue() {
return this.timeout;
return this.timeoutValue;
}
/**
......
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -67,14 +67,14 @@ import org.springframework.web.util.WebUtils;
*/
public abstract class AbstractSockJsService implements SockJsService, CorsConfigurationSource {
private static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
private static final String XFRAME_OPTIONS_HEADER = "X-Frame-Options";
private static final long ONE_YEAR = TimeUnit.DAYS.toSeconds(365);
private static final Random random = new Random();
private static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
private static final String XFRAME_OPTIONS_HEADER = "X-Frame-Options";
private static final Random random = new Random();
protected final Log logger = LogFactory.getLog(getClass());
......@@ -88,9 +88,9 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
private boolean sessionCookieNeeded = true;
private long heartbeatTime = 25 * 1000;
private long heartbeatTime = TimeUnit.SECONDS.toMillis(25);
private long disconnectDelay = 5 * 1000;
private long disconnectDelay = TimeUnit.SECONDS.toMillis(5);
private int httpMessageCacheSize = 100;
......@@ -287,8 +287,9 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
}
/**
* Return if automatic addition of CORS headers has been disabled.
* @since 4.1.2
* @see #setSuppressCors(boolean)
* @see #setSuppressCors
*/
public boolean shouldSuppressCors() {
return this.suppressCors;
......@@ -316,6 +317,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
}
/**
* Return configure allowed {@code Origin} header values.
* @since 4.1.2
* @see #setAllowedOrigins
*/
......@@ -350,7 +352,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
String requestInfo = (logger.isDebugEnabled() ? request.getMethod() + " " + request.getURI() : null);
try {
if (sockJsPath.equals("") || sockJsPath.equals("/")) {
if (sockJsPath.isEmpty() || sockJsPath.equals("/")) {
if (requestInfo != null) {
logger.debug("Processing transport request: " + requestInfo);
}
......@@ -571,21 +573,21 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
private static final String IFRAME_CONTENT =
"<!DOCTYPE html>\n" +
"<html>\n" +
"<head>\n" +
" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n" +
" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" +
" <script>\n" +
" document.domain = document.domain;\n" +
" _sockjs_onload = function(){SockJS.bootstrap_iframe();};\n" +
" </script>\n" +
" <script src=\"%s\"></script>\n" +
"</head>\n" +
"<body>\n" +
" <h2>Don't panic!</h2>\n" +
" <p>This is a SockJS hidden iframe. It's used for cross domain magic.</p>\n" +
"</body>\n" +
"</html>";
"<html>\n" +
"<head>\n" +
" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n" +
" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" +
" <script>\n" +
" document.domain = document.domain;\n" +
" _sockjs_onload = function(){SockJS.bootstrap_iframe();};\n" +
" </script>\n" +
" <script src=\"%s\"></script>\n" +
"</head>\n" +
"<body>\n" +
" <h2>Don't panic!</h2>\n" +
" <p>This is a SockJS hidden iframe. It's used for cross domain magic.</p>\n" +
"</body>\n" +
"</html>";
@Override
public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册