1 package com.thoughtworks.acceptance; 2 3 import com.thoughtworks.acceptance.objects.Hardware; 4 import com.thoughtworks.acceptance.objects.SampleLists; 5 import com.thoughtworks.acceptance.objects.Software; 6 7 import java.util.ArrayList; 8 import java.util.Collection; 9 import java.util.HashSet; 10 11 public class CollectionsTest extends AbstractAcceptanceTest { 12 13 public void testListsCanContainCustomObjects() { 14 SampleLists lists = new SampleLists(); 15 lists.good.add(new Software("apache", "geronimo")); 16 lists.good.add(new Software("caucho", "resin")); 17 lists.good.add(new Hardware("risc", "strong-arm")); 18 lists.bad.add(new Software("apache", "jserv")); 19 20 xstream.alias("lists", SampleLists.class); 21 xstream.alias("software", Software.class); 22 xstream.alias("hardware", Hardware.class); 23 24 String expected = "" + 25 "<lists>\n" + 26 " <good>\n" + 27 " <software>\n" + 28 " <vendor>apache</vendor>\n" + 29 " <name>geronimo</name>\n" + 30 " </software>\n" + 31 " <software>\n" + 32 " <vendor>caucho</vendor>\n" + 33 " <name>resin</name>\n" + 34 " </software>\n" + 35 " <hardware>\n" + 36 " <arch>risc</arch>\n" + 37 " <name>strong-arm</name>\n" + 38 " </hardware>\n" + 39 " </good>\n" + 40 " <bad class=\"list\">\n" + 41 " <software>\n" + 42 " <vendor>apache</vendor>\n" + 43 " <name>jserv</name>\n" + 44 " </software>\n" + 45 " </bad>\n" + 46 "</lists>"; 47 48 assertBothWays(lists, expected); 49 } 50 51 public void testListsCanContainBasicObjects() { 52 SampleLists lists = new SampleLists(); 53 lists.good.add("hello"); 54 lists.good.add(new Integer(3)); 55 lists.good.add(Boolean.TRUE); 56 57 xstream.alias("lists", SampleLists.class); 58 59 String expected = "" + 60 "<lists>\n" + 61 " <good>\n" + 62 " <string>hello</string>\n" + 63 " <int>3</int>\n" + 64 " <boolean>true</boolean>\n" + 65 " </good>\n" + 66 " <bad class=\"list\"/>\n" + 67 "</lists>"; 68 69 assertBothWays(lists, expected); 70 } 71 72 public void testListCanBeRootObject() { 73 Collection list = new ArrayList(); 74 list.add("hi"); 75 list.add("bye"); 76 77 String expected = "" + 78 "<list>\n" + 79 " <string>hi</string>\n" + 80 " <string>bye</string>\n" + 81 "</list>"; 82 83 assertBothWays(list, expected); 84 } 85 86 public void testSetCanBeRootObject() { 87 Collection set = new HashSet(); 88 set.add("hi"); 89 set.add("bye"); 90 91 String expected = "" + 92 "<set>\n" + 93 " <string>hi</string>\n" + 94 " <string>bye</string>\n" + 95 "</set>"; 96 97 assertBothWays(set, expected); 98 } 99 100 }

This page was automatically generated by Maven