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.ContourEntity; 58 59 62 public class ContourEntityTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(ContourEntityTests.class); 71 } 72 73 78 public ContourEntityTests(String name) { 79 super(name); 80 } 81 82 85 public void testEquals() { 86 ContourEntity e1 = new ContourEntity( 87 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0), "ToolTip", "URL" 88 ); 89 ContourEntity e2 = new ContourEntity( 90 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0), "ToolTip", "URL" 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 e1.setIndex(99); 110 assertFalse(e1.equals(e2)); 111 e2.setIndex(99); 112 assertTrue(e1.equals(e2)); 113 } 114 115 118 public void testCloning() { 119 ContourEntity e1 = new ContourEntity( 120 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0), "ToolTip", "URL" 121 ); 122 ContourEntity e2 = null; 123 124 try { 125 e2 = (ContourEntity) e1.clone(); 126 } 127 catch (CloneNotSupportedException e) { 128 System.err.println("Failed to clone."); 129 } 130 assertTrue(e1 != e2); 131 assertTrue(e1.getClass() == e2.getClass()); 132 assertTrue(e1.equals(e2)); 133 } 134 135 138 public void testSerialization() { 139 ContourEntity e1 = new ContourEntity( 140 new Rectangle2D.Double (1.0, 2.0, 3.0, 4.0), "ToolTip", "URL" 141 ); 142 ContourEntity e2 = null; 143 try { 144 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 145 ObjectOutput out = new ObjectOutputStream (buffer); 146 out.writeObject(e1); 147 out.close(); 148 149 ObjectInput in = new ObjectInputStream ( 150 new ByteArrayInputStream (buffer.toByteArray()) 151 ); 152 e2 = (ContourEntity) in.readObject(); 153 in.close(); 154 } 155 catch (Exception e) { 156 System.out.println(e.toString()); 157 } 158 assertEquals(e1, e2); 159 } 160 161 } 162 | Popular Tags |