XYLine3DRendererTest.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. * XYLine3DRendererTest.java
  29. * -------------------------
  30. * (C) Copyright 2007-2013, by Object Refinery Limited.
  31. *
  32. * Original Author: David Gilbert (for Object Refinery Limited);
  33. * Contributor(s): -;
  34. *
  35. * Changes
  36. * -------
  37. * 30-Apr-2007 : Version 1 (DG);
  38. * 22-Apr-2008 : Added testPublicCloneable (DG);
  39. *
  40. */
  41. package org.jfree.chart.renderer.xy;
  42. import static org.junit.Assert.assertEquals;
  43. import static org.junit.Assert.assertTrue;
  44. import static org.junit.Assert.assertFalse;
  45. import java.awt.Color;
  46. import java.awt.GradientPaint;
  47. import org.jfree.chart.TestUtilities;
  48. import org.jfree.util.PublicCloneable;
  49. import org.junit.Test;
  50. /**
  51. * Tests for the {@link XYLine3DRenderer} class.
  52. */
  53. public class XYLine3DRendererTest {
  54. /**
  55. * Check that the equals() method distinguishes all fields.
  56. */
  57. @Test
  58. public void testEquals() {
  59. XYLine3DRenderer r1 = new XYLine3DRenderer();
  60. XYLine3DRenderer r2 = new XYLine3DRenderer();
  61. assertEquals(r1, r2);
  62. r1.setXOffset(11.1);
  63. assertFalse(r1.equals(r2));
  64. r2.setXOffset(11.1);
  65. assertTrue(r1.equals(r2));
  66. r1.setYOffset(11.1);
  67. assertFalse(r1.equals(r2));
  68. r2.setYOffset(11.1);
  69. assertTrue(r1.equals(r2));
  70. r1.setWallPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f,
  71. 4.0f, Color.blue));
  72. assertFalse(r1.equals(r2));
  73. r2.setWallPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f,
  74. 4.0f, Color.blue));
  75. assertTrue(r1.equals(r2));
  76. }
  77. /**
  78. * Two objects that are equal are required to return the same hashCode.
  79. */
  80. @Test
  81. public void testHashcode() {
  82. XYLine3DRenderer r1 = new XYLine3DRenderer();
  83. XYLine3DRenderer r2 = new XYLine3DRenderer();
  84. assertTrue(r1.equals(r2));
  85. int h1 = r1.hashCode();
  86. int h2 = r2.hashCode();
  87. assertEquals(h1, h2);
  88. }
  89. /**
  90. * Confirm that cloning works.
  91. */
  92. @Test
  93. public void testCloning() throws CloneNotSupportedException {
  94. XYLine3DRenderer r1 = new XYLine3DRenderer();
  95. r1.setWallPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
  96. Color.blue));
  97. XYLine3DRenderer r2 = (XYLine3DRenderer) r1.clone();
  98. assertTrue(r1 != r2);
  99. assertTrue(r1.getClass() == r2.getClass());
  100. assertTrue(r1.equals(r2));
  101. }
  102. /**
  103. * Verify that this class implements {@link PublicCloneable}.
  104. */
  105. @Test
  106. public void testPublicCloneable() {
  107. XYLine3DRenderer r1 = new XYLine3DRenderer();
  108. assertTrue(r1 instanceof PublicCloneable);
  109. }
  110. /**
  111. * Serialize an instance, restore it, and check for equality.
  112. */
  113. @Test
  114. public void testSerialization() {
  115. XYLine3DRenderer r1 = new XYLine3DRenderer();
  116. r1.setWallPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
  117. Color.blue));
  118. XYLine3DRenderer r2 = (XYLine3DRenderer) TestUtilities.serialised(r1);
  119. assertEquals(r1, r2);
  120. }
  121. }