DefaultKeyedValues2DDatasetTest.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. * DefaultKeyedValues2DDatasetTest.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. * 13-Mar-2003 : Version 1 (DG);
  38. *
  39. */
  40. package org.jfree.data.general;
  41. import org.jfree.chart.TestUtilities;
  42. import org.junit.Test;
  43. import static org.junit.Assert.assertTrue;
  44. import static org.junit.Assert.assertEquals;
  45. /**
  46. * Tests for the {@link DefaultKeyedValues2DDataset} class.
  47. */
  48. public class DefaultKeyedValues2DDatasetTest {
  49. /**
  50. * Confirm that cloning works.
  51. */
  52. @Test
  53. public void testCloning() throws CloneNotSupportedException {
  54. DefaultKeyedValues2DDataset d1 = new DefaultKeyedValues2DDataset();
  55. d1.setValue(new Integer(1), "V1", "C1");
  56. d1.setValue(null, "V2", "C1");
  57. d1.setValue(new Integer(3), "V3", "C2");
  58. DefaultKeyedValues2DDataset d2 = (DefaultKeyedValues2DDataset)
  59. d1.clone();
  60. assertTrue(d1 != d2);
  61. assertTrue(d1.getClass() == d2.getClass());
  62. assertTrue(d1.equals(d2));
  63. }
  64. /**
  65. * Serialize an instance, restore it, and check for equality.
  66. */
  67. public void testSerialization() {
  68. DefaultKeyedValues2DDataset d1 = new DefaultKeyedValues2DDataset();
  69. d1.addValue(new Double(234.2), "Row1", "Col1");
  70. d1.addValue(null, "Row1", "Col2");
  71. d1.addValue(new Double(345.9), "Row2", "Col1");
  72. d1.addValue(new Double(452.7), "Row2", "Col2");
  73. DefaultKeyedValues2DDataset d2 = (DefaultKeyedValues2DDataset)
  74. TestUtilities.serialised(d1);
  75. assertEquals(d1, d2);
  76. }
  77. }