From 022deac62c7d4da0dabb335a3c8b8df901f614cd Mon Sep 17 00:00:00 2001 From: "chao.liuc" Date: Fri, 28 Oct 2011 08:46:20 +0000 Subject: [PATCH] =?UTF-8?q?DUBBO-7=20fix=20test=5FsimpleCollection=20?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@123 1a56cb94-b969-4eaa-88fa-be21384802f2 --- .../dubbo/common/utils/PojoUtilsTest.java | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/PojoUtilsTest.java b/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/PojoUtilsTest.java index b2d6c29126..1238e4792c 100644 --- a/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/PojoUtilsTest.java +++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/utils/PojoUtilsTest.java @@ -19,6 +19,8 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import java.io.Serializable; +import java.lang.reflect.Method; +import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; @@ -37,10 +39,14 @@ import com.alibaba.dubbo.common.model.person.Phone; * @author ding.lid */ public class PojoUtilsTest { - + public void assertObject(Object data) { + assertObject(data, null); + } + + public void assertObject(Object data, Type type) { Object generalize = PojoUtils.generalize(data); - Object realize = PojoUtils.realize(generalize, data.getClass()); + Object realize = PojoUtils.realize(generalize, data.getClass(), type); assertEquals(data, realize); } @@ -133,10 +139,22 @@ public class PojoUtilsTest { assertArrayObject(array); } - // FIXME - @Ignore("Type missing, Person -> Map") + public List returnListPersonMethod() {return null;} + public BigPerson returnBigPersonMethod() {return null;} + public Type getType(String methodName){ + Method method; + try { + method = getClass().getDeclaredMethod(methodName, new Class[]{} ); + } catch (Exception e) { + throw new IllegalStateException(e); + } + Type gtype = method.getGenericReturnType(); + return gtype; + } + @Test public void test_simpleCollection() throws Exception { + Type gtype = getType("returnListPersonMethod"); List list = new ArrayList(); list.add(new Person()); { @@ -144,9 +162,10 @@ public class PojoUtilsTest { person.setName("xxxx"); list.add(person); } - assertObject(list); + assertObject(list,gtype); } + BigPerson bigPerson; { bigPerson = new BigPerson(); @@ -183,7 +202,8 @@ public class PojoUtilsTest { @Test public void test_total() throws Exception { Object generalize = PojoUtils.generalize(bigPerson); - Object realize = PojoUtils.realize(generalize, BigPerson.class); + Type gtype = getType("returnBigPersonMethod"); + Object realize = PojoUtils.realize(generalize, BigPerson.class,gtype); assertEquals(bigPerson, realize); }