|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2023 the original author or authors. |
|
|
|
|
* Copyright 2002-2024 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. |
|
|
|
|
@ -41,6 +41,8 @@ import org.springframework.beans.propertyeditors.CustomDateEditor;
@@ -41,6 +41,8 @@ import org.springframework.beans.propertyeditors.CustomDateEditor;
|
|
|
|
|
import org.springframework.beans.testfixture.beans.DerivedTestBean; |
|
|
|
|
import org.springframework.beans.testfixture.beans.ITestBean; |
|
|
|
|
import org.springframework.beans.testfixture.beans.TestBean; |
|
|
|
|
import org.springframework.cglib.proxy.Enhancer; |
|
|
|
|
import org.springframework.cglib.proxy.MethodInterceptor; |
|
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
|
import org.springframework.core.io.ResourceEditor; |
|
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
|
@ -51,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
@@ -51,7 +53,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
|
|
|
|
import static org.assertj.core.api.SoftAssertions.assertSoftly; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Unit tests for {@link BeanUtils}. |
|
|
|
|
* Tests for {@link BeanUtils}. |
|
|
|
|
* |
|
|
|
|
* @author Juergen Hoeller |
|
|
|
|
* @author Rob Harrop |
|
|
|
|
@ -321,7 +323,8 @@ class BeanUtilsTests {
@@ -321,7 +323,8 @@ class BeanUtilsTests {
|
|
|
|
|
Order original = new Order("test", List.of("foo", "bar")); |
|
|
|
|
|
|
|
|
|
// Create a Proxy that loses the generic type information for the getLineItems() method.
|
|
|
|
|
OrderSummary proxy = proxyOrder(original); |
|
|
|
|
OrderSummary proxy = (OrderSummary) Proxy.newProxyInstance(getClass().getClassLoader(), |
|
|
|
|
new Class<?>[] {OrderSummary.class}, new OrderInvocationHandler(original)); |
|
|
|
|
assertThat(OrderSummary.class.getDeclaredMethod("getLineItems").toGenericString()) |
|
|
|
|
.contains("java.util.List<java.lang.String>"); |
|
|
|
|
assertThat(proxy.getClass().getDeclaredMethod("getLineItems").toGenericString()) |
|
|
|
|
@ -339,6 +342,23 @@ class BeanUtilsTests {
@@ -339,6 +342,23 @@ class BeanUtilsTests {
|
|
|
|
|
assertThat(target.getLineItems()).containsExactly("foo", "bar"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test // gh-32888
|
|
|
|
|
public void copyPropertiesWithGenericCglibClass() { |
|
|
|
|
Enhancer enhancer = new Enhancer(); |
|
|
|
|
enhancer.setSuperclass(User.class); |
|
|
|
|
enhancer.setCallback((MethodInterceptor) (obj, method, args, proxy) -> proxy.invokeSuper(obj, args)); |
|
|
|
|
User user = (User) enhancer.create(); |
|
|
|
|
user.setId(1); |
|
|
|
|
user.setName("proxy"); |
|
|
|
|
user.setAddress("addr"); |
|
|
|
|
|
|
|
|
|
User target = new User(); |
|
|
|
|
BeanUtils.copyProperties(user, target); |
|
|
|
|
assertThat(target.getId()).isEqualTo(user.getId()); |
|
|
|
|
assertThat(target.getName()).isEqualTo(user.getName()); |
|
|
|
|
assertThat(target.getAddress()).isEqualTo(user.getAddress()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void copyPropertiesWithEditable() throws Exception { |
|
|
|
|
TestBean tb = new TestBean(); |
|
|
|
|
@ -518,6 +538,7 @@ class BeanUtilsTests {
@@ -518,6 +538,7 @@ class BeanUtilsTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
|
private static class IntegerHolder { |
|
|
|
|
|
|
|
|
|
@ -532,6 +553,7 @@ class BeanUtilsTests {
@@ -532,6 +553,7 @@ class BeanUtilsTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
|
private static class WildcardListHolder1 { |
|
|
|
|
|
|
|
|
|
@ -546,6 +568,7 @@ class BeanUtilsTests {
@@ -546,6 +568,7 @@ class BeanUtilsTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
|
private static class WildcardListHolder2 { |
|
|
|
|
|
|
|
|
|
@ -560,6 +583,7 @@ class BeanUtilsTests {
@@ -560,6 +583,7 @@ class BeanUtilsTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
|
private static class NumberUpperBoundedWildcardListHolder { |
|
|
|
|
|
|
|
|
|
@ -574,6 +598,7 @@ class BeanUtilsTests {
@@ -574,6 +598,7 @@ class BeanUtilsTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
|
private static class NumberListHolder { |
|
|
|
|
|
|
|
|
|
@ -588,6 +613,7 @@ class BeanUtilsTests {
@@ -588,6 +613,7 @@ class BeanUtilsTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
|
private static class IntegerListHolder1 { |
|
|
|
|
|
|
|
|
|
@ -602,6 +628,7 @@ class BeanUtilsTests {
@@ -602,6 +628,7 @@ class BeanUtilsTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
|
private static class IntegerListHolder2 { |
|
|
|
|
|
|
|
|
|
@ -616,6 +643,7 @@ class BeanUtilsTests {
@@ -616,6 +643,7 @@ class BeanUtilsTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
|
private static class LongListHolder { |
|
|
|
|
|
|
|
|
|
@ -796,6 +824,7 @@ class BeanUtilsTests {
@@ -796,6 +824,7 @@ class BeanUtilsTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class BeanWithNullableTypes { |
|
|
|
|
|
|
|
|
|
private Integer counter; |
|
|
|
|
@ -826,6 +855,7 @@ class BeanUtilsTests {
@@ -826,6 +855,7 @@ class BeanUtilsTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class BeanWithPrimitiveTypes { |
|
|
|
|
|
|
|
|
|
private boolean flag; |
|
|
|
|
@ -838,7 +868,6 @@ class BeanUtilsTests {
@@ -838,7 +868,6 @@ class BeanUtilsTests {
|
|
|
|
|
private char character; |
|
|
|
|
private String text; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
|
public BeanWithPrimitiveTypes(boolean flag, byte byteCount, short shortCount, int intCount, long longCount, |
|
|
|
|
float floatCount, double doubleCount, char character, String text) { |
|
|
|
|
@ -889,21 +918,22 @@ class BeanUtilsTests {
@@ -889,21 +918,22 @@ class BeanUtilsTests {
|
|
|
|
|
public String getText() { |
|
|
|
|
return text; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class PrivateBeanWithPrivateConstructor { |
|
|
|
|
|
|
|
|
|
private PrivateBeanWithPrivateConstructor() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
|
private static class Order { |
|
|
|
|
|
|
|
|
|
private String id; |
|
|
|
|
private List<String> lineItems; |
|
|
|
|
|
|
|
|
|
private List<String> lineItems; |
|
|
|
|
|
|
|
|
|
Order() { |
|
|
|
|
} |
|
|
|
|
@ -935,6 +965,7 @@ class BeanUtilsTests {
@@ -935,6 +965,7 @@ class BeanUtilsTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private interface OrderSummary { |
|
|
|
|
|
|
|
|
|
String getId(); |
|
|
|
|
@ -943,17 +974,10 @@ class BeanUtilsTests {
@@ -943,17 +974,10 @@ class BeanUtilsTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private OrderSummary proxyOrder(Order order) { |
|
|
|
|
return (OrderSummary) Proxy.newProxyInstance(getClass().getClassLoader(), |
|
|
|
|
new Class<?>[] { OrderSummary.class }, new OrderInvocationHandler(order)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class OrderInvocationHandler implements InvocationHandler { |
|
|
|
|
|
|
|
|
|
private final Order order; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OrderInvocationHandler(Order order) { |
|
|
|
|
this.order = order; |
|
|
|
|
} |
|
|
|
|
@ -971,4 +995,46 @@ class BeanUtilsTests {
@@ -971,4 +995,46 @@ class BeanUtilsTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class GenericBaseModel<T> { |
|
|
|
|
|
|
|
|
|
private T id; |
|
|
|
|
|
|
|
|
|
private String name; |
|
|
|
|
|
|
|
|
|
public T getId() { |
|
|
|
|
return id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setId(T id) { |
|
|
|
|
this.id = id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String getName() { |
|
|
|
|
return name; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setName(String name) { |
|
|
|
|
this.name = name; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class User extends GenericBaseModel<Integer> { |
|
|
|
|
|
|
|
|
|
private String address; |
|
|
|
|
|
|
|
|
|
public User() { |
|
|
|
|
super(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String getAddress() { |
|
|
|
|
return address; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setAddress(String address) { |
|
|
|
|
this.address = address; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|