1 42 43 package org.jfree.chart.junit; 44 45 import java.awt.Graphics2D ; 46 import java.awt.geom.Rectangle2D ; 47 import java.awt.image.BufferedImage ; 48 49 import junit.framework.Test; 50 import junit.framework.TestCase; 51 import junit.framework.TestSuite; 52 53 import org.jfree.chart.ChartFactory; 54 import org.jfree.chart.JFreeChart; 55 import org.jfree.chart.labels.CategoryToolTipGenerator; 56 import org.jfree.chart.labels.StandardCategoryToolTipGenerator; 57 import org.jfree.chart.plot.CategoryPlot; 58 import org.jfree.chart.plot.PlotOrientation; 59 import org.jfree.chart.renderer.category.CategoryItemRenderer; 60 import org.jfree.chart.urls.CategoryURLGenerator; 61 import org.jfree.chart.urls.StandardCategoryURLGenerator; 62 import org.jfree.data.category.CategoryDataset; 63 import org.jfree.data.general.DatasetUtilities; 64 65 68 public class WaterfallChartTests extends TestCase { 69 70 71 private JFreeChart chart; 72 73 78 public static Test suite() { 79 return new TestSuite(WaterfallChartTests.class); 80 } 81 82 87 public WaterfallChartTests(String name) { 88 super(name); 89 } 90 91 94 protected void setUp() { 95 this.chart = createWaterfallChart(); 96 } 97 98 102 public void testDrawWithNullInfo() { 103 104 boolean success = false; 105 106 try { 107 BufferedImage image = new BufferedImage (200 , 100, 108 BufferedImage.TYPE_INT_RGB); 109 Graphics2D g2 = image.createGraphics(); 110 this.chart.draw(g2, new Rectangle2D.Double (0, 0, 200, 100), null, 111 null); 112 g2.dispose(); 113 success = true; 114 } 115 catch (Exception e) { 116 success = false; 117 } 118 119 assertTrue(success); 120 121 } 122 123 127 public void testSetSeriesToolTipGenerator() { 128 CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); 129 CategoryItemRenderer renderer = plot.getRenderer(); 130 StandardCategoryToolTipGenerator tt 131 = new StandardCategoryToolTipGenerator(); 132 renderer.setSeriesToolTipGenerator(0, tt); 133 CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); 134 assertTrue(tt2 == tt); 135 } 136 137 141 public void testSetSeriesURLGenerator() { 142 CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); 143 CategoryItemRenderer renderer = plot.getRenderer(); 144 StandardCategoryURLGenerator url1 145 = new StandardCategoryURLGenerator(); 146 renderer.setSeriesItemURLGenerator(0, url1); 147 CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0); 148 assertTrue(url2 == url1); 149 } 150 151 156 private static JFreeChart createWaterfallChart() { 157 158 Number [][] data = new Integer [][] 160 {{new Integer (-3), new Integer (-2)}, 161 {new Integer (-1), new Integer (1)}, 162 {new Integer (2), new Integer (3)}}; 163 164 CategoryDataset dataset 165 = DatasetUtilities.createCategoryDataset("S", "C", data); 166 167 return ChartFactory.createWaterfallChart( 169 "Waterfall Chart", 170 "Domain", "Range", 171 dataset, 172 PlotOrientation.HORIZONTAL, 173 true, true, 175 true 176 ); 177 178 } 179 180 } 181 | Popular Tags |