01: /*
02: * Copyright (C) 2005 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 06. April 2005 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.converters.enums;
13:
14: import com.thoughtworks.xstream.XStream;
15:
16: import junit.framework.TestCase;
17:
18: import java.util.EnumMap;
19:
20: public class EnumMapConverterTest extends TestCase {
21:
22: private XStream xstream;
23:
24: protected void setUp() throws Exception {
25: super .setUp();
26: xstream = new XStream();
27: }
28:
29: public void testIncludesEnumTypeInSerializedForm() {
30: xstream.alias("simple", SimpleEnum.class);
31: EnumMap map = new EnumMap<SimpleEnum, String>(SimpleEnum.class);
32: map.put(SimpleEnum.BLUE, "sky");
33: map.put(SimpleEnum.GREEN, "grass");
34:
35: String expectedXml = "" + "<enum-map enum-type=\"simple\">\n"
36: + " <entry>\n" + " <simple>GREEN</simple>\n"
37: + " <string>grass</string>\n" + " </entry>\n"
38: + " <entry>\n" + " <simple>BLUE</simple>\n"
39: + " <string>sky</string>\n" + " </entry>\n"
40: + "</enum-map>";
41:
42: assertEquals(expectedXml, xstream.toXML(map));
43: assertEquals(map, xstream.fromXML(expectedXml));
44: }
45:
46: }
|