fontconvertertest.java

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

JAVA
67
字号
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 + =
减小字号Ctrl + -
显示快捷键?