|
@@ -1,14 +1,15 @@
|
|
|
package org.hswebframework.web.bean;
|
|
|
|
|
|
-import org.apache.commons.beanutils.BeanUtils;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
+import java.lang.reflect.Proxy;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
/**
|
|
|
* @author zhouhao
|
|
@@ -44,8 +45,8 @@ public class FastBeanCopierTest {
|
|
|
|
|
|
@Test
|
|
|
public void testMapArray() {
|
|
|
- Map<String,Object> data =new HashMap<>();
|
|
|
- data.put("colors", Arrays.asList("RED"));
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("colors", Arrays.asList("RED"));
|
|
|
|
|
|
|
|
|
Target target = new Target();
|
|
@@ -82,4 +83,41 @@ public class FastBeanCopierTest {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testProxy() {
|
|
|
+ AtomicReference<Object> reference=new AtomicReference<>();
|
|
|
+
|
|
|
+ ProxyTest test = (ProxyTest) Proxy.newProxyInstance(ClassLoader.getSystemClassLoader(),
|
|
|
+ new Class[]{ProxyTest.class}, (proxy, method, args) -> {
|
|
|
+ if (method.getName().equals("getName")) {
|
|
|
+ return "test";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (method.getName().equals("setName")) {
|
|
|
+ reference.set(args[0]);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ });
|
|
|
+
|
|
|
+ Target source = new Target();
|
|
|
+
|
|
|
+ FastBeanCopier.copy(test,source);
|
|
|
+ Assert.assertEquals(source.getName(),test.getName());
|
|
|
+
|
|
|
+
|
|
|
+ source.setName("test2");
|
|
|
+ FastBeanCopier.copy(source,test);
|
|
|
+
|
|
|
+ Assert.assertEquals(reference.get(),source.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public interface ProxyTest {
|
|
|
+ String getName();
|
|
|
+
|
|
|
+ void setName(String name);
|
|
|
+ }
|
|
|
+
|
|
|
}
|