Merge branch '5.1.x'
This commit is contained in:
commit
c78960a1ba
|
@ -121,6 +121,7 @@ public abstract class ClassUtils {
|
|||
primitiveWrapperTypeMap.put(Integer.class, int.class);
|
||||
primitiveWrapperTypeMap.put(Long.class, long.class);
|
||||
primitiveWrapperTypeMap.put(Short.class, short.class);
|
||||
primitiveWrapperTypeMap.put(Void.class, void.class);
|
||||
|
||||
// Map entry iteration is less expensive to initialize than forEach with lambdas
|
||||
for (Map.Entry<Class<?>, Class<?>> entry : primitiveWrapperTypeMap.entrySet()) {
|
||||
|
@ -463,7 +464,8 @@ public abstract class ClassUtils {
|
|||
|
||||
/**
|
||||
* Check if the given class represents a primitive wrapper,
|
||||
* i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.
|
||||
* i.e. Boolean, Byte, Character, Short, Integer, Long, Float, Double, or
|
||||
* Void.
|
||||
* @param clazz the class to check
|
||||
* @return whether the given class is a primitive wrapper class
|
||||
*/
|
||||
|
@ -474,10 +476,12 @@ public abstract class ClassUtils {
|
|||
|
||||
/**
|
||||
* Check if the given class represents a primitive (i.e. boolean, byte,
|
||||
* char, short, int, long, float, or double) or a primitive wrapper
|
||||
* (i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double).
|
||||
* char, short, int, long, float, or double), {@code void}, or a wrapper for
|
||||
* those types (i.e. Boolean, Byte, Character, Short, Integer, Long, Float,
|
||||
* Double, or Void).
|
||||
* @param clazz the class to check
|
||||
* @return whether the given class is a primitive or primitive wrapper class
|
||||
* @return {@code true} if the given class represents a primitive, void, or
|
||||
* a wrapper class
|
||||
*/
|
||||
public static boolean isPrimitiveOrWrapper(Class<?> clazz) {
|
||||
Assert.notNull(clazz, "Class must not be null");
|
||||
|
|
|
@ -40,14 +40,17 @@ import org.springframework.tests.sample.objects.TestObject;
|
|||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ClassUtils}.
|
||||
*
|
||||
* @author Colin Sampaleanu
|
||||
* @author Juergen Hoeller
|
||||
* @author Rob Harrop
|
||||
* @author Rick Evans
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
class ClassUtilsTests {
|
||||
|
||||
private ClassLoader classLoader = getClass().getClassLoader();
|
||||
private final ClassLoader classLoader = getClass().getClassLoader();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
|
@ -380,6 +383,42 @@ class ClassUtilsTests {
|
|||
assertThat(ClassUtils.determineCommonAncestor(String.class, List.class)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPrimitiveWrapper() {
|
||||
assertThat(ClassUtils.isPrimitiveWrapper(Boolean.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveWrapper(Character.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveWrapper(Byte.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveWrapper(Short.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveWrapper(Integer.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveWrapper(Long.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveWrapper(Float.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveWrapper(Double.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveWrapper(Void.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPrimitiveOrWrapper() {
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(boolean.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(char.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(byte.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(short.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(int.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(long.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(float.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(double.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(void.class)).isTrue();
|
||||
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(Boolean.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(Character.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(Byte.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(Short.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(Integer.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(Long.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(Float.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(Double.class)).isTrue();
|
||||
assertThat(ClassUtils.isPrimitiveOrWrapper(Void.class)).isTrue();
|
||||
}
|
||||
|
||||
|
||||
public static class InnerClass {
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ public class ViewResolutionResultHandler extends HandlerResultHandlerSupport
|
|||
|
||||
return (CharSequence.class.isAssignableFrom(type) || Rendering.class.isAssignableFrom(type) ||
|
||||
Model.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type) ||
|
||||
void.class.equals(type) || View.class.isAssignableFrom(type) ||
|
||||
Void.class.equals(type) || void.class.equals(type) || View.class.isAssignableFrom(type) ||
|
||||
!BeanUtils.isSimpleProperty(type));
|
||||
}
|
||||
|
||||
|
|
|
@ -114,7 +114,12 @@ public class ViewResolutionResultHandlerTests {
|
|||
private void testSupports(MethodParameter returnType, boolean supports) {
|
||||
ViewResolutionResultHandler resultHandler = resultHandler(mock(ViewResolver.class));
|
||||
HandlerResult handlerResult = new HandlerResult(new Object(), null, returnType, this.bindingContext);
|
||||
assertThat(resultHandler.supports(handlerResult)).isEqualTo(supports);
|
||||
if (supports) {
|
||||
assertThat(resultHandler.supports(handlerResult)).as("return type [" + returnType + "] should be supported").isEqualTo(supports);
|
||||
}
|
||||
else {
|
||||
assertThat(resultHandler.supports(handlerResult)).as("return type [" + returnType + "] should not be supported").isNotEqualTo(supports);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue