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

📄 finalfieldstest.java

📁 xstream是一个把java object序列化成xml文件的开源库,轻便好用
💻 JAVA
字号:
package com.thoughtworks.acceptance;import com.thoughtworks.xstream.XStream;import com.thoughtworks.xstream.converters.reflection.ObjectAccessException;import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider;import com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider;public class FinalFieldsTest extends AbstractAcceptanceTest {    static class ThingWithFinalField extends StandardObject {        final int number = 9;    }    public void testSerializeFinalFieldsIfSupported() {        xstream = new XStream(new Sun14ReflectionProvider());        xstream.alias("thing", ThingWithFinalField.class);        assertBothWays(new ThingWithFinalField(),                "<thing>\n" +                "  <number>9</number>\n" +                "</thing>");    }    public void testExceptionThrownUponSerializationIfNotSupport() {        xstream = new XStream(new PureJavaReflectionProvider());        xstream.alias("thing", ThingWithFinalField.class);        try {            xstream.toXML(new ThingWithFinalField());            fail("Expected exception");        } catch (ObjectAccessException expectedException) {            assertEquals("Invalid final field " + ThingWithFinalField.class.getName() + ".number",                    expectedException.getMessage());        }    }}

⌨️ 快捷键说明

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