1 43 44 package org.jfree.chart.renderer.xy.junit; 45 46 import java.awt.Color ; 47 import java.awt.GradientPaint ; 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.renderer.xy.XYBoxAndWhiskerRenderer; 60 61 64 public class XYBoxAndWhiskerRendererTests extends TestCase { 65 66 71 public static Test suite() { 72 return new TestSuite(XYBoxAndWhiskerRendererTests.class); 73 } 74 75 80 public XYBoxAndWhiskerRendererTests(String name) { 81 super(name); 82 } 83 84 87 public void testEquals() { 88 89 XYBoxAndWhiskerRenderer r1 = new XYBoxAndWhiskerRenderer(); 90 XYBoxAndWhiskerRenderer r2 = new XYBoxAndWhiskerRenderer(); 91 assertEquals(r1, r2); 92 93 r1.setPaint(new GradientPaint (1.0f, 2.0f, Color.yellow, 94 3.0f, 4.0f, Color.red)); 95 assertFalse(r1.equals(r2)); 96 r2.setPaint(new GradientPaint (1.0f, 2.0f, Color.yellow, 97 3.0f, 4.0f, Color.red)); 98 assertEquals(r1, r2); 99 100 r1.setArtifactPaint(new GradientPaint (1.0f, 2.0f, Color.green, 101 3.0f, 4.0f, Color.red)); 102 assertFalse(r1.equals(r2)); 103 r2.setArtifactPaint(new GradientPaint (1.0f, 2.0f, Color.green, 104 3.0f, 4.0f, Color.red)); 105 assertEquals(r1, r2); 106 107 r1.setBoxWidth(0.55); 108 assertFalse(r1.equals(r2)); 109 r2.setBoxWidth(0.55); 110 assertEquals(r1, r2); 111 112 r1.setFillBox(!r1.getFillBox()); 113 assertFalse(r1.equals(r2)); 114 r2.setFillBox(!r2.getFillBox()); 115 assertEquals(r1, r2); 116 117 } 118 119 122 public void testHashcode() { 123 XYBoxAndWhiskerRenderer r1 = new XYBoxAndWhiskerRenderer(); 124 XYBoxAndWhiskerRenderer r2 = new XYBoxAndWhiskerRenderer(); 125 assertTrue(r1.equals(r2)); 126 int h1 = r1.hashCode(); 127 int h2 = r2.hashCode(); 128 assertEquals(h1, h2); 129 } 130 131 134 public void testCloning() { 135 XYBoxAndWhiskerRenderer r1 = new XYBoxAndWhiskerRenderer(); 136 XYBoxAndWhiskerRenderer r2 = null; 137 try { 138 r2 = (XYBoxAndWhiskerRenderer) r1.clone(); 139 } 140 catch (CloneNotSupportedException e) { 141 System.err.println("Failed to clone."); 142 } 143 assertTrue(r1 != r2); 144 assertTrue(r1.getClass() == r2.getClass()); 145 assertTrue(r1.equals(r2)); 146 } 147 148 151 public void testSerialization() { 152 153 XYBoxAndWhiskerRenderer r1 = new XYBoxAndWhiskerRenderer(); 154 XYBoxAndWhiskerRenderer r2 = null; 155 156 try { 157 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 158 ObjectOutput out = new ObjectOutputStream (buffer); 159 out.writeObject(r1); 160 out.close(); 161 162 ObjectInput in = new ObjectInputStream ( 163 new ByteArrayInputStream (buffer.toByteArray()) 164 ); 165 r2 = (XYBoxAndWhiskerRenderer) in.readObject(); 166 in.close(); 167 } 168 catch (Exception e) { 169 System.out.println(e.toString()); 170 } 171 assertEquals(r1, r2); 172 173 } 174 175 } 176 177 | Popular Tags |