1 42 43 package org.jfree.data.gantt.junit; 44 45 import java.io.ByteArrayInputStream ; 46 import java.io.ByteArrayOutputStream ; 47 import java.io.ObjectInput ; 48 import java.io.ObjectInputStream ; 49 import java.io.ObjectOutput ; 50 import java.io.ObjectOutputStream ; 51 import java.util.Date ; 52 53 import junit.framework.Test; 54 import junit.framework.TestCase; 55 import junit.framework.TestSuite; 56 57 import org.jfree.data.gantt.Task; 58 import org.jfree.data.time.SimpleTimePeriod; 59 60 63 public class TaskTests extends TestCase { 64 65 70 public static Test suite() { 71 return new TestSuite(TaskTests.class); 72 } 73 74 79 public TaskTests(String name) { 80 super(name); 81 } 82 83 86 public void testEquals() { 87 88 Task t1 = new Task("T", new Date (1), new Date (2)); 89 Task t2 = new Task("T", new Date (1), new Date (2)); 90 assertTrue(t1.equals(t2)); 91 assertTrue(t2.equals(t1)); 92 93 t1.setDescription("X"); 94 assertFalse(t1.equals(t2)); 95 t2.setDescription("X"); 96 assertTrue(t1.equals(t2)); 97 98 t1.setDuration(new SimpleTimePeriod(new Date (2), new Date (3))); 99 assertFalse(t1.equals(t2)); 100 t2.setDuration(new SimpleTimePeriod(new Date (2), new Date (3))); 101 assertTrue(t1.equals(t2)); 102 103 t1.setPercentComplete(0.5); 104 assertFalse(t1.equals(t2)); 105 t2.setPercentComplete(0.5); 106 assertTrue(t1.equals(t2)); 107 108 t1.addSubtask(new Task("T", new Date (22), new Date (33))); 109 assertFalse(t1.equals(t2)); 110 t2.addSubtask(new Task("T", new Date (22), new Date (33))); 111 assertTrue(t1.equals(t2)); 112 113 114 } 115 116 119 public void testCloning() { 120 Task t1 = new Task("T", new Date (1), new Date (2)); 121 Task t2 = null; 122 try { 123 t2 = (Task) t1.clone(); 124 } 125 catch (CloneNotSupportedException e) { 126 System.err.println("Failed to clone."); 127 } 128 assertTrue(t1 != t2); 129 assertTrue(t1.getClass() == t2.getClass()); 130 assertTrue(t1.equals(t2)); 131 } 132 133 136 public void testSerialization() { 137 138 Task t1 = new Task("T", new Date (1), new Date (2)); 139 Task t2 = null; 140 141 try { 142 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 143 ObjectOutput out = new ObjectOutputStream (buffer); 144 out.writeObject(t1); 145 out.close(); 146 147 ObjectInput in = new ObjectInputStream ( 148 new ByteArrayInputStream (buffer.toByteArray()) 149 ); 150 t2 = (Task) in.readObject(); 151 in.close(); 152 } 153 catch (Exception e) { 154 System.out.println(e.toString()); 155 } 156 assertEquals(t1, t2); 157 158 } 159 160 163 public void testGetSubTaskCount() { 164 Task t1 = new Task("T", new Date (100), new Date (200)); 165 assertEquals(0, t1.getSubtaskCount()); 166 t1.addSubtask(new Task("S1", new Date (100), new Date (110))); 167 assertEquals(1, t1.getSubtaskCount()); 168 Task s2 = new Task("S2", new Date (111), new Date (120)); 169 t1.addSubtask(s2); 170 assertEquals(2, t1.getSubtaskCount()); 171 t1.addSubtask(new Task("S3", new Date (121), new Date (130))); 172 assertEquals(3, t1.getSubtaskCount()); 173 t1.removeSubtask(s2); 174 assertEquals(2, t1.getSubtaskCount()); 175 } 176 177 } 178 | Popular Tags |