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.XYLineAnnotation; 60 61 64 public class XYLineAnnotationTests extends TestCase { 65 66 71 public static Test suite() { 72 return new TestSuite(XYLineAnnotationTests.class); 73 } 74 75 80 public XYLineAnnotationTests(String name) { 81 super(name); 82 } 83 84 87 public void testEquals() { 88 Stroke stroke = new BasicStroke (2.0f); 89 XYLineAnnotation a1 = new XYLineAnnotation( 90 10.0, 20.0, 100.0, 200.0, stroke, Color.blue 91 ); 92 XYLineAnnotation a2 = new XYLineAnnotation( 93 10.0, 20.0, 100.0, 200.0, stroke, Color.blue 94 ); 95 assertTrue(a1.equals(a2)); 96 } 97 98 101 public void testHashCode() { 102 Stroke stroke = new BasicStroke (2.0f); 103 XYLineAnnotation a1 = new XYLineAnnotation( 104 10.0, 20.0, 100.0, 200.0, stroke, Color.blue 105 ); 106 XYLineAnnotation a2 = new XYLineAnnotation( 107 10.0, 20.0, 100.0, 200.0, stroke, Color.blue 108 ); 109 assertTrue(a1.equals(a2)); 110 int h1 = a1.hashCode(); 111 int h2 = a2.hashCode(); 112 assertEquals(h1, h2); 113 } 114 115 118 public void testCloning() { 119 Stroke stroke = new BasicStroke (2.0f); 120 XYLineAnnotation a1 = new XYLineAnnotation( 121 10.0, 20.0, 100.0, 200.0, stroke, Color.blue 122 ); 123 XYLineAnnotation a2 = null; 124 try { 125 a2 = (XYLineAnnotation) a1.clone(); 126 } 127 catch (CloneNotSupportedException e) { 128 System.err.println("Failed to clone."); 129 } 130 assertTrue(a1 != a2); 131 assertTrue(a1.getClass() == a2.getClass()); 132 assertTrue(a1.equals(a2)); 133 } 134 135 138 public void testSerialization() { 139 140 Stroke stroke = new BasicStroke (2.0f); 141 XYLineAnnotation a1 = new XYLineAnnotation( 142 10.0, 20.0, 100.0, 200.0, stroke, Color.blue 143 ); 144 XYLineAnnotation a2 = null; 145 146 try { 147 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 148 ObjectOutput out = new ObjectOutputStream (buffer); 149 out.writeObject(a1); 150 out.close(); 151 152 ObjectInput in = new ObjectInputStream ( 153 new ByteArrayInputStream (buffer.toByteArray()) 154 ); 155 a2 = (XYLineAnnotation) in.readObject(); 156 in.close(); 157 } 158 catch (Exception e) { 159 System.out.println(e.toString()); 160 } 161 assertEquals(a1, a2); 162 163 } 164 165 } 166 | Popular Tags |