1 package com.thoughtworks.xstream.converters.enums; 2 3 import junit.framework.TestCase; 4 5 import java.util.EnumSet ; 6 import java.util.EnumMap ; 7 import java.beans.XMLEncoder ; 8 import java.io.OutputStream ; 9 import java.io.ByteArrayOutputStream ; 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 { 18 super.setUp(); 19 xstream = new XStream(); 20 } 21 22 public void testIncludesEnumTypeInSerializedForm() { 23 xstream.alias("simple", SimpleEnum.class); 24 EnumMap map = new EnumMap <SimpleEnum,String >(SimpleEnum.class); 25 map.put(SimpleEnum.BLUE, "sky"); 26 map.put(SimpleEnum.GREEN, "grass"); 27 28 String 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 |