1 42 43 package org.jfree.chart.renderer.category.junit; 44 45 import java.io.ByteArrayInputStream ; 46 import java.io.ByteArrayOutputStream ; 47 import java.io.ObjectInput ; 48 import java.io.ObjectInputStream ; 49 import java.io.ObjectOutput ; 50 import java.io.ObjectOutputStream ; 51 52 import junit.framework.Test; 53 import junit.framework.TestCase; 54 import junit.framework.TestSuite; 55 56 import org.jfree.chart.JFreeChart; 57 import org.jfree.chart.axis.CategoryAxis; 58 import org.jfree.chart.axis.NumberAxis; 59 import org.jfree.chart.plot.CategoryPlot; 60 import org.jfree.chart.renderer.category.GroupedStackedBarRenderer; 61 import org.jfree.data.KeyToGroupMap; 62 import org.jfree.data.category.DefaultCategoryDataset; 63 64 67 public class GroupedStackedBarRendererTests extends TestCase { 68 69 74 public static Test suite() { 75 return new TestSuite(GroupedStackedBarRendererTests.class); 76 } 77 78 83 public GroupedStackedBarRendererTests(String name) { 84 super(name); 85 } 86 87 90 public void testEquals() { 91 GroupedStackedBarRenderer r1 = new GroupedStackedBarRenderer(); 92 GroupedStackedBarRenderer r2 = new GroupedStackedBarRenderer(); 93 assertTrue(r1.equals(r2)); 94 assertTrue(r2.equals(r1)); 95 96 KeyToGroupMap m1 = new KeyToGroupMap("G1"); 98 m1.mapKeyToGroup("S1", "G2"); 99 r1.setSeriesToGroupMap(m1); 100 assertFalse(r1.equals(r2)); 101 KeyToGroupMap m2 = new KeyToGroupMap("G1"); 102 m2.mapKeyToGroup("S1", "G2"); 103 r2.setSeriesToGroupMap(m2); 104 assertTrue(r1.equals(r2)); 105 } 106 107 110 public void testCloning() { 111 GroupedStackedBarRenderer r1 = new GroupedStackedBarRenderer(); 112 GroupedStackedBarRenderer r2 = null; 113 try { 114 r2 = (GroupedStackedBarRenderer) r1.clone(); 115 } 116 catch (CloneNotSupportedException e) { 117 System.err.println("Failed to clone."); 118 } 119 assertTrue(r1 != r2); 120 assertTrue(r1.getClass() == r2.getClass()); 121 assertTrue(r1.equals(r2)); 122 } 123 124 127 public void testSerialization() { 128 129 GroupedStackedBarRenderer r1 = new GroupedStackedBarRenderer(); 130 GroupedStackedBarRenderer r2 = null; 131 try { 132 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 133 ObjectOutput out = new ObjectOutputStream (buffer); 134 out.writeObject(r1); 135 out.close(); 136 137 ObjectInput in = new ObjectInputStream ( 138 new ByteArrayInputStream (buffer.toByteArray()) 139 ); 140 r2 = (GroupedStackedBarRenderer) in.readObject(); 141 in.close(); 142 } 143 catch (Exception e) { 144 System.out.println(e.toString()); 145 } 146 assertEquals(r1, r2); 147 148 } 149 150 154 public void testDrawWithNullInfo() { 155 boolean success = false; 156 try { 157 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 158 dataset.addValue(1.0, "S1", "C1"); 159 dataset.addValue(2.0, "S1", "C2"); 160 dataset.addValue(3.0, "S2", "C1"); 161 dataset.addValue(4.0, "S2", "C2"); 162 GroupedStackedBarRenderer renderer 163 = new GroupedStackedBarRenderer(); 164 CategoryPlot plot = new CategoryPlot(dataset, 165 new CategoryAxis("Category"), new NumberAxis("Value"), 166 renderer); 167 JFreeChart chart = new JFreeChart(plot); 168 chart.createBufferedImage(300, 200, 169 null); 170 success = true; 171 } 172 catch (NullPointerException e) { 173 e.printStackTrace(); 174 success = false; 175 } 176 assertTrue(success); 177 } 178 179 } 180 | Popular Tags |