1 package com.thoughtworks.xstream.converters.javabean; 2 3 import java.util.Iterator ; 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 { 12 super.setUp(); 13 propertyDictionary = new PropertyDictionary(); 14 } 15 16 21 class SomeClass { 22 private String a; 23 24 private String URL; 25 26 private String c; 27 28 private String d; 29 30 private String e; 31 32 private String f; 33 34 public String getA() { 35 return a; 36 } 37 38 public void setA(String a) { 39 this.a = a; 40 } 41 42 public String getURL() { 43 return URL; 44 } 45 46 public void setURL(String url) { 47 this.URL = url; 48 } 49 50 public String getC() { 51 return c; 52 } 53 54 public void setC(String c) { 55 this.c = c; 56 } 57 58 public String getD() { 59 return d; 60 } 61 62 public void setE(String e) { 63 this.e = e; 64 } 65 } 66 67 public void testListsFieldsInClassInDefinitionOrder() { 68 Iterator 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 78 class SpecialClass extends SomeClass { 79 private String brilliant; 80 81 public String getBrilliant() { 82 return brilliant; 83 } 84 85 public void setBrilliant(String brilliant) { 86 this.brilliant = brilliant; 87 } 88 89 public String getPrivate() { 90 return null; 91 } 92 93 private void setPrivate(String string) { 94 95 } 96 } 97 98 public void testIncludesFieldsInSuperClasses() { 99 Iterator 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 |