1 package com.thoughtworks.xstream.converters.composite; 2 3 import com.thoughtworks.xstream.XStream; 4 import junit.framework.TestCase; 5 6 /*** 7 * [Marcos Tarruella, tarruella@email.com] Joe, could you please send me the link to the code 8 * so I may have a chance to have another look at it. 9 * Cheers! 10 * 11 * P.S. I was about to use xmlUnit but... a bit dipsy and decided not to (perhaps next GeekNight :-) 12 */ 13 public class ObjectWithFieldsConverterTest extends TestCase { 14 15 public class World { 16 int anInt = 1; 17 Integer anInteger = new Integer(2); 18 char anChar = 'a'; 19 Character anCharacter = new Character('w'); 20 boolean anBool = true; 21 Boolean anBoolean = new Boolean(false); 22 byte aByte = 4; 23 Byte aByteClass = new Byte("5"); 24 short aShort = 6; 25 Short aShortClass = new Short("7"); 26 float aFloat = 8f; 27 Float aFloatClass = new Float("9"); 28 long aLong = 10; 29 Long aLongClass = new Long("11"); 30 String anString = new String("XStream programming!"); 31 } 32 33 public void testPrimitiveTypes() { 34 World world = new World(); 35 36 XStream xstream = new XStream(); 37 xstream.alias("world", World.class); 38 39 String expected = 40 "<world>\n" + 41 " <anInt>1</anInt>\n" + 42 " <anInteger>2</anInteger>\n" + 43 " <anChar>a</anChar>\n" + 44 " <anCharacter>w</anCharacter>\n" + 45 " <anBool>true</anBool>\n" + 46 " <anBoolean>false</anBoolean>\n" + 47 " <aByte>4</aByte>\n" + 48 " <aByteClass>5</aByteClass>\n" + 49 " <aShort>6</aShort>\n" + 50 " <aShortClass>7</aShortClass>\n" + 51 " <aFloat>8.0</aFloat>\n" + 52 " <aFloatClass>9.0</aFloatClass>\n" + 53 " <aLong>10</aLong>\n" + 54 " <aLongClass>11</aLongClass>\n" + 55 " <anString>XStream programming!</anString>\n" + 56 "</world>"; 57 58 assertEquals(expected, xstream.toXML(world)); 59 } 60 61 static class TypesOfFields { 62 String normal = "normal"; 63 transient String trans = "transient"; 64 final String fin = "final"; 65 static String stat = "stat"; 66 } 67 68 public void testDontTryToWriteTransientStaticOrFinalFields() { 69 TypesOfFields fields = new TypesOfFields(); 70 String expected = "" + 71 "<types>\n" + 72 " <normal>normal</normal>\n" + 73 "</types>"; 74 75 XStream xstream = new XStream(); 76 xstream.alias("types", TypesOfFields.class); 77 78 String xml = xstream.toXML(fields); 79 assertEquals(expected, xml); 80 81 } 82 83 }

This page was automatically generated by Maven