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