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

📄 fontconvertertest.java

📁 xstream是一个把java object序列化成xml文件的开源库,轻便好用
💻 JAVA
字号:
package com.thoughtworks.xstream.converters.extended;import com.thoughtworks.xstream.XStream;import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite;import java.awt.*;import java.awt.font.TextAttribute;import java.util.Map;public class FontConverterTest extends TestCase {    private XStream xstream;    private Font in;    public static Test suite() {        // Only try to run this test case if graphics environment is available        try {            new Font("Arial", Font.BOLD, 20);            return new TestSuite(FontConverterTest.class);        } catch (Throwable t) {            return new TestSuite();        }     }    protected void setUp() throws Exception {        super.setUp();        xstream = new XStream();        in = new Font("Arial", Font.BOLD, 20);    }    public void testConvertsToFontThatEqualsOriginal() {        // execute        Font out = (Font) xstream.fromXML(xstream.toXML(in));        // assert        assertEquals(in, out);    }    public void testProducesFontThatHasTheSameAttributes() {        // execute        Font out = (Font) xstream.fromXML(xstream.toXML(in));        // assert        Map inAttributes = in.getAttributes();        Map outAttributes = out.getAttributes();        // these attributes don't have a valid .equals() method (bad Sun!), so we can't use them in the test.        inAttributes.remove(TextAttribute.TRANSFORM);        outAttributes.remove(TextAttribute.TRANSFORM);        assertEquals(inAttributes, outAttributes);    }    public void testCorrectlyInitializesFontToPreventJvmCrash() {        // If a font has not been constructed in the correct way, the JVM crashes horribly through some internal        // native code, whenever the font is rendered to screen.        // execute        Font out = (Font) xstream.fromXML(xstream.toXML(in));        Toolkit.getDefaultToolkit().getFontMetrics(out);        // if the JVM hasn't crashed yet, we're good.    }}

⌨️ 快捷键说明

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