1 42 43 package org.jfree.experimental.chart.plot.dial.junit; 44 45 import java.awt.Color ; 46 import java.awt.GradientPaint ; 47 import java.io.ByteArrayInputStream ; 48 import java.io.ByteArrayOutputStream ; 49 import java.io.ObjectInput ; 50 import java.io.ObjectInputStream ; 51 import java.io.ObjectOutput ; 52 import java.io.ObjectOutputStream ; 53 54 import junit.framework.Test; 55 import junit.framework.TestCase; 56 import junit.framework.TestSuite; 57 58 import org.jfree.experimental.chart.plot.dial.DialTextAnnotation; 59 60 63 public class DialTextAnnotationTests extends TestCase { 64 65 70 public static Test suite() { 71 return new TestSuite(DialTextAnnotationTests.class); 72 } 73 74 79 public DialTextAnnotationTests(String name) { 80 super(name); 81 } 82 83 86 public void testEquals() { 87 DialTextAnnotation a1 = new DialTextAnnotation("A1"); 88 DialTextAnnotation a2 = new DialTextAnnotation("A1"); 89 assertTrue(a1.equals(a2)); 90 91 92 } 93 94 97 public void testHashCode() { 98 DialTextAnnotation a1 = new DialTextAnnotation("A1"); 99 DialTextAnnotation a2 = new DialTextAnnotation("A1"); 100 assertTrue(a1.equals(a2)); 101 int h1 = a1.hashCode(); 102 int h2 = a2.hashCode(); 103 assertEquals(h1, h2); 104 } 105 106 109 public void testCloning() { 110 DialTextAnnotation a1 = new DialTextAnnotation("A1"); 112 DialTextAnnotation a2 = null; 113 try { 114 a2 = (DialTextAnnotation) a1.clone(); 115 } 116 catch (CloneNotSupportedException e) { 117 e.printStackTrace(); 118 } 119 assertTrue(a1 != a2); 120 assertTrue(a1.getClass() == a2.getClass()); 121 assertTrue(a1.equals(a2)); 122 123 125 } 126 127 128 131 public void testSerialization() { 132 DialTextAnnotation a1 = new DialTextAnnotation("A1"); 134 DialTextAnnotation a2 = null; 135 136 try { 137 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 138 ObjectOutput out = new ObjectOutputStream (buffer); 139 out.writeObject(a1); 140 out.close(); 141 142 ObjectInput in = new ObjectInputStream ( 143 new ByteArrayInputStream (buffer.toByteArray())); 144 a2 = (DialTextAnnotation) in.readObject(); 145 in.close(); 146 } 147 catch (Exception e) { 148 e.printStackTrace(); 149 } 150 assertEquals(a1, a2); 151 152 a1 = new DialTextAnnotation("A1"); 154 a1.setPaint(new GradientPaint (1.0f, 2.0f, Color.red, 3.0f, 4.0f, 155 Color.blue)); 156 a2 = null; 157 158 try { 159 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 160 ObjectOutput out = new ObjectOutputStream (buffer); 161 out.writeObject(a1); 162 out.close(); 163 164 ObjectInput in = new ObjectInputStream ( 165 new ByteArrayInputStream (buffer.toByteArray())); 166 a2 = (DialTextAnnotation) in.readObject(); 167 in.close(); 168 } 169 catch (Exception e) { 170 e.printStackTrace(); 171 } 172 assertEquals(a1, a2); 173 174 175 } 176 177 } 178 | Popular Tags |