1 42 43 package org.jfree.chart.entity.junit; 44 45 import java.awt.geom.Rectangle2D ; 46 import java.io.ByteArrayInputStream ; 47 import java.io.ByteArrayOutputStream ; 48 import java.io.ObjectInput ; 49 import java.io.ObjectInputStream ; 50 import java.io.ObjectOutput ; 51 import java.io.ObjectOutputStream ; 52 53 import junit.framework.Test; 54 import junit.framework.TestCase; 55 import junit.framework.TestSuite; 56 57 import org.jfree.chart.entity.LegendItemEntity; 58 59 62 public class LegendItemEntityTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(LegendItemEntityTests.class); 71 } 72 73 78 public LegendItemEntityTests(String name) { 79 super(name); 80 } 81 82 85 public void testEquals() { 86 LegendItemEntity e1 = new LegendItemEntity( 87 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0) 88 ); 89 LegendItemEntity e2 = new LegendItemEntity( 90 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0) 91 ); 92 assertTrue(e1.equals(e2)); 93 94 e1.setArea(new Rectangle2D.Double (4.0, 3.0, 2.0, 1.0)); 95 assertFalse(e1.equals(e2)); 96 e2.setArea(new Rectangle2D.Double (4.0, 3.0, 2.0, 1.0)); 97 assertTrue(e1.equals(e2)); 98 99 e1.setToolTipText("New ToolTip"); 100 assertFalse(e1.equals(e2)); 101 e2.setToolTipText("New ToolTip"); 102 assertTrue(e1.equals(e2)); 103 104 e1.setURLText("New URL"); 105 assertFalse(e1.equals(e2)); 106 e2.setURLText("New URL"); 107 assertTrue(e1.equals(e2)); 108 } 109 110 113 public void testCloning() { 114 LegendItemEntity e1 = new LegendItemEntity( 115 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0) 116 ); 117 LegendItemEntity e2 = null; 118 119 try { 120 e2 = (LegendItemEntity) e1.clone(); 121 } 122 catch (CloneNotSupportedException e) { 123 System.err.println("Failed to clone."); 124 } 125 assertTrue(e1 != e2); 126 assertTrue(e1.getClass() == e2.getClass()); 127 assertTrue(e1.equals(e2)); 128 } 129 130 133 public void testSerialization() { 134 LegendItemEntity e1 = new LegendItemEntity( 135 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0) 136 ); 137 LegendItemEntity e2 = null; 138 try { 139 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 140 ObjectOutput out = new ObjectOutputStream (buffer); 141 out.writeObject(e1); 142 out.close(); 143 144 ObjectInput in = new ObjectInputStream ( 145 new ByteArrayInputStream (buffer.toByteArray()) 146 ); 147 e2 = (LegendItemEntity) in.readObject(); 148 in.close(); 149 } 150 catch (Exception e) { 151 System.out.println(e.toString()); 152 } 153 assertEquals(e1, e2); 154 } 155 156 } 157 | Popular Tags |