ChartRenderingInfoTest.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. * ChartRenderingInfoTest.java
  29. * ---------------------------
  30. * (C) Copyright 2004-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. * 19-Mar-2004 : Version 1 (DG);
  38. * 30-Nov-2005 : Updated for removed field in ChartRenderingInfo (DG);
  39. *
  40. */
  41. package org.jfree.chart;
  42. import java.awt.Rectangle;
  43. import java.awt.geom.Rectangle2D;
  44. import static org.junit.Assert.assertEquals;
  45. import static org.junit.Assert.assertFalse;
  46. import static org.junit.Assert.assertNotSame;
  47. import static org.junit.Assert.assertSame;
  48. import org.jfree.chart.entity.ChartEntity;
  49. import org.jfree.chart.entity.StandardEntityCollection;
  50. import org.junit.Test;
  51. /**
  52. * Tests for the {@link ChartRenderingInfo} class.
  53. */
  54. public class ChartRenderingInfoTest {
  55. /**
  56. * Confirm that the equals method can distinguish all the required fields.
  57. */
  58. @Test
  59. public void testEquals() {
  60. ChartRenderingInfo i1 = new ChartRenderingInfo();
  61. ChartRenderingInfo i2 = new ChartRenderingInfo();
  62. assertEquals(i1, i2);
  63. i1.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
  64. assertFalse(i1.equals(i2));
  65. i2.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
  66. assertEquals(i1, i2);
  67. i1.getPlotInfo().setDataArea(new Rectangle(1, 2, 3, 4));
  68. assertFalse(i1.equals(i2));
  69. i2.getPlotInfo().setDataArea(new Rectangle(1, 2, 3, 4));
  70. assertEquals(i1, i2);
  71. StandardEntityCollection e1 = new StandardEntityCollection();
  72. e1.add(new ChartEntity(new Rectangle(1, 2, 3, 4)));
  73. i1.setEntityCollection(e1);
  74. assertFalse(i1.equals(i2));
  75. StandardEntityCollection e2 = new StandardEntityCollection();
  76. e2.add(new ChartEntity(new Rectangle(1, 2, 3, 4)));
  77. i2.setEntityCollection(e2);
  78. }
  79. /**
  80. * Confirm that cloning works.
  81. */
  82. @Test
  83. public void testCloning() throws CloneNotSupportedException {
  84. ChartRenderingInfo i1 = new ChartRenderingInfo();
  85. ChartRenderingInfo i2 = (ChartRenderingInfo) i1.clone();
  86. assertNotSame(i1, i2);
  87. assertSame(i1.getClass(), i2.getClass());
  88. assertEquals(i1, i2);
  89. // check independence
  90. i1.getChartArea().setRect(4.0, 3.0, 2.0, 1.0);
  91. assertFalse(i1.equals(i2));
  92. i2.getChartArea().setRect(4.0, 3.0, 2.0, 1.0);
  93. assertEquals(i1, i2);
  94. i1.getEntityCollection().add(new ChartEntity(new Rectangle(1, 2, 2,
  95. 1)));
  96. assertFalse(i1.equals(i2));
  97. i2.getEntityCollection().add(new ChartEntity(new Rectangle(1, 2, 2,
  98. 1)));
  99. assertEquals(i1, i2);
  100. }
  101. /**
  102. * Serialize an instance, restore it, and check for equality.
  103. */
  104. @Test
  105. public void testSerialization() {
  106. ChartRenderingInfo i1 = new ChartRenderingInfo();
  107. i1.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
  108. ChartRenderingInfo i2 = (ChartRenderingInfo) TestUtilities.serialised(i1);
  109. assertEquals(i1, i2);
  110. }
  111. /**
  112. * Serialize an instance, restore it, and check for equality.
  113. */
  114. @Test
  115. public void testSerialization2() {
  116. ChartRenderingInfo i1 = new ChartRenderingInfo();
  117. i1.getPlotInfo().setDataArea(new Rectangle2D.Double(1.0, 2.0, 3.0,
  118. 4.0));
  119. ChartRenderingInfo i2 = (ChartRenderingInfo) TestUtilities.serialised(i1);
  120. assertEquals(i1, i2);
  121. assertEquals(i2, i2.getPlotInfo().getOwner());
  122. }
  123. }