Source Code Cross Referenced for PiePlotTests.java in  » Chart » jfreechart » org » jfree » chart » plot » junit » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Chart » jfreechart » org.jfree.chart.plot.junit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ===========================================================
002:         * JFreeChart : a free chart library for the Java(tm) platform
003:         * ===========================================================
004:         *
005:         * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006:         *
007:         * Project Info:  http://www.jfree.org/jfreechart/index.html
008:         *
009:         * This library is free software; you can redistribute it and/or modify it 
010:         * under the terms of the GNU Lesser General Public License as published by 
011:         * the Free Software Foundation; either version 2.1 of the License, or 
012:         * (at your option) any later version.
013:         *
014:         * This library is distributed in the hope that it will be useful, but 
015:         * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017:         * License for more details.
018:         *
019:         * You should have received a copy of the GNU Lesser General Public
020:         * License along with this library; if not, write to the Free Software
021:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022:         * USA.  
023:         *
024:         * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025:         * in the United States and other countries.]
026:         *
027:         * -----------------
028:         * PiePlotTests.java
029:         * -----------------
030:         * (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
031:         *
032:         * Original Author:  David Gilbert (for Object Refinery Limited);
033:         * Contributor(s):   -;
034:         *
035:         * $Id: PiePlotTests.java,v 1.1.2.4 2007/04/17 09:09:22 mungady Exp $
036:         *
037:         * Changes
038:         * -------
039:         * 18-Mar-2003 : Version 1 (DG);
040:         * 10-May-2005 : Strengthened equals() test (DG);
041:         * 27-Sep-2006 : Added tests for the getBaseSectionPaint() method (DG);
042:         * 23-Nov-2006 : Additional equals() and clone() tests (DG);
043:         * 17-Apr-2007 : Added check for label generator that returns a null label (DG);
044:         * 
045:         */
046:
047:        package org.jfree.chart.plot.junit;
048:
049:        import java.awt.BasicStroke;
050:        import java.awt.Color;
051:        import java.awt.Font;
052:        import java.awt.GradientPaint;
053:        import java.awt.Graphics2D;
054:        import java.awt.Rectangle;
055:        import java.awt.Stroke;
056:        import java.awt.geom.Rectangle2D;
057:        import java.awt.image.BufferedImage;
058:        import java.io.ByteArrayInputStream;
059:        import java.io.ByteArrayOutputStream;
060:        import java.io.ObjectInput;
061:        import java.io.ObjectInputStream;
062:        import java.io.ObjectOutput;
063:        import java.io.ObjectOutputStream;
064:        import java.text.AttributedString;
065:
066:        import junit.framework.Test;
067:        import junit.framework.TestCase;
068:        import junit.framework.TestSuite;
069:
070:        import org.jfree.chart.ChartFactory;
071:        import org.jfree.chart.JFreeChart;
072:        import org.jfree.chart.LegendItemCollection;
073:        import org.jfree.chart.labels.PieSectionLabelGenerator;
074:        import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
075:        import org.jfree.chart.labels.StandardPieToolTipGenerator;
076:        import org.jfree.chart.plot.PiePlot;
077:        import org.jfree.chart.urls.CustomPieURLGenerator;
078:        import org.jfree.chart.urls.StandardPieURLGenerator;
079:        import org.jfree.data.general.DefaultPieDataset;
080:        import org.jfree.data.general.PieDataset;
081:        import org.jfree.util.Rotation;
082:
083:        /**
084:         * Some tests for the {@link PiePlot} class.
085:         */
086:        public class PiePlotTests extends TestCase {
087:
088:            /**
089:             * Returns the tests as a test suite.
090:             *
091:             * @return The test suite.
092:             */
093:            public static Test suite() {
094:                return new TestSuite(PiePlotTests.class);
095:            }
096:
097:            /**
098:             * Constructs a new set of tests.
099:             *
100:             * @param name  the name of the tests.
101:             */
102:            public PiePlotTests(String name) {
103:                super (name);
104:            }
105:
106:            /**
107:             * Test the equals() method.
108:             */
109:            public void testEquals() {
110:
111:                PiePlot plot1 = new PiePlot();
112:                PiePlot plot2 = new PiePlot();
113:                assertTrue(plot1.equals(plot2));
114:                assertTrue(plot2.equals(plot1));
115:
116:                // pieIndex...
117:                plot1.setPieIndex(99);
118:                assertFalse(plot1.equals(plot2));
119:                plot2.setPieIndex(99);
120:                assertTrue(plot1.equals(plot2));
121:
122:                // interiorGap...
123:                plot1.setInteriorGap(0.15);
124:                assertFalse(plot1.equals(plot2));
125:                plot2.setInteriorGap(0.15);
126:                assertTrue(plot1.equals(plot2));
127:
128:                // circular
129:                plot1.setCircular(!plot1.isCircular());
130:                assertFalse(plot1.equals(plot2));
131:                plot2.setCircular(false);
132:                assertTrue(plot1.equals(plot2));
133:
134:                // startAngle
135:                plot1.setStartAngle(Math.PI);
136:                assertFalse(plot1.equals(plot2));
137:                plot2.setStartAngle(Math.PI);
138:                assertTrue(plot1.equals(plot2));
139:
140:                // direction
141:                plot1.setDirection(Rotation.ANTICLOCKWISE);
142:                assertFalse(plot1.equals(plot2));
143:                plot2.setDirection(Rotation.ANTICLOCKWISE);
144:                assertTrue(plot1.equals(plot2));
145:
146:                // ignoreZeroValues
147:                plot1.setIgnoreZeroValues(true);
148:                plot2.setIgnoreZeroValues(false);
149:                assertFalse(plot1.equals(plot2));
150:                plot2.setIgnoreZeroValues(true);
151:                assertTrue(plot1.equals(plot2));
152:
153:                // ignoreNullValues
154:                plot1.setIgnoreNullValues(true);
155:                plot2.setIgnoreNullValues(false);
156:                assertFalse(plot1.equals(plot2));
157:                plot2.setIgnoreNullValues(true);
158:                assertTrue(plot1.equals(plot2));
159:
160:                // sectionPaint
161:                plot1.setSectionPaint(new GradientPaint(1.0f, 2.0f, Color.red,
162:                        3.0f, 4.0f, Color.white));
163:                assertFalse(plot1.equals(plot2));
164:                plot2.setSectionPaint(new GradientPaint(1.0f, 2.0f, Color.red,
165:                        3.0f, 4.0f, Color.white));
166:                assertTrue(plot1.equals(plot2));
167:
168:                // sectionPaintMap
169:                plot1.setSectionPaint("A", new GradientPaint(1.0f, 2.0f,
170:                        Color.blue, 3.0f, 4.0f, Color.white));
171:                assertFalse(plot1.equals(plot2));
172:                plot2.setSectionPaint("A", new GradientPaint(1.0f, 2.0f,
173:                        Color.blue, 3.0f, 4.0f, Color.white));
174:                assertTrue(plot1.equals(plot2));
175:
176:                // baseSectionPaint
177:                plot1.setBaseSectionPaint(new GradientPaint(1.0f, 2.0f,
178:                        Color.black, 3.0f, 4.0f, Color.white));
179:                assertFalse(plot1.equals(plot2));
180:                plot2.setBaseSectionPaint(new GradientPaint(1.0f, 2.0f,
181:                        Color.black, 3.0f, 4.0f, Color.white));
182:                assertTrue(plot1.equals(plot2));
183:
184:                // sectionOutlinesVisible
185:                plot1.setSectionOutlinesVisible(false);
186:                assertFalse(plot1.equals(plot2));
187:                plot2.setSectionOutlinesVisible(false);
188:                assertTrue(plot1.equals(plot2));
189:
190:                // sectionOutlinePaint
191:                plot1.setSectionOutlinePaint(new GradientPaint(1.0f, 2.0f,
192:                        Color.cyan, 3.0f, 4.0f, Color.white));
193:                assertFalse(plot1.equals(plot2));
194:                plot2.setSectionOutlinePaint(new GradientPaint(1.0f, 2.0f,
195:                        Color.cyan, 3.0f, 4.0f, Color.white));
196:                assertTrue(plot1.equals(plot2));
197:
198:                // sectionOutlinePaintList
199:                plot1.setSectionOutlinePaint("A", new GradientPaint(1.0f, 2.0f,
200:                        Color.green, 3.0f, 4.0f, Color.white));
201:                assertFalse(plot1.equals(plot2));
202:                plot2.setSectionOutlinePaint("A", new GradientPaint(1.0f, 2.0f,
203:                        Color.green, 3.0f, 4.0f, Color.white));
204:                assertTrue(plot1.equals(plot2));
205:
206:                // baseSectionOutlinePaint
207:                plot1.setBaseSectionOutlinePaint(new GradientPaint(1.0f, 2.0f,
208:                        Color.gray, 3.0f, 4.0f, Color.white));
209:                assertFalse(plot1.equals(plot2));
210:                plot2.setBaseSectionOutlinePaint(new GradientPaint(1.0f, 2.0f,
211:                        Color.gray, 3.0f, 4.0f, Color.white));
212:                assertTrue(plot1.equals(plot2));
213:
214:                // sectionOutlineStroke
215:                plot1.setSectionOutlineStroke(new BasicStroke(1.0f));
216:                assertFalse(plot1.equals(plot2));
217:                plot2.setSectionOutlineStroke(new BasicStroke(1.0f));
218:                assertTrue(plot1.equals(plot2));
219:
220:                // sectionOutlineStrokeList
221:                plot1.setSectionOutlineStroke("A", new BasicStroke(1.0f));
222:                assertFalse(plot1.equals(plot2));
223:                plot2.setSectionOutlineStroke("A", new BasicStroke(1.0f));
224:                assertTrue(plot1.equals(plot2));
225:
226:                // baseSectionOutlineStroke
227:                plot1.setBaseSectionOutlineStroke(new BasicStroke(1.0f));
228:                assertFalse(plot1.equals(plot2));
229:                plot2.setBaseSectionOutlineStroke(new BasicStroke(1.0f));
230:                assertTrue(plot1.equals(plot2));
231:
232:                // shadowPaint
233:                plot1.setShadowPaint(new GradientPaint(1.0f, 2.0f,
234:                        Color.orange, 3.0f, 4.0f, Color.white));
235:                assertFalse(plot1.equals(plot2));
236:                plot2.setShadowPaint(new GradientPaint(1.0f, 2.0f,
237:                        Color.orange, 3.0f, 4.0f, Color.white));
238:                assertTrue(plot1.equals(plot2));
239:
240:                // shadowXOffset
241:                plot1.setShadowXOffset(4.4);
242:                assertFalse(plot1.equals(plot2));
243:                plot2.setShadowXOffset(4.4);
244:                assertTrue(plot1.equals(plot2));
245:
246:                // shadowYOffset
247:                plot1.setShadowYOffset(4.4);
248:                assertFalse(plot1.equals(plot2));
249:                plot2.setShadowYOffset(4.4);
250:                assertTrue(plot1.equals(plot2));
251:
252:                // labelFont
253:                plot1.setLabelFont(new Font("Serif", Font.PLAIN, 18));
254:                assertFalse(plot1.equals(plot2));
255:                plot2.setLabelFont(new Font("Serif", Font.PLAIN, 18));
256:                assertTrue(plot1.equals(plot2));
257:
258:                // labelPaint
259:                plot1.setLabelPaint(new GradientPaint(1.0f, 2.0f,
260:                        Color.darkGray, 3.0f, 4.0f, Color.white));
261:                assertFalse(plot1.equals(plot2));
262:                plot2.setLabelPaint(new GradientPaint(1.0f, 2.0f,
263:                        Color.darkGray, 3.0f, 4.0f, Color.white));
264:                assertTrue(plot1.equals(plot2));
265:
266:                // labelBackgroundPaint
267:                plot1.setLabelBackgroundPaint(new GradientPaint(1.0f, 2.0f,
268:                        Color.red, 3.0f, 4.0f, Color.white));
269:                assertFalse(plot1.equals(plot2));
270:                plot2.setLabelBackgroundPaint(new GradientPaint(1.0f, 2.0f,
271:                        Color.red, 3.0f, 4.0f, Color.white));
272:                assertTrue(plot1.equals(plot2));
273:
274:                // labelOutlinePaint
275:                plot1.setLabelOutlinePaint(new GradientPaint(1.0f, 2.0f,
276:                        Color.blue, 3.0f, 4.0f, Color.white));
277:                assertFalse(plot1.equals(plot2));
278:                plot2.setLabelOutlinePaint(new GradientPaint(1.0f, 2.0f,
279:                        Color.blue, 3.0f, 4.0f, Color.white));
280:                assertTrue(plot1.equals(plot2));
281:
282:                // labelOutlineStroke
283:                Stroke s = new BasicStroke(1.1f);
284:                plot1.setLabelOutlineStroke(s);
285:                assertFalse(plot1.equals(plot2));
286:                plot2.setLabelOutlineStroke(s);
287:                assertTrue(plot1.equals(plot2));
288:
289:                // labelShadowPaint
290:                plot1.setLabelShadowPaint(new GradientPaint(1.0f, 2.0f,
291:                        Color.yellow, 3.0f, 4.0f, Color.white));
292:                assertFalse(plot1.equals(plot2));
293:                plot2.setLabelShadowPaint(new GradientPaint(1.0f, 2.0f,
294:                        Color.yellow, 3.0f, 4.0f, Color.white));
295:                assertTrue(plot1.equals(plot2));
296:
297:                // explodePercentages
298:                plot1.setExplodePercent("A", 0.33);
299:                assertFalse(plot1.equals(plot2));
300:                plot2.setExplodePercent("A", 0.33);
301:                assertTrue(plot1.equals(plot2));
302:
303:                // labelGenerator
304:                plot1.setLabelGenerator(new StandardPieSectionLabelGenerator(
305:                        "{2}{1}{0}"));
306:                assertFalse(plot1.equals(plot2));
307:                plot2.setLabelGenerator(new StandardPieSectionLabelGenerator(
308:                        "{2}{1}{0}"));
309:                assertTrue(plot1.equals(plot2));
310:
311:                // labelFont
312:                Font f = new Font("SansSerif", Font.PLAIN, 20);
313:                plot1.setLabelFont(f);
314:                assertFalse(plot1.equals(plot2));
315:                plot2.setLabelFont(f);
316:                assertTrue(plot1.equals(plot2));
317:
318:                // labelPaint
319:                plot1.setLabelPaint(new GradientPaint(1.0f, 2.0f,
320:                        Color.magenta, 3.0f, 4.0f, Color.white));
321:                assertFalse(plot1.equals(plot2));
322:                plot2.setLabelPaint(new GradientPaint(1.0f, 2.0f,
323:                        Color.magenta, 3.0f, 4.0f, Color.white));
324:                assertTrue(plot1.equals(plot2));
325:
326:                // maximumLabelWidth
327:                plot1.setMaximumLabelWidth(0.33);
328:                assertFalse(plot1.equals(plot2));
329:                plot2.setMaximumLabelWidth(0.33);
330:                assertTrue(plot1.equals(plot2));
331:
332:                // labelGap
333:                plot1.setLabelGap(0.11);
334:                assertFalse(plot1.equals(plot2));
335:                plot2.setLabelGap(0.11);
336:                assertTrue(plot1.equals(plot2));
337:
338:                // links visible
339:                plot1.setLabelLinksVisible(false);
340:                assertFalse(plot1.equals(plot2));
341:                plot2.setLabelLinksVisible(false);
342:                assertTrue(plot1.equals(plot2));
343:
344:                // linkMargin
345:                plot1.setLabelLinkMargin(0.11);
346:                assertFalse(plot1.equals(plot2));
347:                plot2.setLabelLinkMargin(0.11);
348:                assertTrue(plot1.equals(plot2));
349:
350:                // labelLinkPaint
351:                plot1.setLabelLinkPaint(new GradientPaint(1.0f, 2.0f,
352:                        Color.magenta, 3.0f, 4.0f, Color.white));
353:                assertFalse(plot1.equals(plot2));
354:                plot2.setLabelLinkPaint(new GradientPaint(1.0f, 2.0f,
355:                        Color.magenta, 3.0f, 4.0f, Color.white));
356:                assertTrue(plot1.equals(plot2));
357:
358:                // labelLinkStroke
359:                plot1.setLabelLinkStroke(new BasicStroke(1.0f));
360:                assertFalse(plot1.equals(plot2));
361:                plot2.setLabelLinkStroke(new BasicStroke(1.0f));
362:                assertTrue(plot1.equals(plot2));
363:
364:                // toolTipGenerator
365:                plot1.setToolTipGenerator(new StandardPieToolTipGenerator(
366:                        "{2}{1}{0}"));
367:                assertFalse(plot1.equals(plot2));
368:                plot2.setToolTipGenerator(new StandardPieToolTipGenerator(
369:                        "{2}{1}{0}"));
370:                assertTrue(plot1.equals(plot2));
371:
372:                // urlGenerator
373:                plot1.setURLGenerator(new StandardPieURLGenerator("xx"));
374:                assertFalse(plot1.equals(plot2));
375:                plot2.setURLGenerator(new StandardPieURLGenerator("xx"));
376:                assertTrue(plot1.equals(plot2));
377:
378:                // minimumArcAngleToDraw
379:                plot1.setMinimumArcAngleToDraw(1.0);
380:                assertFalse(plot1.equals(plot2));
381:                plot2.setMinimumArcAngleToDraw(1.0);
382:                assertTrue(plot1.equals(plot2));
383:
384:                // legendItemShape
385:                plot1.setLegendItemShape(new Rectangle2D.Double(1.0, 2.0, 3.0,
386:                        4.0));
387:                assertFalse(plot1.equals(plot2));
388:                plot2.setLegendItemShape(new Rectangle2D.Double(1.0, 2.0, 3.0,
389:                        4.0));
390:                assertTrue(plot1.equals(plot2));
391:
392:                // legendLabelGenerator
393:                plot1
394:                        .setLegendLabelGenerator(new StandardPieSectionLabelGenerator(
395:                                "{0} --> {1}"));
396:                assertFalse(plot1.equals(plot2));
397:                plot2
398:                        .setLegendLabelGenerator(new StandardPieSectionLabelGenerator(
399:                                "{0} --> {1}"));
400:                assertTrue(plot1.equals(plot2));
401:
402:                // legendLabelToolTipGenerator
403:                plot1
404:                        .setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator(
405:                                "{0} is {1}"));
406:                assertFalse(plot1.equals(plot2));
407:                plot2
408:                        .setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator(
409:                                "{0} is {1}"));
410:                assertTrue(plot1.equals(plot2));
411:
412:                // legendLabelURLGenerator
413:                plot1.setLegendLabelURLGenerator(new StandardPieURLGenerator(
414:                        "index.html"));
415:                assertFalse(plot1.equals(plot2));
416:                plot2.setLegendLabelURLGenerator(new StandardPieURLGenerator(
417:                        "index.html"));
418:                assertTrue(plot1.equals(plot2));
419:
420:            }
421:
422:            /**
423:             * Some basic checks for the clone() method.
424:             */
425:            public void testCloning() {
426:                PiePlot p1 = new PiePlot();
427:                PiePlot p2 = null;
428:                try {
429:                    p2 = (PiePlot) p1.clone();
430:                } catch (CloneNotSupportedException e) {
431:                    e.printStackTrace();
432:                }
433:                assertTrue(p1 != p2);
434:                assertTrue(p1.getClass() == p2.getClass());
435:                assertTrue(p1.equals(p2));
436:            }
437:
438:            /**
439:             * Check cloning of the urlGenerator field.
440:             */
441:            public void testCloning_URLGenerator() {
442:                CustomPieURLGenerator generator = new CustomPieURLGenerator();
443:                PiePlot p1 = new PiePlot();
444:                p1.setURLGenerator(generator);
445:                PiePlot p2 = null;
446:                try {
447:                    p2 = (PiePlot) p1.clone();
448:                } catch (CloneNotSupportedException e) {
449:                    e.printStackTrace();
450:                }
451:                assertTrue(p1 != p2);
452:                assertTrue(p1.getClass() == p2.getClass());
453:                assertTrue(p1.equals(p2));
454:
455:                // check that the URL generator has been cloned
456:                assertTrue(p1.getURLGenerator() != p2.getURLGenerator());
457:            }
458:
459:            /**
460:             * Check cloning of the legendItemShape field.
461:             */
462:            public void testCloning_LegendItemShape() {
463:                Rectangle shape = new Rectangle(-4, -4, 8, 8);
464:                PiePlot p1 = new PiePlot();
465:                p1.setLegendItemShape(shape);
466:                PiePlot p2 = null;
467:                try {
468:                    p2 = (PiePlot) p1.clone();
469:                } catch (CloneNotSupportedException e) {
470:                    e.printStackTrace();
471:                }
472:                assertTrue(p1 != p2);
473:                assertTrue(p1.getClass() == p2.getClass());
474:                assertTrue(p1.equals(p2));
475:
476:                // change the shape and make sure it only affects p1
477:                shape.setRect(1.0, 2.0, 3.0, 4.0);
478:                assertFalse(p1.equals(p2));
479:            }
480:
481:            /**
482:             * Check cloning of the legendLabelGenerator field.
483:             */
484:            public void testCloning_LegendLabelGenerator() {
485:                StandardPieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator();
486:                PiePlot p1 = new PiePlot();
487:                p1.setLegendLabelGenerator(generator);
488:                PiePlot p2 = null;
489:                try {
490:                    p2 = (PiePlot) p1.clone();
491:                } catch (CloneNotSupportedException e) {
492:                    e.printStackTrace();
493:                }
494:                assertTrue(p1 != p2);
495:                assertTrue(p1.getClass() == p2.getClass());
496:                assertTrue(p1.equals(p2));
497:
498:                // change the generator and make sure it only affects p1
499:                generator.getNumberFormat().setMinimumFractionDigits(2);
500:                assertFalse(p1.equals(p2));
501:            }
502:
503:            /**
504:             * Check cloning of the legendLabelToolTipGenerator field.
505:             */
506:            public void testCloning_LegendLabelToolTipGenerator() {
507:                StandardPieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator();
508:                PiePlot p1 = new PiePlot();
509:                p1.setLegendLabelToolTipGenerator(generator);
510:                PiePlot p2 = null;
511:                try {
512:                    p2 = (PiePlot) p1.clone();
513:                } catch (CloneNotSupportedException e) {
514:                    e.printStackTrace();
515:                }
516:                assertTrue(p1 != p2);
517:                assertTrue(p1.getClass() == p2.getClass());
518:                assertTrue(p1.equals(p2));
519:
520:                // change the generator and make sure it only affects p1
521:                generator.getNumberFormat().setMinimumFractionDigits(2);
522:                assertFalse(p1.equals(p2));
523:            }
524:
525:            /**
526:             * Check cloning of the legendLabelURLGenerator field.
527:             */
528:            public void testCloning_LegendLabelURLGenerator() {
529:                CustomPieURLGenerator generator = new CustomPieURLGenerator();
530:                PiePlot p1 = new PiePlot();
531:                p1.setLegendLabelURLGenerator(generator);
532:                PiePlot p2 = null;
533:                try {
534:                    p2 = (PiePlot) p1.clone();
535:                } catch (CloneNotSupportedException e) {
536:                    e.printStackTrace();
537:                }
538:                assertTrue(p1 != p2);
539:                assertTrue(p1.getClass() == p2.getClass());
540:                assertTrue(p1.equals(p2));
541:
542:                // check that the URL generator has been cloned
543:                assertTrue(p1.getLegendLabelURLGenerator() != p2
544:                        .getLegendLabelURLGenerator());
545:            }
546:
547:            /**
548:             * Serialize an instance, restore it, and check for equality.
549:             */
550:            public void testSerialization() {
551:                PiePlot p1 = new PiePlot(null);
552:                PiePlot p2 = null;
553:                try {
554:                    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
555:                    ObjectOutput out = new ObjectOutputStream(buffer);
556:                    out.writeObject(p1);
557:                    out.close();
558:
559:                    ObjectInput in = new ObjectInputStream(
560:                            new ByteArrayInputStream(buffer.toByteArray()));
561:                    p2 = (PiePlot) in.readObject();
562:                    in.close();
563:                } catch (Exception e) {
564:                    e.printStackTrace();
565:                }
566:                assertEquals(p1, p2);
567:            }
568:
569:            /**
570:             * Some checks for the getLegendItems() method.
571:             */
572:            public void testGetLegendItems() {
573:                DefaultPieDataset dataset = new DefaultPieDataset();
574:                dataset.setValue("Item 1", 1.0);
575:                dataset.setValue("Item 2", 2.0);
576:                dataset.setValue("Item 3", 0.0);
577:                dataset.setValue("Item 4", null);
578:
579:                PiePlot plot = new PiePlot(dataset);
580:                plot.setIgnoreNullValues(false);
581:                plot.setIgnoreZeroValues(false);
582:                LegendItemCollection items = plot.getLegendItems();
583:                assertEquals(4, items.getItemCount());
584:
585:                // check that null items are ignored if requested
586:                plot.setIgnoreNullValues(true);
587:                items = plot.getLegendItems();
588:                assertEquals(3, items.getItemCount());
589:
590:                // check that zero items are ignored if requested
591:                plot.setIgnoreZeroValues(true);
592:                items = plot.getLegendItems();
593:                assertEquals(2, items.getItemCount());
594:
595:                // check that negative items are always ignored
596:                dataset.setValue("Item 5", -1.0);
597:                items = plot.getLegendItems();
598:                assertEquals(2, items.getItemCount());
599:            }
600:
601:            /**
602:             * Check that the default base section paint is not null, and that you 
603:             * can never set it to null.
604:             */
605:            public void testGetBaseSectionPaint() {
606:                PiePlot plot = new PiePlot();
607:                assertNotNull(plot.getBaseSectionPaint());
608:
609:                boolean pass = false;
610:                try {
611:                    plot.setBaseSectionPaint(null);
612:                } catch (IllegalArgumentException e) {
613:                    pass = true;
614:                }
615:                assertTrue(pass);
616:            }
617:
618:            static class NullLegendLabelGenerator implements 
619:                    PieSectionLabelGenerator {
620:                public AttributedString generateAttributedSectionLabel(
621:                        PieDataset dataset, Comparable key) {
622:                    return null;
623:                }
624:
625:                public String generateSectionLabel(PieDataset dataset,
626:                        Comparable key) {
627:                    return null;
628:                }
629:            }
630:
631:            /**
632:             * Draws a pie chart where the label generator returns null.
633:             */
634:            public void testDrawWithNullLegendLabels() {
635:                DefaultPieDataset dataset = new DefaultPieDataset();
636:                dataset.setValue("L1", 12.0);
637:                dataset.setValue("L2", 11.0);
638:                JFreeChart chart = ChartFactory.createPieChart("Test", dataset,
639:                        true, false, false);
640:                PiePlot plot = (PiePlot) chart.getPlot();
641:                plot.setLegendLabelGenerator(new NullLegendLabelGenerator());
642:                boolean success = false;
643:                try {
644:                    BufferedImage image = new BufferedImage(200, 100,
645:                            BufferedImage.TYPE_INT_RGB);
646:                    Graphics2D g2 = image.createGraphics();
647:                    chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100),
648:                            null, null);
649:                    g2.dispose();
650:                    success = true;
651:                } catch (Exception e) {
652:                    success = false;
653:                }
654:                assertTrue(success);
655:            }
656:
657:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.