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