package org.dazzle.utils;

import java.util.Map;

import org.junit.Test;

public class BeanUtilsTest {

	@Test
	public void bean2MapTest() {
		TestBean bean = new TestBean();
		bean.setField1(100L);
		bean.setField2("xxx");
		Map<String, Object> ret = BeanUtils.bean2Map(bean, new String[]{"field1","field2"}, true);
		System.out.println(ret);
		bean = BeanUtils.map2Bean(TestBean.class, ret);
		System.out.println(bean);
		ret.put("field1", 99L);
		ret.put("fieldxxxxxxxx", 99L);
		bean = BeanUtils.map2Bean(bean, ret);
		System.out.println(bean);
		bean.setField1(88L);
		TestBean2 bean2 = BeanUtils.bean2Bean(bean, TestBean2.class);
		System.out.println(bean2);
		bean2.setField1(77L);
		bean = BeanUtils.bean2Bean(bean2, bean);
		System.out.println(bean);
	}

}
class TestBean {
	private Long field1;
	private String field2;
	
	public TestBean() {
		super();
	}
	public Long getField1() {
		return field1;
	}
	public void setField1(Long field1) {
		this.field1 = field1;
	}
	public String getField2() {
		return field2;
	}
	public void setField2(String field2) {
		this.field2 = field2;
	}
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("TestBean [field1=");
		builder.append(field1);
		builder.append(", field2=");
		builder.append(field2);
		builder.append("]");
		return builder.toString();
	}
	
}
class TestBean2 {
	private Long field1;
	private String field2;
	
	public TestBean2() {
		super();
	}
	public Long getField1() {
		return field1;
	}
	public void setField1(Long field1) {
		this.field1 = field1;
	}
	public String getField2() {
		return field2;
	}
	public void setField2(String field2) {
		this.field2 = field2;
	}
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("TestBean2 [field1=");
		builder.append(field1);
		builder.append(", field2=");
		builder.append(field2);
		builder.append("]");
		return builder.toString();
	}
}
@@ -105,16 +105,225 @@
 st %7B%0D%0A%0D%0A
+%09@Test%0D%0A%09public void test2() %7B%0D%0A%09%09Test2Bean bean = new Test2Bean();%0D%0A%09%09bean.setField1(100L);%0D%0A%09%09bean.setField2(%22xxx%22);%0D%0A%09%09Map%3CString, Object%3E ret = BeanUtils.bean2Map(bean);%0D%0A%09%09System.out.println(ret);%0D%0A%09%7D%0D%0A%0D%0A
 %09@Test%0D%0A
@@ -994,24 +994,331 @@
 ;%0D%0A%09%7D%0D%0A%0D%0A%7D%0D%0A
+class Test2Bean extends TestBean %7B%0D%0A%09private static final String a = %22aaa%22;%0D%0A%09public static final String b = %22bbb%22;%0D%0A%09private static volatile String c = %22ccc%22;%0D%0A%09private transient String d = %22ddd%22;%0D%0A%09private enum e %7B f,g,h%7D;%0D%0A//%09private strictfp String i = %22iii%22;%0D%0A%09private volatile String j = %22jjj%22;%0D%0A%7D%0D%0A%0D%0A
 class TestBe

测试了java对象和map互转化时候，静态字段等是否也支持