⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 enumconvertertest.java

📁 xstream是一个把java object序列化成xml文件的开源库,轻便好用
💻 JAVA
字号:
package com.thoughtworks.xstream.converters.enums;import com.thoughtworks.xstream.XStream;import junit.framework.TestCase;// ***** READ THIS *****// This class will only compile with JDK 1.5.0 or above as it test Java enums.// If you are using an earlier version of Java, just don't try to build this class. XStream should work fine without it./** * @author Joe Walnes * @author Bryan Coleman */public class EnumConverterTest extends TestCase {    private XStream xstream;    protected void setUp() throws Exception {        super.setUp();        xstream = new XStream();        xstream.alias("simple", SimpleEnum.class);        xstream.alias("polymorphic", PolymorphicEnum.class);    }    public void testRepresentsEnumAsSingleStringValue() {        String expectedXml = "<simple>GREEN</simple>";        SimpleEnum in = SimpleEnum.GREEN;        assertEquals(expectedXml, xstream.toXML(in));        assertEquals(in, xstream.fromXML(expectedXml));    }    public void testRepresentsPolymorphicEnumAsSingleStringValue() {        String expectedXml = "<polymorphic>B</polymorphic>";        PolymorphicEnum in = PolymorphicEnum.B;        assertEquals(expectedXml, xstream.toXML(in));        assertEquals(in, xstream.fromXML(expectedXml));    }    public void testDeserializedEnumIsTheSameNotJustEqual() {        assertSame(SimpleEnum.GREEN, xstream.fromXML(xstream.toXML(SimpleEnum.GREEN)));        assertSame(PolymorphicEnum.B, xstream.fromXML(xstream.toXML(PolymorphicEnum.B)));    }    public void testResolvesSpecializedPolymorphicEnum() {        PolymorphicEnum in;        PolymorphicEnum out;        in = PolymorphicEnum.A;        out = (PolymorphicEnum) xstream.fromXML(xstream.toXML(in));        assertEquals("apple", out.fruit());        in = PolymorphicEnum.B;        out = (PolymorphicEnum) xstream.fromXML(xstream.toXML(in));        assertEquals("banana", out.fruit());    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -