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.gantt.TaskSeries; 59 60 63 public class TaskSeriesTests extends TestCase { 64 65 70 public static Test suite() { 71 return new TestSuite(TaskSeriesTests.class); 72 } 73 74 79 public TaskSeriesTests(String name) { 80 super(name); 81 } 82 83 86 public void testEquals() { 87 88 TaskSeries s1 = new TaskSeries("S"); 89 s1.add(new Task("T1", new Date (1), new Date (2))); 90 s1.add(new Task("T2", new Date (11), new Date (22))); 91 TaskSeries s2 = new TaskSeries("S"); 92 s2.add(new Task("T1", new Date (1), new Date (2))); 93 s2.add(new Task("T2", new Date (11), new Date (22))); 94 assertTrue(s1.equals(s2)); 95 assertTrue(s2.equals(s1)); 96 97 s1.add(new Task("T3", new Date (22), new Date (33))); 98 assertFalse(s1.equals(s2)); 99 s2.add(new Task("T3", new Date (22), new Date (33))); 100 assertTrue(s1.equals(s2)); 101 102 } 103 104 107 public void testCloning() { 108 TaskSeries s1 = new TaskSeries("S"); 109 s1.add(new Task("T1", new Date (1), new Date (2))); 110 s1.add(new Task("T2", new Date (11), new Date (22))); 111 TaskSeries s2 = null; 112 try { 113 s2 = (TaskSeries) s1.clone(); 114 } 115 catch (CloneNotSupportedException e) { 116 System.err.println("Failed to clone."); 117 } 118 assertTrue(s1 != s2); 119 assertTrue(s1.getClass() == s2.getClass()); 120 assertTrue(s1.equals(s2)); 121 } 122 123 126 public void testSerialization() { 127 128 TaskSeries s1 = new TaskSeries("S"); 129 s1.add(new Task("T1", new Date (1), new Date (2))); 130 s1.add(new Task("T2", new Date (11), new Date (22))); 131 TaskSeries s2 = null; 132 133 try { 134 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 135 ObjectOutput out = new ObjectOutputStream (buffer); 136 out.writeObject(s1); 137 out.close(); 138 139 ObjectInput in = new ObjectInputStream ( 140 new ByteArrayInputStream (buffer.toByteArray()) 141 ); 142 s2 = (TaskSeries) in.readObject(); 143 in.close(); 144 } 145 catch (Exception e) { 146 System.out.println(e.toString()); 147 } 148 assertEquals(s1, s2); 149 150 } 151 152 155 public void testGetTask() { 156 TaskSeries s1 = new TaskSeries("S"); 157 s1.add(new Task("T1", new Date (1), new Date (2))); 158 s1.add(new Task("T2", new Date (11), new Date (22))); 159 Task t1 = s1.get("T1"); 160 assertTrue(t1.equals(new Task("T1", new Date (1), new Date (2)))); 161 Task t2 = s1.get("T2"); 162 assertTrue(t2.equals(new Task("T2", new Date (11), new Date (22)))); 163 Task t3 = s1.get("T3"); 164 assertTrue(t3 == null); 165 } 166 167 } 168 | Popular Tags |