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