ThermometerPlotTest.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. * ThermometerPlotTest.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. * 26-Mar-2003 : Version 1 (DG);
  38. * 30-Apr-2007 : Added new serialization test (DG);
  39. * 03-May-2007 : Added cloning test (DG);
  40. * 08-Oct-2007 : Updated testEquals() for new fields (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.BasicStroke;
  48. import java.awt.Color;
  49. import java.awt.Font;
  50. import java.awt.GradientPaint;
  51. import java.text.DecimalFormat;
  52. import org.jfree.chart.TestUtilities;
  53. import org.jfree.ui.RectangleInsets;
  54. import org.junit.Test;
  55. /**
  56. * Tests for the {@link ThermometerPlot} class.
  57. */
  58. public class ThermometerPlotTest {
  59. /**
  60. * Some checks for the equals() method.
  61. */
  62. @Test
  63. public void testEquals() {
  64. ThermometerPlot p1 = new ThermometerPlot();
  65. ThermometerPlot p2 = new ThermometerPlot();
  66. assertTrue(p1.equals(p2));
  67. assertTrue(p2.equals(p1));
  68. // padding
  69. p1.setPadding(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
  70. assertFalse(p1.equals(p2));
  71. p2.setPadding(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
  72. assertTrue(p2.equals(p1));
  73. // thermometerStroke
  74. BasicStroke s = new BasicStroke(1.23f);
  75. p1.setThermometerStroke(s);
  76. assertFalse(p1.equals(p2));
  77. p2.setThermometerStroke(s);
  78. assertTrue(p2.equals(p1));
  79. // thermometerPaint
  80. p1.setThermometerPaint(new GradientPaint(1.0f, 2.0f, Color.blue,
  81. 3.0f, 4.0f, Color.red));
  82. assertFalse(p1.equals(p2));
  83. p2.setThermometerPaint(new GradientPaint(1.0f, 2.0f, Color.blue,
  84. 3.0f, 4.0f, Color.red));
  85. assertTrue(p2.equals(p1));
  86. // units
  87. p1.setUnits(ThermometerPlot.UNITS_KELVIN);
  88. assertFalse(p1.equals(p2));
  89. p2.setUnits(ThermometerPlot.UNITS_KELVIN);
  90. assertTrue(p2.equals(p1));
  91. // valueLocation
  92. p1.setValueLocation(ThermometerPlot.LEFT);
  93. assertFalse(p1.equals(p2));
  94. p2.setValueLocation(ThermometerPlot.LEFT);
  95. assertTrue(p2.equals(p1));
  96. // axisLocation
  97. p1.setAxisLocation(ThermometerPlot.RIGHT);
  98. assertFalse(p1.equals(p2));
  99. p2.setAxisLocation(ThermometerPlot.RIGHT);
  100. assertTrue(p2.equals(p1));
  101. // valueFont
  102. p1.setValueFont(new Font("Serif", Font.PLAIN, 9));
  103. assertFalse(p1.equals(p2));
  104. p2.setValueFont(new Font("Serif", Font.PLAIN, 9));
  105. assertTrue(p2.equals(p1));
  106. // valuePaint
  107. p1.setValuePaint(new GradientPaint(4.0f, 5.0f, Color.red,
  108. 6.0f, 7.0f, Color.white));
  109. assertFalse(p1.equals(p2));
  110. p2.setValuePaint(new GradientPaint(4.0f, 5.0f, Color.red,
  111. 6.0f, 7.0f, Color.white));
  112. assertTrue(p2.equals(p1));
  113. // valueFormat
  114. p1.setValueFormat(new DecimalFormat("0.0000"));
  115. assertFalse(p1.equals(p2));
  116. p2.setValueFormat(new DecimalFormat("0.0000"));
  117. assertTrue(p2.equals(p1));
  118. // mercuryPaint
  119. p1.setMercuryPaint(new GradientPaint(9.0f, 8.0f, Color.red,
  120. 7.0f, 6.0f, Color.blue));
  121. assertFalse(p1.equals(p2));
  122. p2.setMercuryPaint(new GradientPaint(9.0f, 8.0f, Color.red,
  123. 7.0f, 6.0f, Color.blue));
  124. assertTrue(p2.equals(p1));
  125. // showValueLines
  126. p1.setShowValueLines(true);
  127. assertFalse(p1.equals(p2));
  128. p2.setShowValueLines(true);
  129. assertTrue(p2.equals(p1));
  130. p1.setSubrange(1, 1.0, 2.0);
  131. assertFalse(p1.equals(p2));
  132. p2.setSubrange(1, 1.0, 2.0);
  133. assertTrue(p2.equals(p1));
  134. p1.setSubrangePaint(1, new GradientPaint(1.0f, 2.0f, Color.red,
  135. 3.0f, 4.0f, Color.yellow));
  136. assertFalse(p1.equals(p2));
  137. p2.setSubrangePaint(1, new GradientPaint(1.0f, 2.0f, Color.red,
  138. 3.0f, 4.0f, Color.yellow));
  139. assertTrue(p2.equals(p1));
  140. p1.setBulbRadius(9);
  141. assertFalse(p1.equals(p2));
  142. p2.setBulbRadius(9);
  143. assertTrue(p2.equals(p1));
  144. p1.setColumnRadius(8);
  145. assertFalse(p1.equals(p2));
  146. p2.setColumnRadius(8);
  147. assertTrue(p2.equals(p1));
  148. p1.setGap(7);
  149. assertFalse(p1.equals(p2));
  150. p2.setGap(7);
  151. assertTrue(p2.equals(p1));
  152. }
  153. /**
  154. * Confirm that cloning works.
  155. */
  156. @Test
  157. public void testCloning() throws CloneNotSupportedException {
  158. ThermometerPlot p1 = new ThermometerPlot();
  159. ThermometerPlot p2 = (ThermometerPlot) p1.clone();
  160. assertTrue(p1 != p2);
  161. assertTrue(p1.getClass() == p2.getClass());
  162. assertTrue(p1.equals(p2));
  163. }
  164. /**
  165. * Serialize an instance, restore it, and check for equality.
  166. */
  167. @Test
  168. public void testSerialization() {
  169. ThermometerPlot p1 = new ThermometerPlot();
  170. ThermometerPlot p2 = (ThermometerPlot) TestUtilities.serialised(p1);
  171. assertTrue(p1.equals(p2));
  172. }
  173. /**
  174. * Serialize an instance, restore it, and check for equality.
  175. */
  176. @Test
  177. public void testSerialization2() {
  178. ThermometerPlot p1 = new ThermometerPlot();
  179. p1.setSubrangePaint(1, new GradientPaint(1.0f, 2.0f, Color.red, 3.0f,
  180. 4.0f, Color.blue));
  181. ThermometerPlot p2 = (ThermometerPlot) TestUtilities.serialised(p1);
  182. assertTrue(p1.equals(p2));
  183. }
  184. /**
  185. * Some checks for the setUnits() method.
  186. */
  187. @Test
  188. public void testSetUnits() {
  189. ThermometerPlot p1 = new ThermometerPlot();
  190. assertEquals(ThermometerPlot.UNITS_CELCIUS, p1.getUnits());
  191. p1.setUnits("FAHRENHEIT"); // this doesn't work
  192. assertEquals(ThermometerPlot.UNITS_CELCIUS, p1.getUnits());
  193. p1.setUnits("\u00B0F"); // ...but this does!
  194. assertEquals(ThermometerPlot.UNITS_FAHRENHEIT, p1.getUnits());
  195. }
  196. }