1 37 38 package org.jfree.chart.renderer.junit; 39 40 import java.io.ByteArrayInputStream ; 41 import java.io.ByteArrayOutputStream ; 42 import java.io.ObjectInput ; 43 import java.io.ObjectInputStream ; 44 import java.io.ObjectOutput ; 45 import java.io.ObjectOutputStream ; 46 47 import junit.framework.Test; 48 import junit.framework.TestCase; 49 import junit.framework.TestSuite; 50 51 import org.jfree.chart.renderer.LineAndShapeRenderer; 52 53 58 public class LineAndShapeRendererTests extends TestCase { 59 60 65 public static Test suite() { 66 return new TestSuite(LineAndShapeRendererTests.class); 67 } 68 69 74 public LineAndShapeRendererTests(String name) { 75 super(name); 76 } 77 78 81 public void testEquals() { 82 LineAndShapeRenderer r1 = new LineAndShapeRenderer(); 83 LineAndShapeRenderer r2 = new LineAndShapeRenderer(); 84 assertEquals(r1, r2); 85 } 86 87 90 public void testHashcode() { 91 LineAndShapeRenderer r1 = new LineAndShapeRenderer(); 92 LineAndShapeRenderer r2 = new LineAndShapeRenderer(); 93 assertTrue(r1.equals(r2)); 94 int h1 = r1.hashCode(); 95 int h2 = r2.hashCode(); 96 assertEquals(h1, h2); 97 } 98 99 102 public void testCloning() { 103 LineAndShapeRenderer r1 = new LineAndShapeRenderer(); 104 LineAndShapeRenderer r2 = null; 105 try { 106 r2 = (LineAndShapeRenderer) r1.clone(); 107 } 108 catch (CloneNotSupportedException e) { 109 System.err.println("LineAndShapeRendererTests.testCloning: failed to clone."); 110 } 111 assertTrue(r1 != r2); 112 assertTrue(r1.getClass() == r2.getClass()); 113 assertTrue(r1.equals(r2)); 114 115 assertTrue(checkIndependence(r1, r2)); 116 117 } 118 119 127 private boolean checkIndependence(LineAndShapeRenderer r1, LineAndShapeRenderer r2) { 128 129 boolean b0 = r1.equals(r2); 131 132 r1.setDrawShapes(!r1.isDrawShapes()); 134 boolean b1 = !r1.equals(r2); 135 r2.setDrawShapes(r1.isDrawShapes()); 136 boolean b2 = r1.equals(r2); 137 138 r1.setDrawLines(!r1.isDrawLines()); 139 boolean b3 = !r1.equals(r2); 140 r2.setDrawLines(r1.isDrawLines()); 141 boolean b4 = r1.equals(r2); 142 143 boolean flag = true; 144 Boolean existing = r1.getShapesFilled(); 145 if (existing != null) { 146 flag = !existing.booleanValue(); 147 } 148 r1.setShapesFilled(flag); 149 boolean b5 = !r1.equals(r2); 150 r2.setShapesFilled(flag); 151 boolean b6 = r1.equals(r2); 152 153 r1.setShapesFilled(false); 154 r2.setShapesFilled(false); 155 r1.setSeriesShapesFilled(0, false); 156 r2.setSeriesShapesFilled(0, true); 157 boolean b7 = !r1.equals(r2); 158 r2.setSeriesShapesFilled(0, false); 159 boolean b8 = (r1.equals(r2)); 160 161 r1.setDefaultShapesFilled(false); 162 r2.setDefaultShapesFilled(true); 163 boolean b9 = !r1.equals(r2); 164 r2.setDefaultShapesFilled(false); 165 boolean b10 = (r1.equals(r2)); 166 167 return b0 && b1 && b2 && b3 && b4 && b5 && b6 && b7 && b8 && b9 && b10; 168 169 } 170 171 174 public void testSerialization() { 175 176 LineAndShapeRenderer r1 = new LineAndShapeRenderer(); 177 LineAndShapeRenderer r2 = null; 178 179 try { 180 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 181 ObjectOutput out = new ObjectOutputStream (buffer); 182 out.writeObject(r1); 183 out.close(); 184 185 ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 186 r2 = (LineAndShapeRenderer) in.readObject(); 187 in.close(); 188 } 189 catch (Exception e) { 190 System.out.println(e.toString()); 191 } 192 assertEquals(r1, r2); 193 194 } 195 196 } 197 | Popular Tags |