1
2
3
4
5
6
7 package org.weda;
8
9 import java.lang.reflect.Field;
10 import junit.framework.TestCase;
11 import org.apache.commons.beanutils.BeanUtils;
12
13 /**
14 *
15 * @author Mikhail Titov
16 */
17 public class CloneTest extends TestCase{
18 private enum MyEnum{
19 Значение, VAL2};
20 public MyEnum val;
21
22 public CloneTest(String name) {
23 super(name);
24 }
25
26 public void test() throws Exception {
27 CloneableObject1 o1 = new CloneableObject1();
28 CloneableObject1 o1_c = (CloneableObject1)o1.clone();
29 assertNotSame(o1, o1_c);
30 assertSame(o1.getObj(), o1_c.getObj());
31 }
32
33 public void test_beanUtils() throws Exception {
34 CloneableObject1 o1 = new CloneableObject1();
35 CloneableObject1 o1_c = (CloneableObject1)BeanUtils.cloneBean(o1);
36 assertNotSame(o1, o1_c);
37 assertSame(o1.getObj(), o1_c.getObj());
38 }
39
40 public void test_Enum() throws Exception {
41 Class enumClass = MyEnum.class;
42 assertTrue(enumClass.isEnum());
43 Enum cons = null;
44 for (Object obj: enumClass.getEnumConstants()){
45 cons = (Enum)obj;
46 System.out.format(
47 "Name: %s; Value: %d\n", cons.name(), cons.ordinal());
48 }
49 Field enumField = CloneTest.class.getField("val");
50 enumField.set(this, Enum.valueOf(MyEnum.class, "Значение"));
51 assertSame(MyEnum.Значение, val);
52
53 cons = Enum.valueOf(MyEnum.class, "Значение");
54 }
55
56 }