1 42 43 package org.jfree.text.junit; 44 45 import java.awt.BasicStroke ; 46 import java.awt.Color ; 47 import java.io.ByteArrayInputStream ; 48 import java.io.ByteArrayOutputStream ; 49 import java.io.ObjectInput ; 50 import java.io.ObjectInputStream ; 51 import java.io.ObjectOutput ; 52 import java.io.ObjectOutputStream ; 53 54 import junit.framework.Test; 55 import junit.framework.TestCase; 56 import junit.framework.TestSuite; 57 58 import org.jfree.text.TextBlock; 59 import org.jfree.text.TextBox; 60 import org.jfree.text.TextLine; 61 import org.jfree.ui.RectangleInsets; 62 63 66 public class TextBoxTests extends TestCase { 67 68 73 public static Test suite() { 74 return new TestSuite(TextBoxTests.class); 75 } 76 77 82 public TextBoxTests(final String name) { 83 super(name); 84 } 85 86 89 public void testEquals() { 90 91 final TextBox b1 = new TextBox("Hello"); 92 final TextBox b2 = new TextBox("Hello"); 93 assertTrue(b1.equals(b2)); 94 assertTrue(b2.equals(b1)); 95 96 b1.setOutlinePaint(Color.blue); 98 assertFalse(b1.equals(b2)); 99 b2.setOutlinePaint(Color.blue); 100 assertTrue(b1.equals(b2)); 101 102 b1.setOutlineStroke(new BasicStroke (1.1f)); 104 assertFalse(b1.equals(b2)); 105 b2.setOutlineStroke(new BasicStroke (1.1f)); 106 assertTrue(b1.equals(b2)); 107 108 b1.setInteriorGap(new RectangleInsets(10, 10, 10, 10)); 110 assertFalse(b1.equals(b2)); 111 b2.setInteriorGap(new RectangleInsets(10, 10, 10, 10)); 112 assertTrue(b1.equals(b2)); 113 114 b1.setBackgroundPaint(Color.blue); 116 assertFalse(b1.equals(b2)); 117 b2.setBackgroundPaint(Color.blue); 118 assertTrue(b1.equals(b2)); 119 120 b1.setShadowPaint(Color.blue); 122 assertFalse(b1.equals(b2)); 123 b2.setShadowPaint(Color.blue); 124 assertTrue(b1.equals(b2)); 125 126 b1.setShadowXOffset(1.0); 128 assertFalse(b1.equals(b2)); 129 b2.setShadowXOffset(1.0); 130 assertTrue(b1.equals(b2)); 131 132 b1.setShadowYOffset(1.0); 134 assertFalse(b1.equals(b2)); 135 b2.setShadowYOffset(1.0); 136 assertTrue(b1.equals(b2)); 137 138 final TextBlock tb1 = new TextBlock(); 140 tb1.addLine(new TextLine("Testing")); 141 b1.setTextBlock(tb1); 142 assertFalse(b1.equals(b2)); 143 final TextBlock tb2 = new TextBlock(); 144 tb2.addLine(new TextLine("Testing")); 145 b2.setTextBlock(tb2); 146 assertTrue(b1.equals(b2)); 147 148 } 149 150 153 public void testSerialization() { 154 155 final TextBox b1 = new TextBox("Hello"); 156 TextBox b2 = null; 157 158 try { 159 final ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 160 final ObjectOutput out = new ObjectOutputStream (buffer); 161 out.writeObject(b1); 162 out.close(); 163 164 final ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 165 b2 = (TextBox) in.readObject(); 166 in.close(); 167 } 168 catch (Exception e) { 169 System.out.println(e.toString()); 170 } 171 assertEquals(b1, b2); 172 173 } 174 175 } 176 | Popular Tags |