1 43 44 package org.jfree.chart.plot.junit; 45 46 import java.awt.Color ; 47 import java.awt.GradientPaint ; 48 import java.io.ByteArrayInputStream ; 49 import java.io.ByteArrayOutputStream ; 50 import java.io.ObjectInput ; 51 import java.io.ObjectInputStream ; 52 import java.io.ObjectOutput ; 53 import java.io.ObjectOutputStream ; 54 55 import junit.framework.Test; 56 import junit.framework.TestCase; 57 import junit.framework.TestSuite; 58 59 import org.jfree.chart.ChartFactory; 60 import org.jfree.chart.plot.MultiplePiePlot; 61 import org.jfree.util.TableOrder; 62 63 66 public class MultiplePiePlotTests extends TestCase { 67 68 73 public static Test suite() { 74 return new TestSuite(MultiplePiePlotTests.class); 75 } 76 77 82 public MultiplePiePlotTests(String name) { 83 super(name); 84 } 85 86 89 public void testEquals() { 90 MultiplePiePlot p1 = new MultiplePiePlot(); 91 MultiplePiePlot p2 = new MultiplePiePlot(); 92 assertTrue(p1.equals(p2)); 93 assertTrue(p2.equals(p1)); 94 95 p1.setDataExtractOrder(TableOrder.BY_ROW); 96 assertFalse(p1.equals(p2)); 97 p2.setDataExtractOrder(TableOrder.BY_ROW); 98 assertTrue(p1.equals(p2)); 99 100 p1.setLimit(1.23); 101 assertFalse(p1.equals(p2)); 102 p2.setLimit(1.23); 103 assertTrue(p1.equals(p2)); 104 105 p1.setAggregatedItemsKey("Aggregated Items"); 106 assertFalse(p1.equals(p2)); 107 p2.setAggregatedItemsKey("Aggregated Items"); 108 assertTrue(p1.equals(p2)); 109 110 p1.setAggregatedItemsPaint(new GradientPaint (1.0f, 2.0f, Color.red, 111 3.0f, 4.0f, Color.yellow)); 112 assertFalse(p1.equals(p2)); 113 p2.setAggregatedItemsPaint(new GradientPaint (1.0f, 2.0f, Color.red, 114 3.0f, 4.0f, Color.yellow)); 115 assertTrue(p1.equals(p2)); 116 117 p1.setPieChart(ChartFactory.createPieChart("Title", null, true, true, 118 true)); 119 assertFalse(p1.equals(p2)); 120 p2.setPieChart(ChartFactory.createPieChart("Title", null, true, true, 121 true)); 122 assertTrue(p1.equals(p2)); 123 } 124 125 128 public void testCloning() { 129 MultiplePiePlot p1 = new MultiplePiePlot(); 130 MultiplePiePlot p2 = null; 131 try { 132 p2 = (MultiplePiePlot) p1.clone(); 133 } 134 catch (CloneNotSupportedException e) { 135 e.printStackTrace(); 136 System.err.println("Failed to clone."); 137 } 138 assertTrue(p1 != p2); 139 assertTrue(p1.getClass() == p2.getClass()); 140 assertTrue(p1.equals(p2)); 141 } 142 143 146 public void testSerialization() { 147 MultiplePiePlot p1 = new MultiplePiePlot(null); 148 p1.setAggregatedItemsPaint(new GradientPaint (1.0f, 2.0f, Color.yellow, 149 3.0f, 4.0f, Color.red)); 150 MultiplePiePlot p2 = null; 151 try { 152 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 153 ObjectOutput out = new ObjectOutputStream (buffer); 154 out.writeObject(p1); 155 out.close(); 156 157 ObjectInput in = new ObjectInputStream ( 158 new ByteArrayInputStream (buffer.toByteArray()) 159 ); 160 p2 = (MultiplePiePlot) in.readObject(); 161 in.close(); 162 } 163 catch (Exception e) { 164 e.printStackTrace(); 165 } 166 assertEquals(p1, p2); 167 } 168 169 } 170 | Popular Tags |