1 package com.thoughtworks.xstream.converters.extended; 2 3 import com.thoughtworks.xstream.XStream; 4 import junit.framework.Test; 5 import junit.framework.TestCase; 6 import junit.framework.TestSuite; 7 8 import java.awt.*; 9 import java.awt.font.TextAttribute ; 10 import java.util.Map ; 11 12 public class FontConverterTest extends TestCase { 13 private XStream xstream; 14 private Font in; 15 16 public static Test suite() { 17 try { 19 new Font("Arial", Font.BOLD, 20); 20 return new TestSuite(FontConverterTest.class); 21 } catch (Throwable t) { 22 return new TestSuite(); 23 } 24 } 25 26 protected void setUp() throws Exception { 27 super.setUp(); 28 xstream = new XStream(); 29 in = new Font("Arial", Font.BOLD, 20); 30 } 31 32 public void testConvertsToFontThatEqualsOriginal() { 33 Font out = (Font) xstream.fromXML(xstream.toXML(in)); 35 36 assertEquals(in, out); 38 } 39 40 public void testProducesFontThatHasTheSameAttributes() { 41 Font out = (Font) xstream.fromXML(xstream.toXML(in)); 43 44 Map inAttributes = in.getAttributes(); 46 Map outAttributes = out.getAttributes(); 47 48 inAttributes.remove(TextAttribute.TRANSFORM); 50 outAttributes.remove(TextAttribute.TRANSFORM); 51 52 assertEquals(inAttributes, outAttributes); 53 } 54 55 public void testCorrectlyInitializesFontToPreventJvmCrash() { 56 59 Font out = (Font) xstream.fromXML(xstream.toXML(in)); 61 62 Toolkit.getDefaultToolkit().getFontMetrics(out); 63 65 } 66 } 67 | Popular Tags |