1 42 43 package org.jfree.experimental.chart.plot.dial.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.experimental.chart.plot.dial.DialBackground; 59 import org.jfree.experimental.chart.plot.dial.DialCap; 60 import org.jfree.experimental.chart.plot.dial.DialPlot; 61 import org.jfree.experimental.chart.plot.dial.SimpleDialFrame; 62 import org.jfree.experimental.chart.plot.dial.StandardDialScale; 63 64 67 public class DialPlotTests extends TestCase { 68 69 74 public static Test suite() { 75 return new TestSuite(DialPlotTests.class); 76 } 77 78 83 public DialPlotTests(String name) { 84 super(name); 85 } 86 87 90 public void testEquals() { 91 DialPlot p1 = new DialPlot(); 92 DialPlot p2 = new DialPlot(); 93 assertTrue(p1.equals(p2)); 94 95 p1.setBackground(new DialBackground(Color.green)); 97 assertFalse(p1.equals(p2)); 98 p2.setBackground(new DialBackground(Color.green)); 99 assertTrue(p1.equals(p2)); 100 101 p1.setBackground(null); 102 assertFalse(p1.equals(p2)); 103 p2.setBackground(null); 104 assertTrue(p1.equals(p2)); 105 106 DialCap cap1 = new DialCap(); 108 cap1.setFillPaint(Color.red); 109 p1.setCap(cap1); 110 assertFalse(p1.equals(p2)); 111 DialCap cap2 = new DialCap(); 112 cap2.setFillPaint(Color.red); 113 p2.setCap(cap2); 114 assertTrue(p1.equals(p2)); 115 116 p1.setCap(null); 117 assertFalse(p1.equals(p2)); 118 p2.setCap(null); 119 assertTrue(p1.equals(p2)); 120 121 SimpleDialFrame f1 = new SimpleDialFrame(); 123 f1.setBackgroundPaint(new GradientPaint (1.0f, 2.0f, Color.red, 3.0f, 124 4.0f, Color.white)); 125 p1.setDialFrame(f1); 126 assertFalse(p1.equals(p2)); 127 SimpleDialFrame f2 = new SimpleDialFrame(); 128 f2.setBackgroundPaint(new GradientPaint (1.0f, 2.0f, Color.red, 3.0f, 129 4.0f, Color.white)); 130 p2.setDialFrame(f2); 131 assertTrue(p1.equals(p2)); 132 133 p1.setView(0.2, 0.0, 0.8, 1.0); 135 assertFalse(p1.equals(p2)); 136 p2.setView(0.2, 0.0, 0.8, 1.0); 137 assertTrue(p1.equals(p2)); 138 139 p1.addLayer(new StandardDialScale()); 141 assertFalse(p1.equals(p2)); 142 p2.addLayer(new StandardDialScale()); 143 assertTrue(p1.equals(p2)); 144 } 145 146 149 public void testHashCode() { 150 DialPlot p1 = new DialPlot(); 151 DialPlot p2 = new DialPlot(); 152 assertTrue(p1.equals(p2)); 153 int h1 = p1.hashCode(); 154 int h2 = p2.hashCode(); 155 assertEquals(h1, h2); 156 } 157 158 161 public void testCloning() { 162 DialPlot p1 = new DialPlot(); 163 DialPlot p2 = null; 164 try { 165 p2 = (DialPlot) p1.clone(); 166 } 167 catch (CloneNotSupportedException e) { 168 e.printStackTrace(); 169 } 170 assertTrue(p1 != p2); 171 assertTrue(p1.getClass() == p2.getClass()); 172 assertTrue(p1.equals(p2)); 173 } 174 175 176 179 public void testSerialization() { 180 DialPlot p1 = new DialPlot(); 181 DialPlot p2 = null; 182 183 try { 184 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 185 ObjectOutput out = new ObjectOutputStream (buffer); 186 out.writeObject(p1); 187 out.close(); 188 189 ObjectInput in = new ObjectInputStream ( 190 new ByteArrayInputStream (buffer.toByteArray())); 191 p2 = (DialPlot) in.readObject(); 192 in.close(); 193 } 194 catch (Exception e) { 195 e.printStackTrace(); 196 } 197 assertEquals(p1, p2); 198 } 199 200 } 201 | Popular Tags |