StandardChartThemeTest.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. * StandardChartThemeTest.java
  29. * ---------------------------
  30. * (C) Copyright 2008-2013, by Object Refinery Limited.
  31. *
  32. * Original Author: David Gilbert (for Object Refinery Limited);
  33. * Contributor(s): -;
  34. *
  35. * Changes
  36. * -------
  37. * 14-Aug-2008 : Version 1 (DG);
  38. *
  39. */
  40. package org.jfree.chart;
  41. import static org.junit.Assert.assertTrue;
  42. import static org.junit.Assert.assertFalse;
  43. import java.awt.BasicStroke;
  44. import java.awt.Color;
  45. import java.awt.Font;
  46. import java.awt.GradientPaint;
  47. import java.awt.Paint;
  48. import java.awt.Shape;
  49. import java.awt.Stroke;
  50. import java.awt.geom.Rectangle2D;
  51. import org.jfree.chart.plot.DefaultDrawingSupplier;
  52. import org.jfree.chart.plot.PieLabelLinkStyle;
  53. import org.jfree.chart.renderer.category.StandardBarPainter;
  54. import org.jfree.chart.renderer.xy.StandardXYBarPainter;
  55. import org.jfree.ui.RectangleInsets;
  56. import org.junit.Test;
  57. /**
  58. * Tests for the {@link StandardChartTheme} class.
  59. */
  60. public class StandardChartThemeTest {
  61. /**
  62. * Confirm that the equals method can distinguish all the required fields.
  63. */
  64. @Test
  65. public void testEquals() {
  66. StandardChartTheme t1 = new StandardChartTheme("Name");
  67. StandardChartTheme t2 = new StandardChartTheme("Name");
  68. assertTrue(t1.equals(t2));
  69. // name
  70. t1 = new StandardChartTheme("t1");
  71. assertFalse(t1.equals(t2));
  72. t2 = new StandardChartTheme("t1");
  73. assertTrue(t1.equals(t2));
  74. //extraLargeFont
  75. t1.setExtraLargeFont(new Font("Dialog", Font.PLAIN, 21));
  76. assertFalse(t1.equals(t2));
  77. t2.setExtraLargeFont(new Font("Dialog", Font.PLAIN, 21));
  78. assertTrue(t1.equals(t2));
  79. //largeFont
  80. t1.setLargeFont(new Font("Dialog", Font.PLAIN, 19));
  81. assertFalse(t1.equals(t2));
  82. t2.setLargeFont(new Font("Dialog", Font.PLAIN, 19));
  83. assertTrue(t1.equals(t2));
  84. //regularFont;
  85. t1.setRegularFont(new Font("Dialog", Font.PLAIN, 17));
  86. assertFalse(t1.equals(t2));
  87. t2.setRegularFont(new Font("Dialog", Font.PLAIN, 17));
  88. assertTrue(t1.equals(t2));
  89. //titlePaint;
  90. t1.setTitlePaint(new GradientPaint(0f, 1f, Color.red, 2f, 3f, Color.blue));
  91. assertFalse(t1.equals(t2));
  92. t2.setTitlePaint(new GradientPaint(0f, 1f, Color.red, 2f, 3f, Color.blue));
  93. assertTrue(t1.equals(t2));
  94. //subtitlePaint;
  95. t1.setSubtitlePaint(new GradientPaint(1f, 2f, Color.red, 3f, 4f, Color.blue));
  96. assertFalse(t1.equals(t2));
  97. t2.setSubtitlePaint(new GradientPaint(1f, 2f, Color.red, 3f, 4f, Color.blue));
  98. assertTrue(t1.equals(t2));
  99. //chartBackgroundPaint;
  100. t1.setChartBackgroundPaint(new GradientPaint(2f, 3f, Color.blue, 4f, 5f, Color.red));
  101. assertFalse(t1.equals(t2));
  102. t2.setChartBackgroundPaint(new GradientPaint(2f, 3f, Color.blue, 4f, 5f, Color.red));
  103. assertTrue(t1.equals(t2));
  104. //legendBackgroundPaint;
  105. t1.setLegendBackgroundPaint(new GradientPaint(3f, 4f, Color.gray, 1f, 2f, Color.red));
  106. assertFalse(t1.equals(t2));
  107. t2.setLegendBackgroundPaint(new GradientPaint(3f, 4f, Color.gray, 1f, 2f, Color.red));
  108. assertTrue(t1.equals(t2));
  109. //legendItemPaint;
  110. t1.setLegendItemPaint(new GradientPaint(9f, 8f, Color.red, 7f, 6f, Color.blue));
  111. assertFalse(t1.equals(t2));
  112. t2.setLegendItemPaint(new GradientPaint(9f, 8f, Color.red, 7f, 6f, Color.blue));
  113. assertTrue(t1.equals(t2));
  114. //drawingSupplier;
  115. t1.setDrawingSupplier(new DefaultDrawingSupplier(
  116. new Paint[] {Color.red},
  117. new Paint[] {Color.blue},
  118. new Stroke[] {new BasicStroke(1.0f)},
  119. new Stroke[] {new BasicStroke(1.0f)},
  120. new Shape[] {new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)}));
  121. assertFalse(t1.equals(t2));
  122. t2.setDrawingSupplier(new DefaultDrawingSupplier(
  123. new Paint[] {Color.red},
  124. new Paint[] {Color.blue},
  125. new Stroke[] {new BasicStroke(1.0f)},
  126. new Stroke[] {new BasicStroke(1.0f)},
  127. new Shape[] {new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)}));
  128. assertTrue(t1.equals(t2));
  129. //plotBackgroundPaint;
  130. t1.setPlotBackgroundPaint(new GradientPaint(4f, 3f, Color.red, 6f, 7f, Color.blue));
  131. assertFalse(t1.equals(t2));
  132. t2.setPlotBackgroundPaint(new GradientPaint(4f, 3f, Color.red, 6f, 7f, Color.blue));
  133. assertTrue(t1.equals(t2));
  134. //plotOutlinePaint;
  135. t1.setPlotOutlinePaint(new GradientPaint(5f, 2f, Color.blue, 6f, 7f, Color.red));
  136. assertFalse(t1.equals(t2));
  137. t2.setPlotOutlinePaint(new GradientPaint(5f, 2f, Color.blue, 6f, 7f, Color.red));
  138. assertTrue(t1.equals(t2));
  139. //labelLinkStyle;
  140. t1.setLabelLinkStyle(PieLabelLinkStyle.STANDARD);
  141. assertFalse(t1.equals(t2));
  142. t2.setLabelLinkStyle(PieLabelLinkStyle.STANDARD);
  143. assertTrue(t1.equals(t2));
  144. //labelLinkPaint;
  145. t1.setLabelLinkPaint(new GradientPaint(4f, 3f, Color.red, 2f, 9f, Color.blue));
  146. assertFalse(t1.equals(t2));
  147. t2.setLabelLinkPaint(new GradientPaint(4f, 3f, Color.red, 2f, 9f, Color.blue));
  148. assertTrue(t1.equals(t2));
  149. //domainGridlinePaint;
  150. t1.setDomainGridlinePaint(Color.blue);
  151. assertFalse(t1.equals(t2));
  152. t2.setDomainGridlinePaint(Color.blue);
  153. assertTrue(t1.equals(t2));
  154. //rangeGridlinePaint;
  155. t1.setRangeGridlinePaint(Color.red);
  156. assertFalse(t1.equals(t2));
  157. t2.setRangeGridlinePaint(Color.red);
  158. assertTrue(t1.equals(t2));
  159. //axisOffset;
  160. t1.setAxisOffset(new RectangleInsets(1, 2, 3, 4));
  161. assertFalse(t1.equals(t2));
  162. t2.setAxisOffset(new RectangleInsets(1, 2, 3, 4));
  163. assertTrue(t1.equals(t2));
  164. //axisLabelPaint;
  165. t1.setAxisLabelPaint(new GradientPaint(8f, 4f, Color.gray, 2f, 9f, Color.blue));
  166. assertFalse(t1.equals(t2));
  167. t2.setAxisLabelPaint(new GradientPaint(8f, 4f, Color.gray, 2f, 9f, Color.blue));
  168. assertTrue(t1.equals(t2));
  169. //tickLabelPaint;
  170. t1.setTickLabelPaint(new GradientPaint(3f, 4f, Color.red, 5f, 6f, Color.yellow));
  171. assertFalse(t1.equals(t2));
  172. t2.setTickLabelPaint(new GradientPaint(3f, 4f, Color.red, 5f, 6f, Color.yellow));
  173. assertTrue(t1.equals(t2));
  174. //itemLabelPaint;
  175. t1.setItemLabelPaint(new GradientPaint(2f, 5f, Color.gray, 1f, 2f, Color.blue));
  176. assertFalse(t1.equals(t2));
  177. t2.setItemLabelPaint(new GradientPaint(2f, 5f, Color.gray, 1f, 2f, Color.blue));
  178. assertTrue(t1.equals(t2));
  179. //shadowVisible;
  180. t1.setShadowVisible(!t1.isShadowVisible());
  181. assertFalse(t1.equals(t2));
  182. t2.setShadowVisible(t1.isShadowVisible());
  183. assertTrue(t1.equals(t2));
  184. //shadowPaint;
  185. t1.setShadowPaint(new GradientPaint(7f, 1f, Color.blue, 4f, 6f, Color.red));
  186. assertFalse(t1.equals(t2));
  187. t2.setShadowPaint(new GradientPaint(7f, 1f, Color.blue, 4f, 6f, Color.red));
  188. assertTrue(t1.equals(t2));
  189. //barPainter;
  190. t1.setBarPainter(new StandardBarPainter());
  191. assertFalse(t1.equals(t2));
  192. t2.setBarPainter(new StandardBarPainter());
  193. assertTrue(t1.equals(t2));
  194. //xyBarPainter;
  195. t1.setXYBarPainter(new StandardXYBarPainter());
  196. assertFalse(t1.equals(t2));
  197. t2.setXYBarPainter(new StandardXYBarPainter());
  198. assertTrue(t1.equals(t2));
  199. //thermometerPaint;
  200. t1.setThermometerPaint(new GradientPaint(9f, 7f, Color.red, 5f, 1f, Color.blue));
  201. assertFalse(t1.equals(t2));
  202. t2.setThermometerPaint(new GradientPaint(9f, 7f, Color.red, 5f, 1f, Color.blue));
  203. assertTrue(t1.equals(t2));
  204. //wallPaint;
  205. t1.setWallPaint(new GradientPaint(4f, 5f, Color.red, 1f, 0f, Color.gray));
  206. assertFalse(t1.equals(t2));
  207. t2.setWallPaint(new GradientPaint(4f, 5f, Color.red, 1f, 0f, Color.gray));
  208. assertTrue(t1.equals(t2));
  209. //errorIndicatorPaint;
  210. t1.setErrorIndicatorPaint(new GradientPaint(0f, 1f, Color.white, 2f, 3f, Color.blue));
  211. assertFalse(t1.equals(t2));
  212. t2.setErrorIndicatorPaint(new GradientPaint(0f, 1f, Color.white, 2f, 3f, Color.blue));
  213. assertTrue(t1.equals(t2));
  214. //gridBandPaint
  215. t1.setGridBandPaint(new GradientPaint(1f, 2f, Color.white, 4f, 8f, Color.red));
  216. assertFalse(t1.equals(t2));
  217. t2.setGridBandPaint(new GradientPaint(1f, 2f, Color.white, 4f, 8f, Color.red));
  218. assertTrue(t1.equals(t2));
  219. //gridBandAlternatePaint
  220. t1.setGridBandAlternatePaint(new GradientPaint(1f, 4f, Color.green, 1f, 2f, Color.red));
  221. assertFalse(t1.equals(t2));
  222. t2.setGridBandAlternatePaint(new GradientPaint(1f, 4f, Color.green, 1f, 2f, Color.red));
  223. assertTrue(t1.equals(t2));
  224. }
  225. /**
  226. * Serialize an instance, restore it, and check for equality.
  227. */
  228. @Test
  229. public void testSerialization() {
  230. StandardChartTheme t1 = new StandardChartTheme("Name");
  231. StandardChartTheme t2 = (StandardChartTheme) TestUtilities.serialised(t1);
  232. assertTrue(t1.equals(t2));
  233. }
  234. /**
  235. * Basic checks for cloning.
  236. */
  237. @Test
  238. public void testCloning() throws CloneNotSupportedException {
  239. StandardChartTheme t1 = new StandardChartTheme("Name");
  240. StandardChartTheme t2 = (StandardChartTheme) t1.clone();
  241. assertTrue(t1 != t2);
  242. assertTrue(t1.getClass() == t2.getClass());
  243. assertTrue(t1.equals(t2));
  244. }
  245. }