KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > converters > javabean > PropertyDictionaryTest


1 package com.thoughtworks.xstream.converters.javabean;
2
3 import java.util.Iterator JavaDoc;
4
5 import junit.framework.TestCase;
6
7 public class PropertyDictionaryTest extends TestCase {
8
9     private PropertyDictionary propertyDictionary;
10
11     protected void setUp() throws Exception JavaDoc {
12         super.setUp();
13         propertyDictionary = new PropertyDictionary();
14     }
15
16     /**
17      * Test class: three serializable properties, one with a all capital name,
18      * two others non serializable, one readable, one writable, and another and
19      * a lonely field
20      */

21     class SomeClass {
22         private String JavaDoc a;
23
24         private String JavaDoc URL;
25
26         private String JavaDoc c;
27
28         private String JavaDoc d;
29
30         private String JavaDoc e;
31
32         private String JavaDoc f;
33
34         public String JavaDoc getA() {
35             return a;
36         }
37
38         public void setA(String JavaDoc a) {
39             this.a = a;
40         }
41
42         public String JavaDoc getURL() {
43             return URL;
44         }
45
46         public void setURL(String JavaDoc url) {
47             this.URL = url;
48         }
49
50         public String JavaDoc getC() {
51             return c;
52         }
53
54         public void setC(String JavaDoc c) {
55             this.c = c;
56         }
57
58         public String JavaDoc getD() {
59             return d;
60         }
61
62         public void setE(String JavaDoc e) {
63             this.e = e;
64         }
65     }
66
67     public void testListsFieldsInClassInDefinitionOrder() {
68         Iterator JavaDoc properties = propertyDictionary.serializablePropertiesFor(SomeClass.class);
69         assertEquals("URL", ((BeanProperty) properties.next()).getName());
70         assertEquals("a", ((BeanProperty) properties.next()).getName());
71         assertEquals("c", ((BeanProperty) properties.next()).getName());
72         assertFalse("No more fields should be present", properties.hasNext());
73     }
74
75     /**
76      * Test subclassing and private properties
77      */

78     class SpecialClass extends SomeClass {
79         private String JavaDoc brilliant;
80
81         public String JavaDoc getBrilliant() {
82             return brilliant;
83         }
84
85         public void setBrilliant(String JavaDoc brilliant) {
86             this.brilliant = brilliant;
87         }
88
89         public String JavaDoc getPrivate() {
90             return null;
91         }
92
93         private void setPrivate(String JavaDoc string) {
94
95         }
96     }
97
98     public void testIncludesFieldsInSuperClasses() {
99         Iterator JavaDoc properties = propertyDictionary.serializablePropertiesFor(SpecialClass.class);
100         assertEquals("URL", ((BeanProperty) properties.next()).getName());
101         assertEquals("a", ((BeanProperty) properties.next()).getName());
102         assertEquals("brilliant", ((BeanProperty) properties.next()).getName());
103         assertEquals("c", ((BeanProperty) properties.next()).getName());
104         assertFalse("No more fields should be present", properties.hasNext());
105     }
106 }
Popular Tags