finalfieldstest.java
来自「xstream是一个把java object序列化成xml文件的开源库,轻便好用」· Java 代码 · 共 37 行
JAVA
37 行
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 + =
减小字号Ctrl + -
显示快捷键?