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: import junit.framework.TestCase;
16:
17: import java.util.EnumSet;
18:
19: public class EnumSetConverterTest extends TestCase {
20:
21: private XStream xstream;
22:
23: protected void setUp() throws Exception {
24: super .setUp();
25: xstream = new XStream();
26: }
27:
28: public void testPutsEnumsInCompactCommaSeparatedString() {
29: xstream.alias("simple", SimpleEnum.class);
30: EnumSet<SimpleEnum> set = EnumSet.of(SimpleEnum.GREEN,
31: SimpleEnum.BLUE);
32:
33: String expectedXml = "<enum-set enum-type=\"simple\">GREEN,BLUE</enum-set>";
34:
35: assertEquals(expectedXml, xstream.toXML(set));
36: assertEquals(set, xstream.fromXML(expectedXml));
37: }
38:
39: public void testSupportsJumboEnumSetsForMoreThan64Elements() {
40: xstream.alias("big", BigEnum.class);
41: EnumSet<BigEnum> jumboSet = EnumSet.allOf(BigEnum.class);
42:
43: String expectedXml = "<enum-set enum-type=\"big\">"
44: + "A1,B1,C1,D1,E1,F1,G1,H1,I1,J1,K1,L1,M1,N1,O1,P1,Q1,R1,S1,T1,U1,V1,W1,X1,Y1,Z1,"
45: + "A2,B2,C2,D2,E2,F2,G2,H2,I2,J2,K2,L2,M2,N2,O2,P2,Q2,R2,S2,T2,U2,V2,W2,X2,Y2,Z2,"
46: + "A3,B3,C3,D3,E3,F3,G3,H3,I3,J3,K3,L3,M3,N3,O3,P3,Q3,R3,S3,T3,U3,V3,W3,X3,Y3,Z3"
47: + "</enum-set>";
48:
49: assertEquals(expectedXml, xstream.toXML(jumboSet));
50: assertEquals(jumboSet, xstream.fromXML(expectedXml));
51: }
52:
53: public void testSupportsPolymorphicEnums() {
54: xstream.alias("poly", PolymorphicEnum.class);
55: EnumSet<PolymorphicEnum> set = EnumSet
56: .allOf(PolymorphicEnum.class);
57:
58: String expectedXml = "<enum-set enum-type=\"poly\">A,B</enum-set>";
59:
60: assertEquals(expectedXml, xstream.toXML(set));
61: assertEquals(set, xstream.fromXML(expectedXml));
62: }
63:
64: public void testEmptyEnumSet() {
65: xstream.alias("simple", SimpleEnum.class);
66: EnumSet<SimpleEnum> set = EnumSet.noneOf(SimpleEnum.class);
67:
68: String expectedXml = "<enum-set enum-type=\"simple\"></enum-set>";
69:
70: assertEquals(expectedXml, xstream.toXML(set));
71: assertEquals(set, xstream.fromXML(expectedXml));
72: }
73:
74: }
|