Browse Source

Polishing

(cherry picked from commit 6aa5931)
pull/1405/head
Juergen Hoeller 10 years ago
parent
commit
e30429051d
  1. 5
      spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java
  2. 20
      spring-core/src/main/java/org/springframework/core/env/ConfigurablePropertyResolver.java
  3. 4
      spring-core/src/main/java/org/springframework/util/StopWatch.java
  4. 50
      spring-core/src/test/java/org/springframework/core/SerializableTypeWrapperTests.java
  5. 15
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/AbstractRequestAttributesArgumentResolverTests.java
  6. 8
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestAttributeMethodArgumentResolverTests.java
  7. 8
      spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/SessionAttributeMethodArgumentResolverTests.java

5
spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java

@ -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.
@ -185,9 +185,6 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter {
method = ClassUtils.getStaticMethod(targetClass, "of", sourceClass); method = ClassUtils.getStaticMethod(targetClass, "of", sourceClass);
if (method == null) { if (method == null) {
method = ClassUtils.getStaticMethod(targetClass, "from", sourceClass); method = ClassUtils.getStaticMethod(targetClass, "from", sourceClass);
if (method == null) {
return null;
}
} }
} }
return method; return method;

20
spring-core/src/main/java/org/springframework/core/env/ConfigurablePropertyResolver.java vendored

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 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.
@ -19,10 +19,10 @@ package org.springframework.core.env;
import org.springframework.core.convert.support.ConfigurableConversionService; import org.springframework.core.convert.support.ConfigurableConversionService;
/** /**
* Configuration interface to be implemented by most if not all {@link PropertyResolver * Configuration interface to be implemented by most if not all {@link PropertyResolver}
* PropertyResolver} types. Provides facilities for accessing and customizing the * types. Provides facilities for accessing and customizing the
* {@link org.springframework.core.convert.ConversionService ConversionService} used when * {@link org.springframework.core.convert.ConversionService ConversionService}
* converting property values from one type to another. * used when converting property values from one type to another.
* *
* @author Chris Beams * @author Chris Beams
* @since 3.1 * @since 3.1
@ -30,7 +30,7 @@ import org.springframework.core.convert.support.ConfigurableConversionService;
public interface ConfigurablePropertyResolver extends PropertyResolver { public interface ConfigurablePropertyResolver extends PropertyResolver {
/** /**
* @return the {@link ConfigurableConversionService} used when performing type * Return the {@link ConfigurableConversionService} used when performing type
* conversions on properties. * conversions on properties.
* <p>The configurable nature of the returned conversion service allows for * <p>The configurable nature of the returned conversion service allows for
* the convenient addition and removal of individual {@code Converter} instances: * the convenient addition and removal of individual {@code Converter} instances:
@ -46,10 +46,10 @@ public interface ConfigurablePropertyResolver extends PropertyResolver {
/** /**
* Set the {@link ConfigurableConversionService} to be used when performing type * Set the {@link ConfigurableConversionService} to be used when performing type
* conversions on properties. * conversions on properties.
* <p><strong>Note:</strong> as an alternative to fully replacing the {@code * <p><strong>Note:</strong> as an alternative to fully replacing the
* ConversionService}, consider adding or removing individual {@code Converter} * {@code ConversionService}, consider adding or removing individual
* instances by drilling into {@link #getConversionService()} and calling methods * {@code Converter} instances by drilling into {@link #getConversionService()}
* such as {@code #addConverter}. * and calling methods such as {@code #addConverter}.
* @see PropertyResolver#getProperty(String, Class) * @see PropertyResolver#getProperty(String, Class)
* @see #getConversionService() * @see #getConversionService()
* @see org.springframework.core.convert.converter.ConverterRegistry#addConverter * @see org.springframework.core.convert.converter.ConverterRegistry#addConverter

4
spring-core/src/main/java/org/springframework/util/StopWatch.java

@ -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.
@ -134,7 +134,7 @@ public class StopWatch {
/** /**
* Stop the current task. The results are undefined if timing * Stop the current task. The results are undefined if timing
* methods are called without invoking at least one pair * methods are called without invoking at least one pair
* {@code #start()} / {@code #stop()} methods. * {@code start()} / {@code stop()} methods.
* @see #start() * @see #start()
*/ */
public void stop() throws IllegalStateException { public void stop() throws IllegalStateException {

50
spring-core/src/test/java/org/springframework/core/SerializableTypeWrapperTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 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.
@ -46,7 +46,7 @@ public class SerializableTypeWrapperTests {
public void forField() throws Exception { public void forField() throws Exception {
Type type = SerializableTypeWrapper.forField(Fields.class.getField("parameterizedType")); Type type = SerializableTypeWrapper.forField(Fields.class.getField("parameterizedType"));
assertThat(type.toString(), equalTo("java.util.List<java.lang.String>")); assertThat(type.toString(), equalTo("java.util.List<java.lang.String>"));
assertSerialzable(type); assertSerializable(type);
} }
@Test @Test
@ -54,7 +54,7 @@ public class SerializableTypeWrapperTests {
Method method = Methods.class.getDeclaredMethod("method", Class.class, Object.class); Method method = Methods.class.getDeclaredMethod("method", Class.class, Object.class);
Type type = SerializableTypeWrapper.forMethodParameter(MethodParameter.forMethodOrConstructor(method, 0)); Type type = SerializableTypeWrapper.forMethodParameter(MethodParameter.forMethodOrConstructor(method, 0));
assertThat(type.toString(), equalTo("java.lang.Class<T>")); assertThat(type.toString(), equalTo("java.lang.Class<T>"));
assertSerialzable(type); assertSerializable(type);
} }
@Test @Test
@ -62,62 +62,62 @@ public class SerializableTypeWrapperTests {
Constructor<?> constructor = Constructors.class.getDeclaredConstructor(List.class); Constructor<?> constructor = Constructors.class.getDeclaredConstructor(List.class);
Type type = SerializableTypeWrapper.forMethodParameter(MethodParameter.forMethodOrConstructor(constructor, 0)); Type type = SerializableTypeWrapper.forMethodParameter(MethodParameter.forMethodOrConstructor(constructor, 0));
assertThat(type.toString(), equalTo("java.util.List<java.lang.String>")); assertThat(type.toString(), equalTo("java.util.List<java.lang.String>"));
assertSerialzable(type); assertSerializable(type);
} }
@Test @Test
public void forGenericSuperClass() throws Exception { public void forGenericSuperClass() throws Exception {
Type type = SerializableTypeWrapper.forGenericSuperclass(ArrayList.class); Type type = SerializableTypeWrapper.forGenericSuperclass(ArrayList.class);
assertThat(type.toString(), equalTo("java.util.AbstractList<E>")); assertThat(type.toString(), equalTo("java.util.AbstractList<E>"));
assertSerialzable(type); assertSerializable(type);
} }
@Test @Test
public void forGenericInterfaces() throws Exception { public void forGenericInterfaces() throws Exception {
Type type = SerializableTypeWrapper.forGenericInterfaces(List.class)[0]; Type type = SerializableTypeWrapper.forGenericInterfaces(List.class)[0];
assertThat(type.toString(), equalTo("java.util.Collection<E>")); assertThat(type.toString(), equalTo("java.util.Collection<E>"));
assertSerialzable(type); assertSerializable(type);
} }
@Test @Test
public void forTypeParamters() throws Exception { public void forTypeParamters() throws Exception {
Type type = SerializableTypeWrapper.forTypeParameters(List.class)[0]; Type type = SerializableTypeWrapper.forTypeParameters(List.class)[0];
assertThat(type.toString(), equalTo("E")); assertThat(type.toString(), equalTo("E"));
assertSerialzable(type); assertSerializable(type);
} }
@Test @Test
public void classType() throws Exception { public void classType() throws Exception {
Type type = SerializableTypeWrapper.forField(Fields.class.getField("classType")); Type type = SerializableTypeWrapper.forField(Fields.class.getField("classType"));
assertThat(type.toString(), equalTo("class java.lang.String")); assertThat(type.toString(), equalTo("class java.lang.String"));
assertSerialzable(type); assertSerializable(type);
} }
@Test @Test
public void genericArrayType() throws Exception { public void genericArrayType() throws Exception {
GenericArrayType type = (GenericArrayType) SerializableTypeWrapper.forField(Fields.class.getField("genericArrayType")); GenericArrayType type = (GenericArrayType) SerializableTypeWrapper.forField(Fields.class.getField("genericArrayType"));
assertThat(type.toString(), equalTo("java.util.List<java.lang.String>[]")); assertThat(type.toString(), equalTo("java.util.List<java.lang.String>[]"));
assertSerialzable(type); assertSerializable(type);
assertSerialzable(type.getGenericComponentType()); assertSerializable(type.getGenericComponentType());
} }
@Test @Test
public void parameterizedType() throws Exception { public void parameterizedType() throws Exception {
ParameterizedType type = (ParameterizedType) SerializableTypeWrapper.forField(Fields.class.getField("parameterizedType")); ParameterizedType type = (ParameterizedType) SerializableTypeWrapper.forField(Fields.class.getField("parameterizedType"));
assertThat(type.toString(), equalTo("java.util.List<java.lang.String>")); assertThat(type.toString(), equalTo("java.util.List<java.lang.String>"));
assertSerialzable(type); assertSerializable(type);
assertSerialzable(type.getOwnerType()); assertSerializable(type.getOwnerType());
assertSerialzable(type.getRawType()); assertSerializable(type.getRawType());
assertSerialzable(type.getActualTypeArguments()); assertSerializable(type.getActualTypeArguments());
assertSerialzable(type.getActualTypeArguments()[0]); assertSerializable(type.getActualTypeArguments()[0]);
} }
@Test @Test
public void typeVariableType() throws Exception { public void typeVariableType() throws Exception {
TypeVariable<?> type = (TypeVariable<?>) SerializableTypeWrapper.forField(Fields.class.getField("typeVariableType")); TypeVariable<?> type = (TypeVariable<?>) SerializableTypeWrapper.forField(Fields.class.getField("typeVariableType"));
assertThat(type.toString(), equalTo("T")); assertThat(type.toString(), equalTo("T"));
assertSerialzable(type); assertSerializable(type);
assertSerialzable(type.getBounds()); assertSerializable(type.getBounds());
} }
@Test @Test
@ -125,13 +125,13 @@ public class SerializableTypeWrapperTests {
ParameterizedType typeSource = (ParameterizedType) SerializableTypeWrapper.forField(Fields.class.getField("wildcardType")); ParameterizedType typeSource = (ParameterizedType) SerializableTypeWrapper.forField(Fields.class.getField("wildcardType"));
WildcardType type = (WildcardType) typeSource.getActualTypeArguments()[0]; WildcardType type = (WildcardType) typeSource.getActualTypeArguments()[0];
assertThat(type.toString(), equalTo("? extends java.lang.CharSequence")); assertThat(type.toString(), equalTo("? extends java.lang.CharSequence"));
assertSerialzable(type); assertSerializable(type);
assertSerialzable(type.getLowerBounds()); assertSerializable(type.getLowerBounds());
assertSerialzable(type.getUpperBounds()); assertSerializable(type.getUpperBounds());
} }
private void assertSerialzable(Object source) throws Exception { private void assertSerializable(Object source) throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos); ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(source); oos.writeObject(source);
@ -152,19 +152,19 @@ public class SerializableTypeWrapperTests {
public T typeVariableType; public T typeVariableType;
public List<? extends CharSequence> wildcardType; public List<? extends CharSequence> wildcardType;
} }
static interface Methods {
<T> List<T> method(Class<T> p1, T p2); interface Methods {
<T> List<T> method(Class<T> p1, T p2);
} }
static class Constructors { static class Constructors {
public Constructors(List<String> p) { public Constructors(List<String> p) {
} }
} }
} }

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

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.servlet.mvc.method.annotation; package org.springframework.web.servlet.mvc.method.annotation;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -40,14 +41,8 @@ import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer; import org.springframework.web.method.support.ModelAndViewContainer;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse; import static org.mockito.BDDMockito.*;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
/** /**
@ -87,7 +82,7 @@ public abstract class AbstractRequestAttributesArgumentResolverTests {
@Test @Test
public void supportsParameter() throws Exception { public void supportsParameter() throws Exception {
assertTrue(this.resolver.supportsParameter(new MethodParameter(this.handleMethod, 0))); assertTrue(this.resolver.supportsParameter(new MethodParameter(this.handleMethod, 0)));
assertFalse(this.resolver.supportsParameter(new MethodParameter(this.handleMethod, 4))); assertFalse(this.resolver.supportsParameter(new MethodParameter(this.handleMethod, -1)));
} }
@Test @Test
@ -180,6 +175,8 @@ public abstract class AbstractRequestAttributesArgumentResolverTests {
@SessionAttribute(name="foo") Optional<Foo> optionalFoo) { @SessionAttribute(name="foo") Optional<Foo> optionalFoo) {
} }
private static class Foo { private static class Foo {
} }
} }

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

@ -13,19 +13,19 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.servlet.mvc.method.annotation; package org.springframework.web.servlet.mvc.method.annotation;
import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolver;
/** /**
* Unit tests for {@link RequestAttributeMethodArgumentResolver}. * Unit tests for {@link RequestAttributeMethodArgumentResolver}.
*
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 4.3
*/ */
public class RequestAttributeMethodArgumentResolverTests public class RequestAttributeMethodArgumentResolverTests extends AbstractRequestAttributesArgumentResolverTests {
extends AbstractRequestAttributesArgumentResolverTests {
@Override @Override
protected HandlerMethodArgumentResolver createResolver() { protected HandlerMethodArgumentResolver createResolver() {

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

@ -13,19 +13,19 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.web.servlet.mvc.method.annotation; package org.springframework.web.servlet.mvc.method.annotation;
import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolver;
/** /**
* Unit tests for {@link SessionAttributeMethodArgumentResolver}. * Unit tests for {@link SessionAttributeMethodArgumentResolver}.
*
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 4.3
*/ */
public class SessionAttributeMethodArgumentResolverTests public class SessionAttributeMethodArgumentResolverTests extends AbstractRequestAttributesArgumentResolverTests {
extends AbstractRequestAttributesArgumentResolverTests {
@Override @Override
protected HandlerMethodArgumentResolver createResolver() { protected HandlerMethodArgumentResolver createResolver() {

Loading…
Cancel
Save