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.XYItemEntity; 58 import org.jfree.data.time.TimeSeriesCollection; 59 60 63 public class XYItemEntityTests extends TestCase { 64 65 70 public static Test suite() { 71 return new TestSuite(XYItemEntityTests.class); 72 } 73 74 79 public XYItemEntityTests(String name) { 80 super(name); 81 } 82 83 86 public void testEquals() { 87 XYItemEntity e1 = new XYItemEntity( 88 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0), 89 new TimeSeriesCollection(), 1, 9, "ToolTip", "URL" 90 ); 91 XYItemEntity e2 = new XYItemEntity( 92 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0), 93 new TimeSeriesCollection(), 1, 9, "ToolTip", "URL" 94 ); 95 assertTrue(e1.equals(e2)); 96 97 e1.setArea(new Rectangle2D.Double (4.0, 3.0, 2.0, 1.0)); 98 assertFalse(e1.equals(e2)); 99 e2.setArea(new Rectangle2D.Double (4.0, 3.0, 2.0, 1.0)); 100 assertTrue(e1.equals(e2)); 101 102 e1.setToolTipText("New ToolTip"); 103 assertFalse(e1.equals(e2)); 104 e2.setToolTipText("New ToolTip"); 105 assertTrue(e1.equals(e2)); 106 107 e1.setURLText("New URL"); 108 assertFalse(e1.equals(e2)); 109 e2.setURLText("New URL"); 110 assertTrue(e1.equals(e2)); 111 112 e1.setSeriesIndex(88); 113 assertFalse(e1.equals(e2)); 114 e2.setSeriesIndex(88); 115 assertTrue(e1.equals(e2)); 116 117 e1.setItem(88); 118 assertFalse(e1.equals(e2)); 119 e2.setItem(88); 120 assertTrue(e1.equals(e2)); 121 122 } 123 124 127 public void testCloning() { 128 XYItemEntity e1 = new XYItemEntity( 129 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0), 130 new TimeSeriesCollection(), 1, 9, "ToolTip", "URL" 131 ); 132 XYItemEntity e2 = null; 133 134 try { 135 e2 = (XYItemEntity) e1.clone(); 136 } 137 catch (CloneNotSupportedException e) { 138 System.err.println("Failed to clone."); 139 } 140 assertTrue(e1 != e2); 141 assertTrue(e1.getClass() == e2.getClass()); 142 assertTrue(e1.equals(e2)); 143 } 144 145 148 public void testSerialization() { 149 XYItemEntity e1 = new XYItemEntity( 150 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0), 151 new TimeSeriesCollection(), 1, 9, "ToolTip", "URL" 152 ); 153 XYItemEntity e2 = null; 154 try { 155 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 156 ObjectOutput out = new ObjectOutputStream (buffer); 157 out.writeObject(e1); 158 out.close(); 159 160 ObjectInput in = new ObjectInputStream ( 161 new ByteArrayInputStream (buffer.toByteArray()) 162 ); 163 e2 = (XYItemEntity) in.readObject(); 164 in.close(); 165 } 166 catch (Exception e) { 167 System.out.println(e.toString()); 168 } 169 assertEquals(e1, e2); 170 } 171 172 } 173 | Popular Tags |