1 43 44 package org.jfree.chart.renderer.xy.junit; 45 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.ChartFactory; 58 import org.jfree.chart.JFreeChart; 59 import org.jfree.chart.axis.NumberAxis; 60 import org.jfree.chart.plot.PlotOrientation; 61 import org.jfree.chart.plot.XYPlot; 62 import org.jfree.chart.renderer.xy.StackedXYBarRenderer; 63 import org.jfree.data.Range; 64 import org.jfree.data.xy.TableXYDataset; 65 66 69 public class StackedXYBarRendererTests extends TestCase { 70 71 76 public static Test suite() { 77 return new TestSuite(StackedXYBarRendererTests.class); 78 } 79 80 85 public StackedXYBarRendererTests(String name) { 86 super(name); 87 } 88 89 92 public void testEquals() { 93 StackedXYBarRenderer r1 = new StackedXYBarRenderer(); 94 StackedXYBarRenderer r2 = new StackedXYBarRenderer(); 95 assertTrue(r1.equals(r2)); 96 assertTrue(r2.equals(r1)); 97 } 98 99 102 public void testHashcode() { 103 StackedXYBarRenderer r1 = new StackedXYBarRenderer(); 104 StackedXYBarRenderer r2 = new StackedXYBarRenderer(); 105 assertTrue(r1.equals(r2)); 106 int h1 = r1.hashCode(); 107 int h2 = r2.hashCode(); 108 assertEquals(h1, h2); 109 } 110 111 114 public void testCloning() { 115 StackedXYBarRenderer r1 = new StackedXYBarRenderer(); 116 StackedXYBarRenderer r2 = null; 117 try { 118 r2 = (StackedXYBarRenderer) r1.clone(); 119 } 120 catch (CloneNotSupportedException e) { 121 System.err.println("Failed to clone."); 122 } 123 assertTrue(r1 != r2); 124 assertTrue(r1.getClass() == r2.getClass()); 125 assertTrue(r1.equals(r2)); 126 } 127 128 131 public void testSerialization() { 132 StackedXYBarRenderer r1 = new StackedXYBarRenderer(); 133 StackedXYBarRenderer r2 = null; 134 try { 135 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 136 ObjectOutput out = new ObjectOutputStream (buffer); 137 out.writeObject(r1); 138 out.close(); 139 140 ObjectInput in = new ObjectInputStream ( 141 new ByteArrayInputStream (buffer.toByteArray()) 142 ); 143 r2 = (StackedXYBarRenderer) in.readObject(); 144 in.close(); 145 } 146 catch (Exception e) { 147 System.out.println(e.toString()); 148 } 149 assertEquals(r1, r2); 150 } 151 152 155 public void testFindDomainBounds() { 156 TableXYDataset dataset 157 = RendererXYPackageTests.createTestTableXYDataset(); 158 JFreeChart chart = ChartFactory.createStackedXYAreaChart( 159 "Test Chart", "X", "Y", dataset, 160 PlotOrientation.VERTICAL, false, false, false 161 ); 162 XYPlot plot = (XYPlot) chart.getPlot(); 163 plot.setRenderer(new StackedXYBarRenderer()); 164 NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); 165 domainAxis.setAutoRangeIncludesZero(false); 166 Range bounds = domainAxis.getRange(); 167 assertFalse(bounds.contains(0.3)); 168 assertTrue(bounds.contains(0.5)); 169 assertTrue(bounds.contains(2.5)); 170 assertFalse(bounds.contains(2.8)); 171 } 172 173 176 public void testFindRangeBounds() { 177 TableXYDataset dataset 178 = RendererXYPackageTests.createTestTableXYDataset(); 179 JFreeChart chart = ChartFactory.createStackedXYAreaChart( 180 "Test Chart", "X", "Y", dataset, 181 PlotOrientation.VERTICAL, false, false, false 182 ); 183 XYPlot plot = (XYPlot) chart.getPlot(); 184 plot.setRenderer(new StackedXYBarRenderer()); 185 NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); 186 Range bounds = rangeAxis.getRange(); 187 assertTrue(bounds.contains(6.0)); 188 assertTrue(bounds.contains(8.0)); 189 } 190 191 } 192 | Popular Tags |