aliastest.java

来自「xstream是一个把java object序列化成xml文件的开源库,轻便好用」· Java 代码 · 共 48 行

JAVA
48
字号
package com.thoughtworks.acceptance;import com.thoughtworks.acceptance.someobjects.X;import com.thoughtworks.xstream.alias.CannotResolveClassException;/** * @author Paul Hammant */public class AliasTest extends AbstractAcceptanceTest {    public void testBarfsIfAliasDoesNotExist() {        String xml = "" +                "<X-array>\n" +                "  <X>\n" +                "    <anInt>0</anInt>\n" +                "  </X>\n" +                "</X-array>";        // now change the alias        xstream.alias("Xxxxxxxx", X.class);        try {            xstream.fromXML(xml);            fail("ShouldCannotResolveClassException expected");        } catch (CannotResolveClassException expectedException) {            // expected        }    }    public void testAliasWithUnderscore() {        String xml = "" +                "<X_alias>\n" +                "  <anInt>0</anInt>\n" +                "</X_alias>";        // now change the alias        xstream.alias("X_alias", X.class);        X x = new X(0);        try {            assertBothWays(x, xml);            fail("CannotResolveClassException expected");        } catch (CannotResolveClassException e) {            //expected - marshalling works but not unmarshalling        }    }}

⌨️ 快捷键说明

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