1 43 44 package org.jfree.chart.renderer.xy.junit; 45 46 import java.awt.Color ; 47 import java.awt.GradientPaint ; 48 import java.awt.geom.Line2D ; 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.renderer.xy.XYDifferenceRenderer; 61 62 65 public class XYDifferenceRendererTests extends TestCase { 66 67 72 public static Test suite() { 73 return new TestSuite(XYDifferenceRendererTests.class); 74 } 75 76 81 public XYDifferenceRendererTests(String name) { 82 super(name); 83 } 84 85 88 public void testEquals() { 89 XYDifferenceRenderer r1 = new XYDifferenceRenderer( 90 Color.red, Color.blue, false); 91 XYDifferenceRenderer r2 = new XYDifferenceRenderer( 92 Color.red, Color.blue, false); 93 assertEquals(r1, r2); 94 95 r1.setPositivePaint(new GradientPaint (1.0f, 2.0f, Color.red, 97 3.0f, 4.0f, Color.blue)); 98 assertFalse(r1.equals(r2)); 99 r2.setPositivePaint(new GradientPaint (1.0f, 2.0f, Color.red, 100 3.0f, 4.0f, Color.blue)); 101 assertTrue(r1.equals(r2)); 102 103 r1.setNegativePaint(new GradientPaint (1.0f, 2.0f, Color.yellow, 105 3.0f, 4.0f, Color.blue)); 106 assertFalse(r1.equals(r2)); 107 r2.setNegativePaint(new GradientPaint (1.0f, 2.0f, Color.yellow, 108 3.0f, 4.0f, Color.blue)); 109 assertTrue(r1.equals(r2)); 110 111 r1 = new XYDifferenceRenderer(Color.green, Color.yellow, true); 113 assertFalse(r1.equals(r2)); 114 r2 = new XYDifferenceRenderer(Color.green, Color.yellow, true); 115 assertTrue(r1.equals(r2)); 116 117 r1.setLegendLine(new Line2D.Double (1.0, 2.0, 3.0, 4.0)); 119 assertFalse(r1.equals(r2)); 120 r2.setLegendLine(new Line2D.Double (1.0, 2.0, 3.0, 4.0)); 121 assertTrue(r1.equals(r2)); 122 123 assertFalse(r1.equals(null)); 124 } 125 126 129 public void testHashcode() { 130 XYDifferenceRenderer r1 131 = new XYDifferenceRenderer(Color.red, Color.blue, false); 132 XYDifferenceRenderer r2 133 = new XYDifferenceRenderer(Color.red, Color.blue, false); 134 assertTrue(r1.equals(r2)); 135 int h1 = r1.hashCode(); 136 int h2 = r2.hashCode(); 137 assertEquals(h1, h2); 138 } 139 140 143 public void testCloning() { 144 XYDifferenceRenderer r1 145 = new XYDifferenceRenderer(Color.red, Color.blue, false); 146 XYDifferenceRenderer r2 = null; 147 try { 148 r2 = (XYDifferenceRenderer) r1.clone(); 149 } 150 catch (CloneNotSupportedException e) { 151 System.err.println("Failed to clone."); 152 } 153 assertTrue(r1 != r2); 154 assertTrue(r1.getClass() == r2.getClass()); 155 assertTrue(r1.equals(r2)); 156 } 157 158 161 public void testSerialization() { 162 163 XYDifferenceRenderer r1 164 = new XYDifferenceRenderer(Color.red, Color.blue, false); 165 XYDifferenceRenderer r2 = null; 166 167 try { 168 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 169 ObjectOutput out = new ObjectOutputStream (buffer); 170 out.writeObject(r1); 171 out.close(); 172 173 ObjectInput in = new ObjectInputStream ( 174 new ByteArrayInputStream (buffer.toByteArray()) 175 ); 176 r2 = (XYDifferenceRenderer) in.readObject(); 177 in.close(); 178 } 179 catch (Exception e) { 180 System.out.println(e.toString()); 181 } 182 assertEquals(r1, r2); 183 184 } 185 186 } 187 | Popular Tags |