1 43 44 package org.jfree.chart.plot.junit; 45 46 import java.awt.BasicStroke ; 47 import java.awt.Color ; 48 import java.awt.GradientPaint ; 49 import java.awt.Stroke ; 50 import java.io.ByteArrayInputStream ; 51 import java.io.ByteArrayOutputStream ; 52 import java.io.ObjectInput ; 53 import java.io.ObjectInputStream ; 54 import java.io.ObjectOutput ; 55 import java.io.ObjectOutputStream ; 56 57 import junit.framework.Test; 58 import junit.framework.TestCase; 59 import junit.framework.TestSuite; 60 61 import org.jfree.chart.plot.RingPlot; 62 63 66 public class RingPlotTests extends TestCase { 67 68 73 public static Test suite() { 74 return new TestSuite(RingPlotTests.class); 75 } 76 77 82 public RingPlotTests(String name) { 83 super(name); 84 } 85 86 89 public void testEquals() { 90 91 RingPlot plot1 = new RingPlot(null); 92 RingPlot plot2 = new RingPlot(null); 93 assertTrue(plot1.equals(plot2)); 94 assertTrue(plot2.equals(plot1)); 95 96 plot1.setSeparatorsVisible(false); 98 assertFalse(plot1.equals(plot2)); 99 plot2.setSeparatorsVisible(false); 100 assertTrue(plot1.equals(plot2)); 101 102 Stroke s = new BasicStroke (1.1f); 104 plot1.setSeparatorStroke(s); 105 assertFalse(plot1.equals(plot2)); 106 plot2.setSeparatorStroke(s); 107 assertTrue(plot1.equals(plot2)); 108 109 plot1.setSeparatorPaint(new GradientPaint (1.0f, 2.0f, Color.red, 111 2.0f, 1.0f, Color.blue)); 112 assertFalse(plot1.equals(plot2)); 113 plot2.setSeparatorPaint(new GradientPaint (1.0f, 2.0f, Color.red, 114 2.0f, 1.0f, Color.blue)); 115 assertTrue(plot1.equals(plot2)); 116 117 plot1.setInnerSeparatorExtension(0.01); 119 assertFalse(plot1.equals(plot2)); 120 plot2.setInnerSeparatorExtension(0.01); 121 assertTrue(plot1.equals(plot2)); 122 123 plot1.setOuterSeparatorExtension(0.02); 125 assertFalse(plot1.equals(plot2)); 126 plot2.setOuterSeparatorExtension(0.02); 127 assertTrue(plot1.equals(plot2)); 128 129 plot1.setSectionDepth(0.12); 131 assertFalse(plot1.equals(plot2)); 132 plot2.setSectionDepth(0.12); 133 assertTrue(plot1.equals(plot2)); 134 135 } 136 137 140 public void testCloning() { 141 RingPlot p1 = new RingPlot(null); 142 GradientPaint gp = new GradientPaint (1.0f, 2.0f, Color.yellow, 143 3.0f, 4.0f, Color.red); 144 p1.setSeparatorPaint(gp); 145 RingPlot p2 = null; 146 try { 147 p2 = (RingPlot) p1.clone(); 148 } 149 catch (CloneNotSupportedException e) { 150 e.printStackTrace(); 151 } 152 assertTrue(p1 != p2); 153 assertTrue(p1.getClass() == p2.getClass()); 154 assertTrue(p1.equals(p2)); 155 } 156 157 160 public void testSerialization() { 161 162 RingPlot p1 = new RingPlot(null); 163 GradientPaint gp = new GradientPaint (1.0f, 2.0f, Color.yellow, 164 3.0f, 4.0f, Color.red); 165 p1.setSeparatorPaint(gp); 166 RingPlot p2 = null; 167 try { 168 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 169 ObjectOutput out = new ObjectOutputStream (buffer); 170 out.writeObject(p1); 171 out.close(); 172 173 ObjectInput in = new ObjectInputStream ( 174 new ByteArrayInputStream (buffer.toByteArray())); 175 p2 = (RingPlot) in.readObject(); 176 in.close(); 177 } 178 catch (Exception e) { 179 e.printStackTrace(); 180 } 181 assertEquals(p1, p2); 182 } 183 184 } 185 | Popular Tags |