1 42 43 package org.jfree.text.junit; 44 45 import java.io.ByteArrayInputStream ; 46 import java.io.ByteArrayOutputStream ; 47 import java.io.ObjectInput ; 48 import java.io.ObjectInputStream ; 49 import java.io.ObjectOutput ; 50 import java.io.ObjectOutputStream ; 51 52 import junit.framework.Test; 53 import junit.framework.TestCase; 54 import junit.framework.TestSuite; 55 56 import org.jfree.text.TextBlock; 57 import org.jfree.text.TextLine; 58 59 62 public class TextBlockTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(TextBlockTests.class); 71 } 72 73 78 public TextBlockTests(final String name) { 79 super(name); 80 } 81 82 85 public void testEquals() { 86 87 final TextBlock b1 = new TextBlock(); 88 b1.addLine(new TextLine("Test")); 89 final TextBlock b2 = new TextBlock(); 90 b2.addLine(new TextLine("Test")); 91 assertTrue(b1.equals(b2)); 92 assertTrue(b2.equals(b1)); 93 94 } 95 96 99 public void testSerialization() { 100 101 final TextBlock b1 = new TextBlock(); 102 b1.addLine(new TextLine("Test")); 103 TextBlock b2 = null; 104 105 try { 106 final ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 107 final ObjectOutput out = new ObjectOutputStream (buffer); 108 out.writeObject(b1); 109 out.close(); 110 111 final ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 112 b2 = (TextBlock) in.readObject(); 113 in.close(); 114 } 115 catch (Exception e) { 116 System.out.println(e.toString()); 117 } 118 assertEquals(b1, b2); 119 120 } 121 122 } 123 | Popular Tags |