-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
201 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.tuyang.test.testEnum2; | ||
|
||
import java.util.List; | ||
|
||
public class FromBean { | ||
|
||
private MyEnum myEnum1; | ||
private MyEnum myEnum2; | ||
|
||
private String enumString; | ||
|
||
private MyEnum[] myEnums1; | ||
private MyEnum[] myEnums2; | ||
|
||
private String[] enumStrings; | ||
|
||
private List<MyEnum> myEnums3; | ||
|
||
private List<String> eStrings; | ||
|
||
private Inside inside; | ||
|
||
public Inside getInside() { | ||
return inside; | ||
} | ||
|
||
public void setInside(Inside inside) { | ||
this.inside = inside; | ||
} | ||
|
||
public MyEnum getMyEnum1() { | ||
return myEnum1; | ||
} | ||
|
||
public void setMyEnum1(MyEnum myEnum1) { | ||
this.myEnum1 = myEnum1; | ||
} | ||
|
||
public MyEnum getMyEnum2() { | ||
return myEnum2; | ||
} | ||
|
||
public void setMyEnum2(MyEnum myEnum2) { | ||
this.myEnum2 = myEnum2; | ||
} | ||
|
||
public String getEnumString() { | ||
return enumString; | ||
} | ||
|
||
public void setEnumString(String enumString) { | ||
this.enumString = enumString; | ||
} | ||
|
||
public MyEnum[] getMyEnums1() { | ||
return myEnums1; | ||
} | ||
|
||
public void setMyEnums1(MyEnum[] myEnums1) { | ||
this.myEnums1 = myEnums1; | ||
} | ||
|
||
public MyEnum[] getMyEnums2() { | ||
return myEnums2; | ||
} | ||
|
||
public void setMyEnums2(MyEnum[] myEnums2) { | ||
this.myEnums2 = myEnums2; | ||
} | ||
|
||
public String[] getEnumStrings() { | ||
return enumStrings; | ||
} | ||
|
||
public void setEnumStrings(String[] enumStrings) { | ||
this.enumStrings = enumStrings; | ||
} | ||
|
||
public List<MyEnum> getMyEnums3() { | ||
return myEnums3; | ||
} | ||
|
||
public void setMyEnums3(List<MyEnum> myEnums3) { | ||
this.myEnums3 = myEnums3; | ||
} | ||
|
||
public List<String> geteStrings() { | ||
return eStrings; | ||
} | ||
|
||
public void seteStrings(List<String> eStrings) { | ||
this.eStrings = eStrings; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.tuyang.test.testEnum2; | ||
|
||
public class Inside { | ||
|
||
private String a; | ||
private MyEnum b; | ||
|
||
public String getA() { | ||
return a; | ||
} | ||
public void setA(String a) { | ||
this.a = a; | ||
} | ||
public MyEnum getB() { | ||
return b; | ||
} | ||
public void setB(MyEnum b) { | ||
this.b = b; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.tuyang.test.testEnum2; | ||
|
||
public enum MyEnum { | ||
One, | ||
Two, | ||
Three | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.tuyang.test.testEnum2; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.lang.reflect.Array; | ||
import java.util.Arrays; | ||
|
||
import org.junit.Test; | ||
|
||
import com.tuyang.beanutils.BeanCopyUtils; | ||
|
||
public class Test08 { | ||
|
||
private FromBean getFromBean() { | ||
FromBean fromBean = new FromBean(); | ||
|
||
fromBean.setMyEnum1(MyEnum.One); | ||
fromBean.setMyEnum2(MyEnum.Two); | ||
fromBean.setEnumString(MyEnum.Three.toString()); | ||
|
||
MyEnum[] array = new MyEnum[2]; | ||
array[0]= MyEnum.One; | ||
array[1] = MyEnum.Three; | ||
fromBean.setMyEnums1(array); | ||
fromBean.setMyEnums2(array); | ||
fromBean.setMyEnums3(Arrays.asList(array)); | ||
|
||
String[] enumStrings = new String[2]; | ||
enumStrings[0] = MyEnum.Three.toString(); | ||
enumStrings[1] = MyEnum.Two.toString(); | ||
|
||
fromBean.setEnumStrings(enumStrings); | ||
fromBean.seteStrings(Arrays.asList(enumStrings)); | ||
fromBean.setInside(new Inside()); | ||
fromBean.getInside().setB(MyEnum.One); | ||
|
||
return fromBean; | ||
} | ||
|
||
@Test | ||
public void testEnum() { | ||
FromBean fromBean = getFromBean(); | ||
ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); | ||
|
||
assertEquals(toBean.getMyEnum(), MyEnum.One); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.tuyang.test.testEnum2; | ||
|
||
import com.tuyang.beanutils.annotation.BeanCopySource; | ||
import com.tuyang.beanutils.annotation.CopyProperty; | ||
|
||
@BeanCopySource(source=FromBean.class) | ||
public class ToBean { | ||
|
||
@CopyProperty(property = "inside.b") | ||
private MyEnum myEnum; | ||
|
||
public MyEnum getMyEnum() { | ||
return myEnum; | ||
} | ||
|
||
public void setMyEnum(MyEnum myEnum) { | ||
this.myEnum = myEnum; | ||
} | ||
|
||
} |