1 43 44 package org.jfree.chart.annotations.junit; 45 46 import java.awt.BasicStroke ; 47 import java.awt.Color ; 48 import java.awt.Stroke ; 49 import java.io.ByteArrayInputStream ; 50 import java.io.ByteArrayOutputStream ; 51 import java.io.ObjectInput ; 52 import java.io.ObjectInputStream ; 53 import java.io.ObjectOutput ; 54 import java.io.ObjectOutputStream ; 55 56 import junit.framework.Test; 57 import junit.framework.TestCase; 58 import junit.framework.TestSuite; 59 60 import org.jfree.chart.annotations.XYPointerAnnotation; 61 62 65 public class XYPointerAnnotationTests extends TestCase { 66 67 72 public static Test suite() { 73 return new TestSuite(XYPointerAnnotationTests.class); 74 } 75 76 81 public XYPointerAnnotationTests(String name) { 82 super(name); 83 } 84 85 88 public void testEquals() { 89 90 XYPointerAnnotation a1 = new XYPointerAnnotation( 91 "Label", 10.0, 20.0, Math.PI 92 ); 93 XYPointerAnnotation a2 = new XYPointerAnnotation( 94 "Label", 10.0, 20.0, Math.PI 95 ); 96 assertTrue(a1.equals(a2)); 97 98 a1.setAngle(Math.PI / 4.0); 100 assertFalse(a1.equals(a2)); 101 a2.setAngle(Math.PI / 4.0); 102 assertTrue(a1.equals(a2)); 103 104 a1.setTipRadius(20.0); 106 assertFalse(a1.equals(a2)); 107 a2.setTipRadius(20.0); 108 assertTrue(a1.equals(a2)); 109 110 a1.setBaseRadius(5.0); 112 assertFalse(a1.equals(a2)); 113 a2.setBaseRadius(5.0); 114 assertTrue(a1.equals(a2)); 115 116 a1.setArrowLength(33.0); 118 assertFalse(a1.equals(a2)); 119 a2.setArrowLength(33.0); 120 assertTrue(a1.equals(a2)); 121 122 a1.setArrowWidth(9.0); 124 assertFalse(a1.equals(a2)); 125 a2.setArrowWidth(9.0); 126 assertTrue(a1.equals(a2)); 127 128 Stroke stroke = new BasicStroke (1.5f); 130 a1.setArrowStroke(stroke); 131 assertFalse(a1.equals(a2)); 132 a2.setArrowStroke(stroke); 133 assertTrue(a1.equals(a2)); 134 135 a1.setArrowPaint(Color.blue); 137 assertFalse(a1.equals(a2)); 138 a2.setArrowPaint(Color.blue); 139 assertTrue(a1.equals(a2)); 140 141 a1.setLabelOffset(10.0); 143 assertFalse(a1.equals(a2)); 144 a2.setLabelOffset(10.0); 145 assertTrue(a1.equals(a2)); 146 147 } 148 149 152 public void testHashCode() { 153 XYPointerAnnotation a1 = new XYPointerAnnotation( 154 "Label", 10.0, 20.0, Math.PI 155 ); 156 XYPointerAnnotation a2 = new XYPointerAnnotation( 157 "Label", 10.0, 20.0, Math.PI 158 ); 159 assertTrue(a1.equals(a2)); 160 int h1 = a1.hashCode(); 161 int h2 = a2.hashCode(); 162 assertEquals(h1, h2); 163 } 164 165 168 public void testCloning() { 169 170 XYPointerAnnotation a1 = new XYPointerAnnotation( 171 "Label", 10.0, 20.0, Math.PI 172 ); 173 XYPointerAnnotation a2 = null; 174 try { 175 a2 = (XYPointerAnnotation) a1.clone(); 176 } 177 catch (CloneNotSupportedException e) { 178 System.err.println("Failed to clone."); 179 } 180 assertTrue(a1 != a2); 181 assertTrue(a1.getClass() == a2.getClass()); 182 assertTrue(a1.equals(a2)); 183 } 184 185 188 public void testSerialization() { 189 190 XYPointerAnnotation a1 = new XYPointerAnnotation( 191 "Label", 10.0, 20.0, Math.PI 192 ); 193 XYPointerAnnotation a2 = null; 194 195 try { 196 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 197 ObjectOutput out = new ObjectOutputStream (buffer); 198 out.writeObject(a1); 199 out.close(); 200 201 ObjectInput in = new ObjectInputStream ( 202 new ByteArrayInputStream (buffer.toByteArray()) 203 ); 204 a2 = (XYPointerAnnotation) in.readObject(); 205 in.close(); 206 } 207 catch (Exception e) { 208 System.out.println(e.toString()); 209 } 210 assertEquals(a1, a2); 211 212 } 213 214 } 215 | Popular Tags |