PlotTest.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. * PlotTest.java
  29. * -------------
  30. * (C) Copyright 2005-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. * 06-Jun-2005 : Version 1 (DG);
  38. * 30-Jun-2006 : Extended equals() test to cover new field (DG);
  39. * 11-May-2007 : Another new field in testEquals() (DG);
  40. *
  41. */
  42. package org.jfree.chart.plot;
  43. import static org.junit.Assert.assertFalse;
  44. import static org.junit.Assert.assertTrue;
  45. import java.awt.BasicStroke;
  46. import java.awt.Color;
  47. import java.awt.Font;
  48. import java.awt.GradientPaint;
  49. import java.awt.Paint;
  50. import java.awt.Rectangle;
  51. import java.awt.Shape;
  52. import java.awt.Stroke;
  53. import org.jfree.chart.JFreeChart;
  54. import org.jfree.ui.Align;
  55. import org.jfree.ui.RectangleInsets;
  56. import org.junit.Test;
  57. /**
  58. * Some tests for the {@link Plot} class.
  59. */
  60. public class PlotTest {
  61. /**
  62. * Check that the equals() method can distinguish all fields (note that
  63. * the dataset is NOT considered in the equals() method).
  64. */
  65. @Test
  66. public void testEquals() {
  67. PiePlot plot1 = new PiePlot();
  68. PiePlot plot2 = new PiePlot();
  69. assertTrue(plot1.equals(plot2));
  70. assertTrue(plot2.equals(plot1));
  71. // noDataMessage
  72. plot1.setNoDataMessage("No data XYZ");
  73. assertFalse(plot1.equals(plot2));
  74. plot2.setNoDataMessage("No data XYZ");
  75. assertTrue(plot1.equals(plot2));
  76. // noDataMessageFont
  77. plot1.setNoDataMessageFont(new Font("SansSerif", Font.PLAIN, 13));
  78. assertFalse(plot1.equals(plot2));
  79. plot2.setNoDataMessageFont(new Font("SansSerif", Font.PLAIN, 13));
  80. assertTrue(plot1.equals(plot2));
  81. // noDataMessagePaint
  82. plot1.setNoDataMessagePaint(new GradientPaint(1.0f, 2.0f, Color.red,
  83. 3.0f, 4.0f, Color.blue));
  84. assertFalse(plot1.equals(plot2));
  85. plot2.setNoDataMessagePaint(new GradientPaint(1.0f, 2.0f, Color.red,
  86. 3.0f, 4.0f, Color.blue));
  87. assertTrue(plot1.equals(plot2));
  88. // insets
  89. plot1.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
  90. assertFalse(plot1.equals(plot2));
  91. plot2.setInsets(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
  92. assertTrue(plot1.equals(plot2));
  93. // outlineVisible
  94. plot1.setOutlineVisible(false);
  95. assertFalse(plot1.equals(plot2));
  96. plot2.setOutlineVisible(false);
  97. assertTrue(plot1.equals(plot2));
  98. // outlineStroke
  99. BasicStroke s = new BasicStroke(1.23f);
  100. plot1.setOutlineStroke(s);
  101. assertFalse(plot1.equals(plot2));
  102. plot2.setOutlineStroke(s);
  103. assertTrue(plot1.equals(plot2));
  104. // outlinePaint
  105. plot1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.yellow,
  106. 3.0f, 4.0f, Color.green));
  107. assertFalse(plot1.equals(plot2));
  108. plot2.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.yellow,
  109. 3.0f, 4.0f, Color.green));
  110. assertTrue(plot1.equals(plot2));
  111. // backgroundPaint
  112. plot1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.cyan,
  113. 3.0f, 4.0f, Color.green));
  114. assertFalse(plot1.equals(plot2));
  115. plot2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.cyan,
  116. 3.0f, 4.0f, Color.green));
  117. assertTrue(plot1.equals(plot2));
  118. // backgroundImage
  119. plot1.setBackgroundImage(JFreeChart.INFO.getLogo());
  120. assertFalse(plot1.equals(plot2));
  121. plot2.setBackgroundImage(JFreeChart.INFO.getLogo());
  122. assertTrue(plot1.equals(plot2));
  123. // backgroundImageAlignment
  124. plot1.setBackgroundImageAlignment(Align.BOTTOM_RIGHT);
  125. assertFalse(plot1.equals(plot2));
  126. plot2.setBackgroundImageAlignment(Align.BOTTOM_RIGHT);
  127. assertTrue(plot1.equals(plot2));
  128. // backgroundImageAlpha
  129. plot1.setBackgroundImageAlpha(0.77f);
  130. assertFalse(plot1.equals(plot2));
  131. plot2.setBackgroundImageAlpha(0.77f);
  132. assertTrue(plot1.equals(plot2));
  133. // foregroundAlpha
  134. plot1.setForegroundAlpha(0.99f);
  135. assertFalse(plot1.equals(plot2));
  136. plot2.setForegroundAlpha(0.99f);
  137. assertTrue(plot1.equals(plot2));
  138. // backgroundAlpha
  139. plot1.setBackgroundAlpha(0.99f);
  140. assertFalse(plot1.equals(plot2));
  141. plot2.setBackgroundAlpha(0.99f);
  142. assertTrue(plot1.equals(plot2));
  143. // drawingSupplier
  144. plot1.setDrawingSupplier(new DefaultDrawingSupplier(
  145. new Paint[] {Color.blue}, new Paint[] {Color.red},
  146. new Stroke[] {new BasicStroke(1.1f)},
  147. new Stroke[] {new BasicStroke(9.9f)},
  148. new Shape[] {new Rectangle(1, 2, 3, 4)}));
  149. assertFalse(plot1.equals(plot2));
  150. plot2.setDrawingSupplier(new DefaultDrawingSupplier(
  151. new Paint[] {Color.blue}, new Paint[] {Color.red},
  152. new Stroke[] {new BasicStroke(1.1f)},
  153. new Stroke[] {new BasicStroke(9.9f)},
  154. new Shape[] {new Rectangle(1, 2, 3, 4)}));
  155. assertTrue(plot1.equals(plot2));
  156. }
  157. }