PiePlot3DTest.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2013, 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
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  22. * USA.
  23. *
  24. * [Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  25. * Other names may be trademarks of their respective owners.]
  26. *
  27. * ------------------
  28. * Pie3DPlotTest.java
  29. * ------------------
  30. * (C) Copyright 2003-2013, by Object Refinery Limited and Contributors.
  31. *
  32. * Original Author: David Gilbert (for Object Refinery Limited);
  33. * Contributor(s): -;
  34. *
  35. * Changes
  36. * -------
  37. * 18-Mar-2003 : Version 1 (DG);
  38. * 22-Mar-2007 : Added testEquals() (DG);
  39. * 05-Oct-2007 : Modified testEquals() for new field (DG);
  40. * 19-Mar-2008 : Added test for null dataset (DG);
  41. *
  42. */
  43. package org.jfree.chart.plot;
  44. import static org.junit.Assert.assertEquals;
  45. import static org.junit.Assert.assertFalse;
  46. import static org.junit.Assert.assertTrue;
  47. import java.awt.Graphics2D;
  48. import java.awt.geom.Rectangle2D;
  49. import java.awt.image.BufferedImage;
  50. import org.jfree.chart.ChartFactory;
  51. import org.jfree.chart.JFreeChart;
  52. import org.jfree.chart.TestUtilities;
  53. import org.junit.Test;
  54. /**
  55. * Tests for the {@link PiePlot3D} class.
  56. */
  57. public class PiePlot3DTest {
  58. /**
  59. * Some checks for the equals() method.
  60. */
  61. @Test
  62. public void testEquals() {
  63. PiePlot3D p1 = new PiePlot3D();
  64. PiePlot3D p2 = new PiePlot3D();
  65. assertTrue(p1.equals(p2));
  66. assertTrue(p2.equals(p1));
  67. p1.setDepthFactor(1.23);
  68. assertFalse(p1.equals(p2));
  69. p2.setDepthFactor(1.23);
  70. assertTrue(p1.equals(p2));
  71. p1.setDarkerSides(true);
  72. assertFalse(p1.equals(p2));
  73. p2.setDarkerSides(true);
  74. assertTrue(p1.equals(p2));
  75. }
  76. /**
  77. * Serialize an instance, restore it, and check for equality.
  78. */
  79. @Test
  80. public void testSerialization() {
  81. PiePlot3D p1 = new PiePlot3D(null);
  82. PiePlot3D p2 = (PiePlot3D) TestUtilities.serialised(p1);
  83. assertEquals(p1, p2);
  84. }
  85. /**
  86. * Draws a pie chart where the label generator returns null.
  87. */
  88. @Test
  89. public void testDrawWithNullDataset() {
  90. JFreeChart chart = ChartFactory.createPieChart3D("Test", null, true,
  91. false, false);
  92. boolean success = false;
  93. try {
  94. BufferedImage image = new BufferedImage(200 , 100,
  95. BufferedImage.TYPE_INT_RGB);
  96. Graphics2D g2 = image.createGraphics();
  97. chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
  98. g2.dispose();
  99. success = true;
  100. }
  101. catch (Exception e) {
  102. success = false;
  103. }
  104. assertTrue(success);
  105. }
  106. }