1 42 43 package org.jfree.chart.plot.junit; 44 45 import java.awt.Color ; 46 import java.awt.Font ; 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 import java.text.DecimalFormat ; 54 55 import junit.framework.Test; 56 import junit.framework.TestCase; 57 import junit.framework.TestSuite; 58 59 import org.jfree.chart.plot.DialShape; 60 import org.jfree.chart.plot.MeterInterval; 61 import org.jfree.chart.plot.MeterPlot; 62 import org.jfree.data.Range; 63 import org.jfree.data.general.DefaultValueDataset; 64 65 68 public class MeterPlotTests extends TestCase { 69 70 75 public static Test suite() { 76 return new TestSuite(MeterPlotTests.class); 77 } 78 79 84 public MeterPlotTests(String name) { 85 super(name); 86 } 87 88 92 public void testEquals() { 93 MeterPlot plot1 = new MeterPlot(); 94 MeterPlot plot2 = new MeterPlot(); 95 assertTrue(plot1.equals(plot2)); 96 97 plot1.setUnits("mph"); 99 assertFalse(plot1.equals(plot2)); 100 plot2.setUnits("mph"); 101 assertTrue(plot1.equals(plot2)); 102 103 plot1.setRange(new Range(50.0, 70.0)); 105 assertFalse(plot1.equals(plot2)); 106 plot2.setRange(new Range(50.0, 70.0)); 107 assertTrue(plot1.equals(plot2)); 108 109 plot1.addInterval(new MeterInterval("Normal", new Range(55.0, 60.0))); 111 assertFalse(plot1.equals(plot2)); 112 plot2.addInterval(new MeterInterval("Normal", new Range(55.0, 60.0))); 113 assertTrue(plot1.equals(plot2)); 114 115 plot1.setDialOutlinePaint(Color.red); 117 assertFalse(plot1.equals(plot2)); 118 plot2.setDialOutlinePaint(Color.red); 119 assertTrue(plot1.equals(plot2)); 120 121 plot1.setDialShape(DialShape.CHORD); 123 assertFalse(plot1.equals(plot2)); 124 plot2.setDialShape(DialShape.CHORD); 125 assertTrue(plot1.equals(plot2)); 126 127 plot1.setDialBackgroundPaint(Color.yellow); 129 assertFalse(plot1.equals(plot2)); 130 plot2.setDialBackgroundPaint(Color.yellow); 131 assertTrue(plot1.equals(plot2)); 132 133 plot1.setNeedlePaint(Color.black); 135 assertFalse(plot1.equals(plot2)); 136 plot2.setNeedlePaint(Color.black); 137 assertTrue(plot1.equals(plot2)); 138 139 plot1.setValueFont(new Font ("Serif", Font.PLAIN, 6)); 141 assertFalse(plot1.equals(plot2)); 142 plot2.setValueFont(new Font ("Serif", Font.PLAIN, 6)); 143 assertTrue(plot1.equals(plot2)); 144 145 plot1.setValuePaint(Color.black); 147 assertFalse(plot1.equals(plot2)); 148 plot2.setValuePaint(Color.black); 149 assertTrue(plot1.equals(plot2)); 150 151 plot1.setTickLabelsVisible(false); 153 assertFalse(plot1.equals(plot2)); 154 plot2.setTickLabelsVisible(false); 155 assertTrue(plot1.equals(plot2)); 156 157 plot1.setTickLabelFont(new Font ("Serif", Font.PLAIN, 6)); 159 assertFalse(plot1.equals(plot2)); 160 plot2.setTickLabelFont(new Font ("Serif", Font.PLAIN, 6)); 161 assertTrue(plot1.equals(plot2)); 162 163 plot1.setTickLabelFormat(new DecimalFormat ("0")); 165 assertFalse(plot1.equals(plot2)); 166 plot2.setTickLabelFormat(new DecimalFormat ("0")); 167 assertTrue(plot1.equals(plot2)); 168 169 plot1.setDrawBorder(!plot1.getDrawBorder()); 171 assertFalse(plot1.equals(plot2)); 172 plot2.setDrawBorder(plot1.getDrawBorder()); 173 assertTrue(plot1.equals(plot2)); 174 175 plot1.setMeterAngle(22); 177 assertFalse(plot1.equals(plot2)); 178 plot2.setMeterAngle(22); 179 assertTrue(plot1.equals(plot2)); 180 181 } 182 183 186 public void testCloning() { 187 MeterPlot p1 = new MeterPlot(); 188 MeterPlot p2 = null; 189 try { 190 p2 = (MeterPlot) p1.clone(); 191 } 192 catch (CloneNotSupportedException e) { 193 e.printStackTrace(); 194 System.err.println("Failed to clone."); 195 } 196 assertTrue(p1 != p2); 197 assertTrue(p1.getClass() == p2.getClass()); 198 assertTrue(p1.equals(p2)); 199 200 assertTrue(p1.getDataset() == p2.getDataset()); 202 203 p1.getTickLabelFormat().setMinimumIntegerDigits(99); 206 assertFalse(p1.equals(p2)); 207 p2.getTickLabelFormat().setMinimumIntegerDigits(99); 208 assertTrue(p1.equals(p2)); 209 210 p1.addInterval(new MeterInterval("Test", new Range(1.234, 5.678))); 211 assertFalse(p1.equals(p2)); 212 p2.addInterval(new MeterInterval("Test", new Range(1.234, 5.678))); 213 assertTrue(p1.equals(p2)); 214 215 } 216 217 220 public void testSerialization1() { 221 MeterPlot p1 = new MeterPlot(null); 222 MeterPlot p2 = null; 223 try { 224 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 225 ObjectOutput out = new ObjectOutputStream (buffer); 226 out.writeObject(p1); 227 out.close(); 228 229 ObjectInput in = new ObjectInputStream ( 230 new ByteArrayInputStream (buffer.toByteArray()) 231 ); 232 p2 = (MeterPlot) in.readObject(); 233 in.close(); 234 } 235 catch (Exception e) { 236 System.out.println(e.toString()); 237 } 238 assertEquals(p1, p2); 239 } 240 241 244 public void testSerialization2() { 245 MeterPlot p1 = new MeterPlot(new DefaultValueDataset(1.23)); 246 MeterPlot p2 = null; 247 try { 248 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 249 ObjectOutput out = new ObjectOutputStream (buffer); 250 out.writeObject(p1); 251 out.close(); 252 253 ObjectInput in = new ObjectInputStream ( 254 new ByteArrayInputStream (buffer.toByteArray()) 255 ); 256 p2 = (MeterPlot) in.readObject(); 257 in.close(); 258 } 259 catch (Exception e) { 260 e.printStackTrace(); 261 } 262 assertEquals(p1, p2); 263 264 } 265 266 } 267 | Popular Tags |