1 43 44 package org.jfree.chart.plot.junit; 45 46 import java.awt.BasicStroke ; 47 import java.awt.Color ; 48 import java.awt.Font ; 49 import java.awt.GradientPaint ; 50 import java.awt.Stroke ; 51 import java.io.ByteArrayInputStream ; 52 import java.io.ByteArrayOutputStream ; 53 import java.io.ObjectInput ; 54 import java.io.ObjectInputStream ; 55 import java.io.ObjectOutput ; 56 import java.io.ObjectOutputStream ; 57 58 import junit.framework.Test; 59 import junit.framework.TestCase; 60 import junit.framework.TestSuite; 61 62 import org.jfree.chart.axis.NumberAxis; 63 import org.jfree.chart.plot.PolarPlot; 64 65 68 public class PolarPlotTests extends TestCase { 69 70 75 public static Test suite() { 76 return new TestSuite(PolarPlotTests.class); 77 } 78 79 84 public PolarPlotTests(String name) { 85 super(name); 86 } 87 88 91 public void testEquals() { 92 PolarPlot plot1 = new PolarPlot(); 93 PolarPlot plot2 = new PolarPlot(); 94 assertTrue(plot1.equals(plot2)); 95 assertTrue(plot2.equals(plot1)); 96 97 plot1.setAngleGridlinePaint(new GradientPaint (1.0f, 2.0f, Color.red, 98 3.0f, 4.0f, Color.blue)); 99 assertFalse(plot1.equals(plot2)); 100 plot2.setAngleGridlinePaint(new GradientPaint (1.0f, 2.0f, Color.red, 101 3.0f, 4.0f, Color.blue)); 102 assertTrue(plot1.equals(plot2)); 103 104 Stroke s = new BasicStroke (1.23f); 105 plot1.setAngleGridlineStroke(s); 106 assertFalse(plot1.equals(plot2)); 107 plot2.setAngleGridlineStroke(s); 108 assertTrue(plot1.equals(plot2)); 109 110 plot1.setAngleGridlinesVisible(false); 111 assertFalse(plot1.equals(plot2)); 112 plot2.setAngleGridlinesVisible(false); 113 assertTrue(plot1.equals(plot2)); 114 115 plot1.setAngleLabelFont(new Font ("Serif", Font.PLAIN, 9)); 116 assertFalse(plot1.equals(plot2)); 117 plot2.setAngleLabelFont(new Font ("Serif", Font.PLAIN, 9)); 118 assertTrue(plot1.equals(plot2)); 119 120 plot1.setAngleLabelPaint(new GradientPaint (9.0f, 8.0f, Color.blue, 121 7.0f, 6.0f, Color.red)); 122 assertFalse(plot1.equals(plot2)); 123 plot2.setAngleLabelPaint(new GradientPaint (9.0f, 8.0f, Color.blue, 124 7.0f, 6.0f, Color.red)); 125 assertTrue(plot1.equals(plot2)); 126 127 plot1.setAngleLabelsVisible(false); 128 assertFalse(plot1.equals(plot2)); 129 plot2.setAngleLabelsVisible(false); 130 assertTrue(plot1.equals(plot2)); 131 132 plot1.setAxis(new NumberAxis("Test")); 133 assertFalse(plot1.equals(plot2)); 134 plot2.setAxis(new NumberAxis("Test")); 135 assertTrue(plot1.equals(plot2)); 136 137 plot1.setRadiusGridlinePaint(new GradientPaint (1.0f, 2.0f, Color.white, 138 3.0f, 4.0f, Color.black)); 139 assertFalse(plot1.equals(plot2)); 140 plot2.setRadiusGridlinePaint(new GradientPaint (1.0f, 2.0f, Color.white, 141 3.0f, 4.0f, Color.black)); 142 assertTrue(plot1.equals(plot2)); 143 144 plot1.setRadiusGridlineStroke(s); 145 assertFalse(plot1.equals(plot2)); 146 plot2.setRadiusGridlineStroke(s); 147 assertTrue(plot1.equals(plot2)); 148 149 plot1.setRadiusGridlinesVisible(false); 150 assertFalse(plot1.equals(plot2)); 151 plot2.setRadiusGridlinesVisible(false); 152 assertTrue(plot1.equals(plot2)); 153 } 154 155 158 public void testCloning() { 159 PolarPlot p1 = new PolarPlot(); 160 PolarPlot p2 = null; 161 try { 162 p2 = (PolarPlot) p1.clone(); 163 } 164 catch (CloneNotSupportedException e) { 165 e.printStackTrace(); 166 System.err.println("Failed to clone."); 167 } 168 assertTrue(p1 != p2); 169 assertTrue(p1.getClass() == p2.getClass()); 170 assertTrue(p1.equals(p2)); 171 } 172 173 176 public void testSerialization() { 177 178 PolarPlot p1 = new PolarPlot(); 179 PolarPlot p2 = null; 180 181 try { 182 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 183 ObjectOutput out = new ObjectOutputStream (buffer); 184 out.writeObject(p1); 185 out.close(); 186 187 ObjectInput in = new ObjectInputStream ( 188 new ByteArrayInputStream (buffer.toByteArray()) 189 ); 190 p2 = (PolarPlot) in.readObject(); 191 in.close(); 192 } 193 catch (Exception e) { 194 e.printStackTrace(); 195 } 196 assertEquals(p1, p2); 197 198 } 199 200 } 201 | Popular Tags |