GrayPaintScaleTest.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. * GrayPaintScaleTest.java
  29. * -----------------------
  30. * (C) Copyright 2006-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. * 05-Jul-2006 : Version 1 (DG);
  38. * 26-Sep-2007 : Added testConstructor() and testGetPaint() (DG);
  39. * 29-Jan-2009 : Extended testEquals() for new alpha field (DG);
  40. *
  41. */
  42. package org.jfree.chart.renderer;
  43. import static org.junit.Assert.assertEquals;
  44. import static org.junit.Assert.assertFalse;
  45. import static org.junit.Assert.assertTrue;
  46. import java.awt.Color;
  47. import org.jfree.chart.TestUtilities;
  48. import org.junit.Test;
  49. /**
  50. * Tests for the {@link GrayPaintScale} class.
  51. */
  52. public class GrayPaintScaleTest {
  53. private static final double EPSILON = 0.000000001;
  54. /**
  55. * Simple check for the default constructor.
  56. */
  57. @Test
  58. public void testConstructor() {
  59. GrayPaintScale gps = new GrayPaintScale();
  60. assertEquals(0.0, gps.getLowerBound(), EPSILON);
  61. assertEquals(1.0, gps.getUpperBound(), EPSILON);
  62. assertEquals(255, gps.getAlpha());
  63. }
  64. /**
  65. * Some checks for the getPaint() method.
  66. */
  67. @Test
  68. public void testGetPaint() {
  69. GrayPaintScale gps = new GrayPaintScale();
  70. Color c = (Color) gps.getPaint(0.0);
  71. assertTrue(c.equals(Color.black));
  72. c = (Color) gps.getPaint(1.0);
  73. assertTrue(c.equals(Color.white));
  74. // check lookup values that are outside the bounds - see bug report
  75. // 1767315
  76. c = (Color) gps.getPaint(-0.5);
  77. assertTrue(c.equals(Color.black));
  78. c = (Color) gps.getPaint(1.5);
  79. assertTrue(c.equals(Color.white));
  80. }
  81. /**
  82. * A test for the equals() method.
  83. */
  84. @Test
  85. public void testEquals() {
  86. GrayPaintScale g1 = new GrayPaintScale();
  87. GrayPaintScale g2 = new GrayPaintScale();
  88. assertTrue(g1.equals(g2));
  89. assertTrue(g2.equals(g1));
  90. g1 = new GrayPaintScale(0.0, 1.0);
  91. g2 = new GrayPaintScale(0.0, 1.0);
  92. assertTrue(g1.equals(g2));
  93. g1 = new GrayPaintScale(0.1, 1.0);
  94. assertFalse(g1.equals(g2));
  95. g2 = new GrayPaintScale(0.1, 1.0);
  96. assertTrue(g1.equals(g2));
  97. g1 = new GrayPaintScale(0.1, 0.9);
  98. assertFalse(g1.equals(g2));
  99. g2 = new GrayPaintScale(0.1, 0.9);
  100. assertTrue(g1.equals(g2));
  101. g1 = new GrayPaintScale(0.1, 0.9, 128);
  102. assertFalse(g1.equals(g2));
  103. g2 = new GrayPaintScale(0.1, 0.9, 128);
  104. assertTrue(g1.equals(g2));
  105. }
  106. /**
  107. * Confirm that cloning works.
  108. */
  109. @Test
  110. public void testCloning() throws CloneNotSupportedException {
  111. GrayPaintScale g1 = new GrayPaintScale();
  112. GrayPaintScale g2 = (GrayPaintScale) g1.clone();
  113. assertTrue(g1 != g2);
  114. assertTrue(g1.getClass() == g2.getClass());
  115. assertTrue(g1.equals(g2));
  116. }
  117. /**
  118. * Serialize an instance, restore it, and check for equality.
  119. */
  120. @Test
  121. public void testSerialization() {
  122. GrayPaintScale g1 = new GrayPaintScale();
  123. GrayPaintScale g2 = (GrayPaintScale) TestUtilities.serialised(g1);
  124. assertEquals(g1, g2);
  125. }
  126. }