KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > plot > junit > CategoryPlotTests


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * ----------------------
27  * CategoryPlotTests.java
28  * ----------------------
29  * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: CategoryPlotTests.java,v 1.8 2005/06/01 09:41:14 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 26-Mar-2003 : Version 1 (DG);
39  * 15-Sep-2003 : Added a unit test to reproduce a bug in serialization (now
40  * fixed) (DG);
41  *
42  */

43
44 package org.jfree.chart.plot.junit;
45
46 import java.awt.BasicStroke JavaDoc;
47 import java.awt.Color JavaDoc;
48 import java.awt.Stroke JavaDoc;
49 import java.io.ByteArrayInputStream JavaDoc;
50 import java.io.ByteArrayOutputStream JavaDoc;
51 import java.io.ObjectInput JavaDoc;
52 import java.io.ObjectInputStream JavaDoc;
53 import java.io.ObjectOutput JavaDoc;
54 import java.io.ObjectOutputStream JavaDoc;
55
56 import junit.framework.Test;
57 import junit.framework.TestCase;
58 import junit.framework.TestSuite;
59
60 import org.jfree.chart.ChartFactory;
61 import org.jfree.chart.JFreeChart;
62 import org.jfree.chart.annotations.CategoryTextAnnotation;
63 import org.jfree.chart.axis.AxisLocation;
64 import org.jfree.chart.axis.AxisSpace;
65 import org.jfree.chart.axis.CategoryAnchor;
66 import org.jfree.chart.axis.CategoryAxis;
67 import org.jfree.chart.axis.NumberAxis;
68 import org.jfree.chart.plot.CategoryPlot;
69 import org.jfree.chart.plot.DatasetRenderingOrder;
70 import org.jfree.chart.plot.IntervalMarker;
71 import org.jfree.chart.plot.PlotOrientation;
72 import org.jfree.chart.plot.ValueMarker;
73 import org.jfree.chart.renderer.category.AreaRenderer;
74 import org.jfree.chart.renderer.category.BarRenderer;
75 import org.jfree.chart.renderer.category.CategoryItemRenderer;
76 import org.jfree.chart.renderer.category.LineAndShapeRenderer;
77 import org.jfree.data.Range;
78 import org.jfree.data.category.DefaultCategoryDataset;
79 import org.jfree.ui.Layer;
80 import org.jfree.ui.RectangleInsets;
81 import org.jfree.util.SortOrder;
82
83 /**
84  * Tests for the {@link CategoryPlot} class.
85  */

86 public class CategoryPlotTests extends TestCase {
87
88     /**
89      * Returns the tests as a test suite.
90      *
91      * @return The test suite.
92      */

93     public static Test suite() {
94         return new TestSuite(CategoryPlotTests.class);
95     }
96
97     /**
98      * Constructs a new set of tests.
99      *
100      * @param name the name of the tests.
101      */

102     public CategoryPlotTests(String JavaDoc name) {
103         super(name);
104     }
105
106     /**
107      * A test for a bug reported in the forum.
108      */

109     public void testAxisRange() {
110         DefaultCategoryDataset datasetA = new DefaultCategoryDataset();
111         DefaultCategoryDataset datasetB = new DefaultCategoryDataset();
112         datasetB.addValue(50.0, "R1", "C1");
113         datasetB.addValue(80.0, "R1", "C1");
114         CategoryPlot plot = new CategoryPlot(
115             datasetA, new CategoryAxis(null), new NumberAxis(null),
116             new LineAndShapeRenderer()
117         );
118         plot.setDataset(1, datasetB);
119         plot.setRenderer(1, new LineAndShapeRenderer());
120         Range r = plot.getRangeAxis().getRange();
121         assertEquals(84.0, r.getUpperBound(), 0.00001);
122     }
123     
124     /**
125      * Test that the equals() method differentiates all the required fields.
126      */

127     public void testEquals() {
128         
129         CategoryPlot plot1 = new CategoryPlot();
130         CategoryPlot plot2 = new CategoryPlot();
131         assertTrue(plot1.equals(plot2));
132         assertTrue(plot2.equals(plot1));
133         
134         // orientation...
135
plot1.setOrientation(PlotOrientation.HORIZONTAL);
136         assertFalse(plot1.equals(plot2));
137         plot2.setOrientation(PlotOrientation.HORIZONTAL);
138         assertTrue(plot1.equals(plot2));
139         
140         // axisOffset...
141
plot1.setAxisOffset(new RectangleInsets(0.05, 0.05, 0.05, 0.05));
142         assertFalse(plot1.equals(plot2));
143         plot2.setAxisOffset(new RectangleInsets(0.05, 0.05, 0.05, 0.05));
144         assertTrue(plot1.equals(plot2));
145
146         // domainAxis - no longer a separate field but test anyway...
147
plot1.setDomainAxis(new CategoryAxis("Category Axis"));
148         assertFalse(plot1.equals(plot2));
149         plot2.setDomainAxis(new CategoryAxis("Category Axis"));
150         assertTrue(plot1.equals(plot2));
151
152         // domainAxes...
153
plot1.setDomainAxis(11, new CategoryAxis("Secondary Axis"));
154         assertFalse(plot1.equals(plot2));
155         plot2.setDomainAxis(11, new CategoryAxis("Secondary Axis"));
156         assertTrue(plot1.equals(plot2));
157
158         // domainAxisLocation - no longer a separate field but test anyway...
159
plot1.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
160         assertFalse(plot1.equals(plot2));
161         plot2.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
162         assertTrue(plot1.equals(plot2));
163
164         // domainAxisLocations...
165
plot1.setDomainAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
166         assertFalse(plot1.equals(plot2));
167         plot2.setDomainAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
168         assertTrue(plot1.equals(plot2));
169
170         // draw shared domain axis...
171
plot1.setDrawSharedDomainAxis(!plot1.getDrawSharedDomainAxis());
172         assertFalse(plot1.equals(plot2));
173         plot2.setDrawSharedDomainAxis(!plot2.getDrawSharedDomainAxis());
174         assertTrue(plot1.equals(plot2));
175         
176         // rangeAxis - no longer a separate field but test anyway...
177
plot1.setRangeAxis(new NumberAxis("Range Axis"));
178         assertFalse(plot1.equals(plot2));
179         plot2.setRangeAxis(new NumberAxis("Range Axis"));
180         assertTrue(plot1.equals(plot2));
181
182         // rangeAxes...
183
plot1.setRangeAxis(11, new NumberAxis("Secondary Range Axis"));
184         assertFalse(plot1.equals(plot2));
185         plot2.setRangeAxis(11, new NumberAxis("Secondary Range Axis"));
186         assertTrue(plot1.equals(plot2));
187
188         // rangeAxisLocation - no longer a separate field but test anyway...
189
plot1.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
190         assertFalse(plot1.equals(plot2));
191         plot2.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
192         assertTrue(plot1.equals(plot2));
193
194         // rangeAxisLocations...
195
plot1.setRangeAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
196         assertFalse(plot1.equals(plot2));
197         plot2.setRangeAxisLocation(11, AxisLocation.TOP_OR_RIGHT);
198         assertTrue(plot1.equals(plot2));
199         
200         // datasetToDomainAxisMap...
201
plot1.mapDatasetToDomainAxis(11, 11);
202         assertFalse(plot1.equals(plot2));
203         plot2.mapDatasetToDomainAxis(11, 11);
204         assertTrue(plot1.equals(plot2));
205
206         // datasetToRangeAxisMap...
207
plot1.mapDatasetToRangeAxis(11, 11);
208         assertFalse(plot1.equals(plot2));
209         plot2.mapDatasetToRangeAxis(11, 11);
210         assertTrue(plot1.equals(plot2));
211         
212         // renderer - no longer a separate field but test anyway...
213
plot1.setRenderer(new AreaRenderer());
214         assertFalse(plot1.equals(plot2));
215         plot2.setRenderer(new AreaRenderer());
216         assertTrue(plot1.equals(plot2));
217         
218         // renderers...
219
plot1.setRenderer(11, new AreaRenderer());
220         assertFalse(plot1.equals(plot2));
221         plot2.setRenderer(11, new AreaRenderer());
222         assertTrue(plot1.equals(plot2));
223         
224         // rendering order...
225
plot1.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
226         assertFalse(plot1.equals(plot2));
227         plot2.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
228         assertTrue(plot1.equals(plot2));
229
230         // columnRenderingOrder...
231
plot1.setColumnRenderingOrder(SortOrder.DESCENDING);
232         assertFalse(plot1.equals(plot2));
233         plot2.setColumnRenderingOrder(SortOrder.DESCENDING);
234         assertTrue(plot1.equals(plot2));
235         
236         // rowRenderingOrder...
237
plot1.setRowRenderingOrder(SortOrder.DESCENDING);
238         assertFalse(plot1.equals(plot2));
239         plot2.setRowRenderingOrder(SortOrder.DESCENDING);
240         assertTrue(plot1.equals(plot2));
241         
242         // domainGridlinesVisible
243
plot1.setDomainGridlinesVisible(true);
244         assertFalse(plot1.equals(plot2));
245         plot2.setDomainGridlinesVisible(true);
246         assertTrue(plot1.equals(plot2));
247
248         // domainGridlinePosition
249
plot1.setDomainGridlinePosition(CategoryAnchor.END);
250         assertFalse(plot1.equals(plot2));
251         plot2.setDomainGridlinePosition(CategoryAnchor.END);
252         assertTrue(plot1.equals(plot2));
253
254         // domainGridlineStroke
255
Stroke JavaDoc stroke = new BasicStroke JavaDoc(2.0f);
256         plot1.setDomainGridlineStroke(stroke);
257         assertFalse(plot1.equals(plot2));
258         plot2.setDomainGridlineStroke(stroke);
259         assertTrue(plot1.equals(plot2));
260         
261         // domainGridlinePaint
262
plot1.setDomainGridlinePaint(Color.blue);
263         assertFalse(plot1.equals(plot2));
264         plot2.setDomainGridlinePaint(Color.blue);
265         assertTrue(plot1.equals(plot2));
266         
267         // rangeGridlinesVisible
268
plot1.setRangeGridlinesVisible(false);
269         assertFalse(plot1.equals(plot2));
270         plot2.setRangeGridlinesVisible(false);
271         assertTrue(plot1.equals(plot2));
272
273         // rangeGridlineStroke
274
plot1.setRangeGridlineStroke(stroke);
275         assertFalse(plot1.equals(plot2));
276         plot2.setRangeGridlineStroke(stroke);
277         assertTrue(plot1.equals(plot2));
278         
279         // rangeGridlinePaint
280
plot1.setRangeGridlinePaint(Color.blue);
281         assertFalse(plot1.equals(plot2));
282         plot2.setRangeGridlinePaint(Color.blue);
283         assertTrue(plot1.equals(plot2));
284         
285         // anchorValue
286
plot1.setAnchorValue(100.0);
287         assertFalse(plot1.equals(plot2));
288         plot2.setAnchorValue(100.0);
289         assertTrue(plot1.equals(plot2));
290         
291         // rangeCrosshairVisible
292
plot1.setRangeCrosshairVisible(true);
293         assertFalse(plot1.equals(plot2));
294         plot2.setRangeCrosshairVisible(true);
295         assertTrue(plot1.equals(plot2));
296         
297         // rangeCrosshairValue
298
plot1.setRangeCrosshairValue(100.0);
299         assertFalse(plot1.equals(plot2));
300         plot2.setRangeCrosshairValue(100.0);
301         assertTrue(plot1.equals(plot2));
302         
303         // rangeCrosshairStroke
304
plot1.setRangeCrosshairStroke(stroke);
305         assertFalse(plot1.equals(plot2));
306         plot2.setRangeCrosshairStroke(stroke);
307         assertTrue(plot1.equals(plot2));
308         
309         // rangeCrosshairPaint
310
plot1.setRangeCrosshairPaint(Color.blue);
311         assertFalse(plot1.equals(plot2));
312         plot2.setRangeCrosshairPaint(Color.blue);
313         assertTrue(plot1.equals(plot2));
314         
315         // rangeCrosshairLockedOnData
316
plot1.setRangeCrosshairLockedOnData(false);
317         assertFalse(plot1.equals(plot2));
318         plot2.setRangeCrosshairLockedOnData(false);
319         assertTrue(plot1.equals(plot2));
320         
321         // range markers - no longer separate fields but test anyway...
322
plot1.addRangeMarker(new ValueMarker(4.0), Layer.FOREGROUND);
323         assertFalse(plot1.equals(plot2));
324         plot2.addRangeMarker(new ValueMarker(4.0), Layer.FOREGROUND);
325         assertTrue(plot1.equals(plot2));
326         
327         plot1.addRangeMarker(new ValueMarker(5.0), Layer.BACKGROUND);
328         assertFalse(plot1.equals(plot2));
329         plot2.addRangeMarker(new ValueMarker(5.0), Layer.BACKGROUND);
330         assertTrue(plot1.equals(plot2));
331         
332         // foreground range markers...
333
plot1.addRangeMarker(1, new ValueMarker(4.0), Layer.FOREGROUND);
334         assertFalse(plot1.equals(plot2));
335         plot2.addRangeMarker(1, new ValueMarker(4.0), Layer.FOREGROUND);
336         assertTrue(plot1.equals(plot2));
337         
338         // background range markers...
339
plot1.addRangeMarker(1, new ValueMarker(5.0), Layer.BACKGROUND);
340         assertFalse(plot1.equals(plot2));
341         plot2.addRangeMarker(1, new ValueMarker(5.0), Layer.BACKGROUND);
342         assertTrue(plot1.equals(plot2));
343
344         // annotations
345
plot1.addAnnotation(
346             new CategoryTextAnnotation("Text", "Category", 43.0)
347         );
348         assertFalse(plot1.equals(plot2));
349         plot2.addAnnotation(
350             new CategoryTextAnnotation("Text", "Category", 43.0)
351         );
352         assertTrue(plot1.equals(plot2));
353         
354         // weight
355
plot1.setWeight(3);
356         assertFalse(plot1.equals(plot2));
357         plot2.setWeight(3);
358         assertTrue(plot1.equals(plot2));
359         
360         // fixed domain axis space...
361
plot1.setFixedDomainAxisSpace(new AxisSpace());
362         assertFalse(plot1.equals(plot2));
363         plot2.setFixedDomainAxisSpace(new AxisSpace());
364         assertTrue(plot1.equals(plot2));
365         
366         // fixed range axis space...
367
plot1.setFixedRangeAxisSpace(new AxisSpace());
368         assertFalse(plot1.equals(plot2));
369         plot2.setFixedRangeAxisSpace(new AxisSpace());
370         assertTrue(plot1.equals(plot2));
371         
372         
373     }
374
375     /**
376      * Confirm that cloning works.
377      */

378     public void testCloning() {
379         CategoryPlot p1 = new CategoryPlot();
380         CategoryPlot p2 = null;
381         try {
382             p2 = (CategoryPlot) p1.clone();
383         }
384         catch (CloneNotSupportedException JavaDoc e) {
385             e.printStackTrace();
386             System.err.println("Failed to clone.");
387         }
388         assertTrue(p1 != p2);
389         assertTrue(p1.getClass() == p2.getClass());
390         assertTrue(p1.equals(p2));
391     }
392
393     /**
394      * Serialize an instance, restore it, and check for equality.
395      */

396     public void testSerialization() {
397
398         DefaultCategoryDataset dataset = new DefaultCategoryDataset();
399         CategoryAxis domainAxis = new CategoryAxis("Domain");
400         NumberAxis rangeAxis = new NumberAxis("Range");
401         BarRenderer renderer = new BarRenderer();
402         CategoryPlot p1 = new CategoryPlot(
403             dataset, domainAxis, rangeAxis, renderer
404         );
405         p1.setOrientation(PlotOrientation.HORIZONTAL);
406         CategoryPlot p2 = null;
407         try {
408             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
409             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
410             out.writeObject(p1);
411             out.close();
412
413             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
414                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
415             );
416             p2 = (CategoryPlot) in.readObject();
417             in.close();
418         }
419         catch (Exception JavaDoc e) {
420             e.printStackTrace();
421         }
422         assertTrue(p1.equals(p2));
423     }
424
425     /**
426      * Serialize an instance, restore it, and check for equality.
427      */

428     public void testSerialization2() {
429
430         DefaultCategoryDataset data = new DefaultCategoryDataset();
431         CategoryAxis domainAxis = new CategoryAxis("Domain");
432         NumberAxis rangeAxis = new NumberAxis("Range");
433         BarRenderer renderer = new BarRenderer();
434         CategoryPlot p1 = new CategoryPlot(
435             data, domainAxis, rangeAxis, renderer
436         );
437         p1.setOrientation(PlotOrientation.VERTICAL);
438         CategoryPlot p2 = null;
439
440         try {
441             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
442             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
443             out.writeObject(p1);
444             out.close();
445
446             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
447                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
448             );
449             p2 = (CategoryPlot) in.readObject();
450             in.close();
451         }
452         catch (Exception JavaDoc e) {
453             fail(e.toString());
454         }
455         assertEquals(p1, p2);
456
457     }
458
459     /**
460      * Serialize an instance, restore it, and check for equality.
461      */

462     public void testSerialization3() {
463         DefaultCategoryDataset dataset = new DefaultCategoryDataset();
464         JFreeChart chart = ChartFactory.createBarChart(
465             "Test Chart",
466             "Category Axis",
467             "Value Axis",
468             dataset,
469             PlotOrientation.VERTICAL,
470             true,
471             true,
472             false
473         );
474         JFreeChart chart2 = null;
475         
476         // serialize and deserialize the chart....
477
try {
478             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
479             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
480             out.writeObject(chart);
481             out.close();
482
483             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
484                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
485             );
486             chart2 = (JFreeChart) in.readObject();
487             in.close();
488         }
489         catch (Exception JavaDoc e) {
490             fail(e.toString());
491         }
492
493         // now check that the chart is usable...
494
boolean passed = true;
495         try {
496             chart2.createBufferedImage(300, 200);
497         }
498         catch (Exception JavaDoc e) {
499             passed = false;
500             e.printStackTrace();
501         }
502         assertTrue(passed);
503     }
504     
505     /**
506      * This test ensures that a plot with markers is serialized correctly.
507      */

508     public void testSerialization4() {
509         DefaultCategoryDataset dataset = new DefaultCategoryDataset();
510         JFreeChart chart = ChartFactory.createBarChart(
511             "Test Chart",
512             "Category Axis",
513             "Value Axis",
514             dataset,
515             PlotOrientation.VERTICAL,
516             true,
517             true,
518             false
519         );
520         CategoryPlot plot = (CategoryPlot) chart.getPlot();
521         plot.addRangeMarker(new ValueMarker(1.1), Layer.FOREGROUND);
522         plot.addRangeMarker(new IntervalMarker(2.2, 3.3), Layer.BACKGROUND);
523         JFreeChart chart2 = null;
524         
525         // serialize and deserialize the chart....
526
try {
527             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
528             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
529             out.writeObject(chart);
530             out.close();
531
532             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
533                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
534             );
535             chart2 = (JFreeChart) in.readObject();
536             in.close();
537         }
538         catch (Exception JavaDoc e) {
539             fail(e.toString());
540         }
541         assertEquals(chart, chart2);
542         
543         // now check that the chart is usable...
544
boolean passed = true;
545         try {
546             chart2.createBufferedImage(300, 200);
547         }
548         catch (Exception JavaDoc e) {
549             passed = false;
550             e.printStackTrace();
551         }
552         assertTrue(passed);
553     }
554     
555     /**
556      * Tests a bug where the plot is no longer registered as a listener
557      * with the dataset(s) and axes after deserialization. See patch 1209475
558      * at SourceForge.
559      */

560     public void testSerialization5() {
561         DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
562         CategoryAxis domainAxis1 = new CategoryAxis("Domain 1");
563         NumberAxis rangeAxis1 = new NumberAxis("Range 1");
564         BarRenderer renderer1 = new BarRenderer();
565         CategoryPlot p1 = new CategoryPlot(dataset1, domainAxis1, rangeAxis1,
566                 renderer1);
567         CategoryAxis domainAxis2 = new CategoryAxis("Domain 2");
568         NumberAxis rangeAxis2 = new NumberAxis("Range 2");
569         BarRenderer renderer2 = new BarRenderer();
570         DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
571         p1.setDataset(1, dataset2);
572         p1.setDomainAxis(1, domainAxis2);
573         p1.setRangeAxis(1, rangeAxis2);
574         p1.setRenderer(1, renderer2);
575         CategoryPlot p2 = null;
576         try {
577             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
578             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
579             out.writeObject(p1);
580             out.close();
581             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
582                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
583             );
584             p2 = (CategoryPlot) in.readObject();
585             in.close();
586         }
587         catch (Exception JavaDoc e) {
588             fail(e.toString());
589         }
590         assertEquals(p1, p2);
591         
592         // now check that all datasets, renderers and axes are being listened
593
// too...
594
CategoryAxis domainAxisA = p2.getDomainAxis(0);
595         NumberAxis rangeAxisA = (NumberAxis) p2.getRangeAxis(0);
596         DefaultCategoryDataset datasetA
597             = (DefaultCategoryDataset) p2.getDataset(0);
598         BarRenderer rendererA = (BarRenderer) p2.getRenderer(0);
599         CategoryAxis domainAxisB = p2.getDomainAxis(1);
600         NumberAxis rangeAxisB = (NumberAxis) p2.getRangeAxis(1);
601         DefaultCategoryDataset datasetB
602             = (DefaultCategoryDataset) p2.getDataset(1);
603         BarRenderer rendererB = (BarRenderer) p2.getRenderer(1);
604         assertTrue(datasetA.hasListener(p2));
605         assertTrue(domainAxisA.hasListener(p2));
606         assertTrue(rangeAxisA.hasListener(p2));
607         assertTrue(rendererA.hasListener(p2));
608         assertTrue(datasetB.hasListener(p2));
609         assertTrue(domainAxisB.hasListener(p2));
610         assertTrue(rangeAxisB.hasListener(p2));
611         assertTrue(rendererB.hasListener(p2));
612     }
613
614     /**
615      * A test for a bug where setting the renderer doesn't register the plot
616      * as a RendererChangeListener.
617      */

618     public void testSetRenderer() {
619         CategoryPlot plot = new CategoryPlot();
620         CategoryItemRenderer renderer = new LineAndShapeRenderer();
621         plot.setRenderer(renderer);
622         // now make a change to the renderer and see if it triggers a plot
623
// change event...
624
MyPlotChangeListener listener = new MyPlotChangeListener();
625         plot.addChangeListener(listener);
626         renderer.setSeriesPaint(0, Color.black);
627         assertTrue(listener.getEvent() != null);
628     }
629     
630     /**
631      * A test for bug report 1169972.
632      */

633     public void test1169972() {
634         CategoryPlot plot = new CategoryPlot(null, null, null, null);
635         plot.setDomainAxis(new CategoryAxis("C"));
636         plot.setRangeAxis(new NumberAxis("Y"));
637         plot.setRenderer(new BarRenderer());
638         plot.setDataset(new DefaultCategoryDataset());
639         assertTrue(plot != null);
640     }
641
642 }
643
Popular Tags