1 42 43 package org.jfree.chart.junit; 44 45 import java.util.EventListener ; 46 47 import javax.swing.event.CaretListener ; 48 49 import junit.framework.Test; 50 import junit.framework.TestCase; 51 import junit.framework.TestSuite; 52 53 import org.jfree.chart.ChartMouseEvent; 54 import org.jfree.chart.ChartMouseListener; 55 import org.jfree.chart.ChartPanel; 56 import org.jfree.chart.JFreeChart; 57 import org.jfree.chart.plot.XYPlot; 58 59 62 public class ChartPanelTests extends TestCase implements ChartMouseListener { 63 64 69 public static Test suite() { 70 return new TestSuite(ChartPanelTests.class); 71 } 72 73 78 public ChartPanelTests(String name) { 79 super(name); 80 } 81 82 85 public void testConstructor1() { 86 ChartPanel panel = new ChartPanel(null); 87 assertEquals(null, panel.getChart()); 88 } 89 90 93 public void testSetChart() { 94 JFreeChart chart = new JFreeChart(new XYPlot()); 95 ChartPanel panel = new ChartPanel(chart); 96 panel.setChart(null); 97 assertEquals(null, panel.getChart()); 98 } 99 100 103 public void testGetListeners() { 104 ChartPanel p = new ChartPanel(null); 105 p.addChartMouseListener(this); 106 EventListener [] listeners = p.getListeners( 107 (Class ) ChartMouseListener.class); 108 assertEquals(1, listeners.length); 109 assertEquals(this, listeners[0]); 110 listeners = p.getListeners((Class ) CaretListener .class); 112 assertEquals(0, listeners.length); 113 p.removeChartMouseListener(this); 114 listeners = p.getListeners((Class ) ChartMouseListener.class); 115 assertEquals(0, listeners.length); 116 117 boolean pass = false; 119 try { 120 listeners = p.getListeners((Class ) null); 121 } 122 catch (NullPointerException e) { 123 pass = true; 124 } 125 assertTrue(pass); 126 127 pass = false; 129 try { 130 listeners = p.getListeners(Integer .class); 131 } 132 catch (ClassCastException e) { 133 pass = true; 134 } 135 assertTrue(pass); 136 } 137 138 public void chartMouseClicked(ChartMouseEvent event) { 139 } 141 142 public void chartMouseMoved(ChartMouseEvent event) { 143 } 145 146 } 147 | Popular Tags |