TaskTest.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. * TaskTest.java
  29. * -------------
  30. * (C) Copyright 2004-2013, by Object Refinery Limited.
  31. *
  32. * Original Author: David Gilbert (for Object Refinery Limited);
  33. * Contributor(s): -;
  34. *
  35. * Changes
  36. * -------
  37. * 30-Jul-2004 : Version 1 (DG);
  38. *
  39. */
  40. package org.jfree.data.gantt;
  41. import java.util.Date;
  42. import org.jfree.chart.TestUtilities;
  43. import org.jfree.data.time.SimpleTimePeriod;
  44. import static org.junit.Assert.assertEquals;
  45. import static org.junit.Assert.assertFalse;
  46. import static org.junit.Assert.assertTrue;
  47. import org.junit.Test;
  48. /**
  49. * Tests for the {@link Task} class.
  50. */
  51. public class TaskTest {
  52. /**
  53. * Confirm that the equals method can distinguish all the required fields.
  54. */
  55. @Test
  56. public void testEquals() {
  57. Task t1 = new Task("T", new Date(1), new Date(2));
  58. Task t2 = new Task("T", new Date(1), new Date(2));
  59. assertTrue(t1.equals(t2));
  60. assertTrue(t2.equals(t1));
  61. t1.setDescription("X");
  62. assertFalse(t1.equals(t2));
  63. t2.setDescription("X");
  64. assertTrue(t1.equals(t2));
  65. t1.setDuration(new SimpleTimePeriod(new Date(2), new Date(3)));
  66. assertFalse(t1.equals(t2));
  67. t2.setDuration(new SimpleTimePeriod(new Date(2), new Date(3)));
  68. assertTrue(t1.equals(t2));
  69. t1.setPercentComplete(0.5);
  70. assertFalse(t1.equals(t2));
  71. t2.setPercentComplete(0.5);
  72. assertTrue(t1.equals(t2));
  73. t1.addSubtask(new Task("T", new Date(22), new Date(33)));
  74. assertFalse(t1.equals(t2));
  75. t2.addSubtask(new Task("T", new Date(22), new Date(33)));
  76. assertTrue(t1.equals(t2));
  77. }
  78. /**
  79. * Confirm that cloning works.
  80. */
  81. @Test
  82. public void testCloning() throws CloneNotSupportedException {
  83. Task t1 = new Task("T", new Date(1), new Date(2));
  84. Task t2 = (Task) t1.clone();
  85. assertTrue(t1 != t2);
  86. assertTrue(t1.getClass() == t2.getClass());
  87. assertTrue(t1.equals(t2));
  88. }
  89. /**
  90. * Serialize an instance, restore it, and check for equality.
  91. */
  92. @Test
  93. public void testSerialization() {
  94. Task t1 = new Task("T", new Date(1), new Date(2));
  95. Task t2 = (Task) TestUtilities.serialised(t1);
  96. assertEquals(t1, t2);
  97. }
  98. /**
  99. * Check the getSubTaskCount() method.
  100. */
  101. @Test
  102. public void testGetSubTaskCount() {
  103. Task t1 = new Task("T", new Date(100), new Date(200));
  104. assertEquals(0, t1.getSubtaskCount());
  105. t1.addSubtask(new Task("S1", new Date(100), new Date(110)));
  106. assertEquals(1, t1.getSubtaskCount());
  107. Task s2 = new Task("S2", new Date(111), new Date(120));
  108. t1.addSubtask(s2);
  109. assertEquals(2, t1.getSubtaskCount());
  110. t1.addSubtask(new Task("S3", new Date(121), new Date(130)));
  111. assertEquals(3, t1.getSubtaskCount());
  112. t1.removeSubtask(s2);
  113. assertEquals(2, t1.getSubtaskCount());
  114. }
  115. }