KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > converters > enums > EnumMapConverterTest


1 package com.thoughtworks.xstream.converters.enums;
2
3 import junit.framework.TestCase;
4
5 import java.util.EnumSet JavaDoc;
6 import java.util.EnumMap JavaDoc;
7 import java.beans.XMLEncoder JavaDoc;
8 import java.io.OutputStream JavaDoc;
9 import java.io.ByteArrayOutputStream JavaDoc;
10
11 import com.thoughtworks.xstream.XStream;
12
13 public class EnumMapConverterTest extends TestCase {
14
15     private XStream xstream;
16
17     protected void setUp() throws Exception JavaDoc {
18         super.setUp();
19         xstream = new XStream();
20     }
21
22     public void testIncludesEnumTypeInSerializedForm() {
23         xstream.alias("simple", SimpleEnum.class);
24         EnumMap JavaDoc map = new EnumMap JavaDoc<SimpleEnum,String JavaDoc>(SimpleEnum.class);
25         map.put(SimpleEnum.BLUE, "sky");
26         map.put(SimpleEnum.GREEN, "grass");
27
28         String JavaDoc expectedXml = "" +
29                 "<enum-map enum-type=\"simple\">\n" +
30                 " <entry>\n" +
31                 " <simple>GREEN</simple>\n" +
32                 " <string>grass</string>\n" +
33                 " </entry>\n" +
34                 " <entry>\n" +
35                 " <simple>BLUE</simple>\n" +
36                 " <string>sky</string>\n" +
37                 " </entry>\n" +
38                 "</enum-map>";
39
40         assertEquals(expectedXml, xstream.toXML(map));
41         assertEquals(map, xstream.fromXML(expectedXml));
42     }
43
44 }
45
Popular Tags