1 42 43 package org.jfree.chart.renderer.xy.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.chart.renderer.xy.XYErrorRenderer; 59 60 63 public class XYErrorRendererTests extends TestCase { 64 65 70 public static Test suite() { 71 return new TestSuite(XYErrorRendererTests.class); 72 } 73 74 79 public XYErrorRendererTests(String name) { 80 super(name); 81 } 82 83 86 public void testEquals() { 87 XYErrorRenderer r1 = new XYErrorRenderer(); 88 XYErrorRenderer r2 = new XYErrorRenderer(); 89 assertEquals(r1, r2); 90 91 r1.setDrawXError(false); 93 assertFalse(r1.equals(r2)); 94 r2.setDrawXError(false); 95 assertTrue(r1.equals(r2)); 96 97 r1.setDrawYError(false); 99 assertFalse(r1.equals(r2)); 100 r2.setDrawYError(false); 101 assertTrue(r1.equals(r2)); 102 103 r1.setCapLength(9.0); 105 assertFalse(r1.equals(r2)); 106 r2.setCapLength(9.0); 107 assertTrue(r1.equals(r2)); 108 109 r1.setErrorPaint(new GradientPaint (1.0f, 2.0f, Color.red, 3.0f, 4.0f, 111 Color.green)); 112 assertFalse(r1.equals(r2)); 113 r2.setErrorPaint(new GradientPaint (1.0f, 2.0f, Color.red, 3.0f, 4.0f, 114 Color.green)); 115 assertTrue(r1.equals(r2)); 116 } 117 118 121 public void testHashcode() { 122 XYErrorRenderer r1 = new XYErrorRenderer(); 123 XYErrorRenderer r2 = new XYErrorRenderer(); 124 assertTrue(r1.equals(r2)); 125 int h1 = r1.hashCode(); 126 int h2 = r2.hashCode(); 127 assertEquals(h1, h2); 128 } 129 130 133 public void testCloning() { 134 XYErrorRenderer r1 = new XYErrorRenderer(); 135 r1.setErrorPaint(new GradientPaint (1.0f, 2.0f, Color.red, 3.0f, 4.0f, 136 Color.white)); 137 XYErrorRenderer r2 = null; 138 try { 139 r2 = (XYErrorRenderer) r1.clone(); 140 } 141 catch (CloneNotSupportedException e) { 142 e.printStackTrace(); 143 } 144 assertTrue(r1 != r2); 145 assertTrue(r1.getClass() == r2.getClass()); 146 assertTrue(r1.equals(r2)); 147 } 148 149 152 public void testSerialization() { 153 154 XYErrorRenderer r1 = new XYErrorRenderer(); 155 r1.setErrorPaint(new GradientPaint (1.0f, 2.0f, Color.red, 3.0f, 4.0f, 156 Color.white)); 157 XYErrorRenderer r2 = null; 158 159 try { 160 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 161 ObjectOutput out = new ObjectOutputStream (buffer); 162 out.writeObject(r1); 163 out.close(); 164 165 ObjectInput in = new ObjectInputStream ( 166 new ByteArrayInputStream (buffer.toByteArray())); 167 r2 = (XYErrorRenderer) in.readObject(); 168 in.close(); 169 } 170 catch (Exception e) { 171 e.printStackTrace(); 172 } 173 assertEquals(r1, r2); 174 175 } 176 177 } 178 | Popular Tags |