DefaultDrawingSupplierTest.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. * DefaultDrawingSupplierTest.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. * 25-Mar-2003 : Version 1 (DG);
  38. *
  39. */
  40. package org.jfree.chart.plot;
  41. import static org.junit.Assert.assertEquals;
  42. import static org.junit.Assert.assertFalse;
  43. import static org.junit.Assert.assertTrue;
  44. import java.awt.BasicStroke;
  45. import java.awt.Color;
  46. import java.awt.Paint;
  47. import java.awt.Shape;
  48. import java.awt.Stroke;
  49. import java.awt.geom.Rectangle2D;
  50. import org.jfree.chart.TestUtilities;
  51. import org.junit.Test;
  52. /**
  53. * Tests for the {@link DefaultDrawingSupplier} class.
  54. */
  55. public class DefaultDrawingSupplierTest {
  56. /**
  57. * Check that the equals() method can distinguish all required fields.
  58. */
  59. @Test
  60. public void testEquals() {
  61. DefaultDrawingSupplier r1 = new DefaultDrawingSupplier();
  62. DefaultDrawingSupplier r2 = new DefaultDrawingSupplier();
  63. assertTrue(r1.equals(r2));
  64. assertTrue(r2.equals(r1));
  65. // set up some objects...
  66. Paint[] ps1A = new Paint[] {Color.red, Color.blue};
  67. Paint[] ps2A = new Paint[] {Color.green, Color.yellow, Color.white};
  68. Paint[] ops1A = new Paint[] {Color.lightGray, Color.blue};
  69. Paint[] ops2A = new Paint[] {Color.black, Color.yellow, Color.cyan};
  70. Stroke[] ss1A = new Stroke[] {new BasicStroke(1.1f)};
  71. Stroke[] ss2A
  72. = new Stroke[] {new BasicStroke(2.2f), new BasicStroke(3.3f)};
  73. Stroke[] oss1A = new Stroke[] {new BasicStroke(4.4f)};
  74. Stroke[] oss2A
  75. = new Stroke[] {new BasicStroke(5.5f), new BasicStroke(6.6f)};
  76. Shape[] shapes1A = new Shape[] {
  77. new Rectangle2D.Double(1.0, 1.0, 1.0, 1.0)
  78. };
  79. Shape[] shapes2A = new Shape[] {
  80. new Rectangle2D.Double(2.0, 2.0, 2.0, 2.0),
  81. new Rectangle2D.Double(2.0, 2.0, 2.0, 2.0)
  82. };
  83. Paint[] ps1B = new Paint[] {Color.red, Color.blue};
  84. Paint[] ps2B = new Paint[] {Color.green, Color.yellow, Color.white};
  85. Paint[] ops1B = new Paint[] {Color.lightGray, Color.blue};
  86. Paint[] ops2B = new Paint[] {Color.black, Color.yellow, Color.cyan};
  87. Stroke[] ss1B = new Stroke[] {new BasicStroke(1.1f)};
  88. Stroke[] ss2B
  89. = new Stroke[] {new BasicStroke(2.2f), new BasicStroke(3.3f)};
  90. Stroke[] oss1B = new Stroke[] {new BasicStroke(4.4f)};
  91. Stroke[] oss2B
  92. = new Stroke[] {new BasicStroke(5.5f), new BasicStroke(6.6f)};
  93. Shape[] shapes1B = new Shape[] {
  94. new Rectangle2D.Double(1.0, 1.0, 1.0, 1.0)
  95. };
  96. Shape[] shapes2B = new Shape[] {
  97. new Rectangle2D.Double(2.0, 2.0, 2.0, 2.0),
  98. new Rectangle2D.Double(2.0, 2.0, 2.0, 2.0)
  99. };
  100. r1 = new DefaultDrawingSupplier(ps1A, ops1A, ss1A, oss1A, shapes1A);
  101. r2 = new DefaultDrawingSupplier(ps1B, ops1B, ss1B, oss1B, shapes1B);
  102. assertTrue(r1.equals(r2));
  103. // paint sequence
  104. r1 = new DefaultDrawingSupplier(ps2A, ops1A, ss1A, oss1A, shapes1A);
  105. assertFalse(r1.equals(r2));
  106. r2 = new DefaultDrawingSupplier(ps2B, ops1B, ss1B, oss1B, shapes1B);
  107. assertTrue(r1.equals(r2));
  108. // outline paint sequence
  109. r1 = new DefaultDrawingSupplier(ps2A, ops2A, ss1A, oss1A, shapes1A);
  110. assertFalse(r1.equals(r2));
  111. r2 = new DefaultDrawingSupplier(ps2B, ops2B, ss1B, oss1B, shapes1B);
  112. assertTrue(r1.equals(r2));
  113. // stroke sequence
  114. r1 = new DefaultDrawingSupplier(ps2A, ops2A, ss2A, oss1A, shapes1A);
  115. assertFalse(r1.equals(r2));
  116. r2 = new DefaultDrawingSupplier(ps2B, ops2B, ss2B, oss1B, shapes1B);
  117. assertTrue(r1.equals(r2));
  118. // outline stroke sequence
  119. r1 = new DefaultDrawingSupplier(ps2A, ops2A, ss2A, oss2A, shapes1A);
  120. assertFalse(r1.equals(r2));
  121. r2 = new DefaultDrawingSupplier(ps2B, ops2B, ss2B, oss2B, shapes1B);
  122. assertTrue(r1.equals(r2));
  123. // shape sequence
  124. r1 = new DefaultDrawingSupplier(ps2A, ops2A, ss2A, oss2A, shapes2A);
  125. assertFalse(r1.equals(r2));
  126. r2 = new DefaultDrawingSupplier(ps2B, ops2B, ss2B, oss2B, shapes2B);
  127. assertTrue(r1.equals(r2));
  128. // paint index
  129. r1.getNextPaint();
  130. assertFalse(r1.equals(r2));
  131. r2.getNextPaint();
  132. assertTrue(r1.equals(r2));
  133. // outline paint index
  134. r1.getNextOutlinePaint();
  135. assertFalse(r1.equals(r2));
  136. r2.getNextOutlinePaint();
  137. assertTrue(r1.equals(r2));
  138. // stroke index
  139. r1.getNextStroke();
  140. assertFalse(r1.equals(r2));
  141. r2.getNextStroke();
  142. assertTrue(r1.equals(r2));
  143. // outline stroke index
  144. r1.getNextOutlineStroke();
  145. assertFalse(r1.equals(r2));
  146. r2.getNextOutlineStroke();
  147. assertTrue(r1.equals(r2));
  148. // shape index
  149. r1.getNextShape();
  150. assertFalse(r1.equals(r2));
  151. r2.getNextShape();
  152. assertTrue(r1.equals(r2));
  153. }
  154. /**
  155. * Some basic checks for the clone() method.
  156. */
  157. @Test
  158. public void testCloning() throws CloneNotSupportedException {
  159. DefaultDrawingSupplier r1 = new DefaultDrawingSupplier();
  160. DefaultDrawingSupplier r2 = (DefaultDrawingSupplier) r1.clone();
  161. assertTrue(r1 != r2);
  162. assertTrue(r1.getClass() == r2.getClass());
  163. assertTrue(r1.equals(r2));
  164. }
  165. /**
  166. * Serialize an instance, restore it, and check for equality.
  167. */
  168. @Test
  169. public void testSerialization() {
  170. DefaultDrawingSupplier r1 = new DefaultDrawingSupplier();
  171. DefaultDrawingSupplier r2 = (DefaultDrawingSupplier)
  172. TestUtilities.serialised(r1);
  173. assertEquals(r1, r2);
  174. }
  175. }