📄 finalfieldstest.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 + -