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 EnumSetConverterTest 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 testPutsEnumsInCompactCommaSeparatedString() { 23 xstream.alias("simple", SimpleEnum.class); 24 EnumSet <SimpleEnum> set = EnumSet.of(SimpleEnum.GREEN, SimpleEnum.BLUE); 25 26 String expectedXml = "<enum-set enum-type=\"simple\">GREEN,BLUE</enum-set>"; 27 28 assertEquals(expectedXml, xstream.toXML(set)); 29 assertEquals(set, xstream.fromXML(expectedXml)); 30 } 31 32 public void testSupportsJumboEnumSetsForMoreThan64Elements() { 33 xstream.alias("big", BigEnum.class); 34 EnumSet <BigEnum> jumboSet = EnumSet.allOf(BigEnum.class); 35 36 String expectedXml = "<enum-set enum-type=\"big\">" + 37 "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," + 38 "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," + 39 "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" + 40 "</enum-set>"; 41 42 assertEquals(expectedXml, xstream.toXML(jumboSet)); 43 assertEquals(jumboSet, xstream.fromXML(expectedXml)); 44 } 45 46 public void testSupportsPolymorphicEnums() { 47 xstream.alias("poly", PolymorphicEnum.class); 48 EnumSet <PolymorphicEnum> set = EnumSet.allOf(PolymorphicEnum.class); 49 50 String expectedXml = "<enum-set enum-type=\"poly\">A,B</enum-set>"; 51 52 assertEquals(expectedXml, xstream.toXML(set)); 53 assertEquals(set, xstream.fromXML(expectedXml)); 54 } 55 } 56 | Popular Tags |