StrokeMapTest.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. * StrokeMapTest.java
  29. * ------------------
  30. * (C) Copyright 2006-2013, by Object Refinery Limited.
  31. *
  32. * Original Author: David Gilbert (for Object Refinery Limited);
  33. * Contributor(s): -;
  34. *
  35. * Changes:
  36. * --------
  37. * 27-Sep-2006 : Version 1 (DG);
  38. *
  39. */
  40. package org.jfree.chart;
  41. import static org.junit.Assert.assertEquals;
  42. import static org.junit.Assert.assertTrue;
  43. import static org.junit.Assert.assertFalse;
  44. import java.awt.BasicStroke;
  45. import org.junit.Test;
  46. /**
  47. * Some tests for the {@link StrokeMap} class.
  48. */
  49. public class StrokeMapTest {
  50. /**
  51. * Some checks for the getStroke() method.
  52. */
  53. @Test
  54. public void testGetStroke() {
  55. StrokeMap m1 = new StrokeMap();
  56. assertEquals(null, m1.getStroke("A"));
  57. m1.put("A", new BasicStroke(1.1f));
  58. assertEquals(new BasicStroke(1.1f), m1.getStroke("A"));
  59. m1.put("A", null);
  60. assertEquals(null, m1.getStroke("A"));
  61. // a null key should throw an IllegalArgumentException
  62. boolean pass = false;
  63. try {
  64. m1.getStroke(null);
  65. }
  66. catch (IllegalArgumentException e) {
  67. pass = true;
  68. }
  69. assertTrue(pass);
  70. }
  71. /**
  72. * Some checks for the put() method.
  73. */
  74. @Test
  75. public void testPut() {
  76. StrokeMap m1 = new StrokeMap();
  77. m1.put("A", new BasicStroke(1.1f));
  78. assertEquals(new BasicStroke(1.1f), m1.getStroke("A"));
  79. // a null key should throw an IllegalArgumentException
  80. boolean pass = false;
  81. try {
  82. m1.put(null, new BasicStroke(1.1f));
  83. }
  84. catch (IllegalArgumentException e) {
  85. pass = true;
  86. }
  87. assertTrue(pass);
  88. }
  89. /**
  90. * Some checks for the equals() method.
  91. */
  92. @Test
  93. public void testEquals() {
  94. StrokeMap m1 = new StrokeMap();
  95. StrokeMap m2 = new StrokeMap();
  96. assertTrue(m1.equals(m1));
  97. assertTrue(m1.equals(m2));
  98. assertFalse(m1.equals(null));
  99. assertFalse(m1.equals("ABC"));
  100. m1.put("K1", new BasicStroke(1.1f));
  101. assertFalse(m1.equals(m2));
  102. m2.put("K1", new BasicStroke(1.1f));
  103. assertTrue(m1.equals(m2));
  104. m1.put("K2", new BasicStroke(2.2f));
  105. assertFalse(m1.equals(m2));
  106. m2.put("K2", new BasicStroke(2.2f));
  107. assertTrue(m1.equals(m2));
  108. m1.put("K2", null);
  109. assertFalse(m1.equals(m2));
  110. m2.put("K2", null);
  111. assertTrue(m1.equals(m2));
  112. }
  113. /**
  114. * Some checks for cloning.
  115. */
  116. @Test
  117. public void testCloning() throws CloneNotSupportedException {
  118. StrokeMap m1 = new StrokeMap();
  119. StrokeMap m2 = (StrokeMap) m1.clone();
  120. assertTrue(m1.equals(m2));
  121. m1.put("K1", new BasicStroke(1.1f));
  122. m1.put("K2", new BasicStroke(2.2f));
  123. m2 = (StrokeMap) m1.clone();
  124. assertTrue(m1.equals(m2));
  125. }
  126. /**
  127. * A check for serialization.
  128. */
  129. @Test
  130. public void testSerialization1() {
  131. StrokeMap m1 = new StrokeMap();
  132. StrokeMap m2 = (StrokeMap) TestUtilities.serialised(m1);
  133. assertEquals(m1, m2);
  134. }
  135. /**
  136. * A check for serialization.
  137. */
  138. @Test
  139. public void testSerialization2() {
  140. StrokeMap m1 = new StrokeMap();
  141. m1.put("K1", new BasicStroke(1.1f));
  142. m1.put("K2", new BasicStroke(2.2f));
  143. StrokeMap m2 = (StrokeMap) TestUtilities.serialised(m1);
  144. assertEquals(m1, m2);
  145. }
  146. }