1 37 38 package org.jfree.chart.renderer.junit; 39 40 import java.io.ByteArrayInputStream ; 41 import java.io.ByteArrayOutputStream ; 42 import java.io.ObjectInput ; 43 import java.io.ObjectInputStream ; 44 import java.io.ObjectOutput ; 45 import java.io.ObjectOutputStream ; 46 47 import junit.framework.Test; 48 import junit.framework.TestCase; 49 import junit.framework.TestSuite; 50 51 import org.jfree.chart.renderer.GanttRenderer; 52 53 58 public class GanttRendererTests extends TestCase { 59 60 65 public static Test suite() { 66 return new TestSuite(GanttRendererTests.class); 67 } 68 69 74 public GanttRendererTests(String name) { 75 super(name); 76 } 77 78 81 public void testEquals() { 82 GanttRenderer r1 = new GanttRenderer(); 83 GanttRenderer r2 = new GanttRenderer(); 84 assertEquals(r1, r2); 85 86 } 87 88 91 public void testHashcode() { 92 GanttRenderer r1 = new GanttRenderer(); 93 GanttRenderer r2 = new GanttRenderer(); 94 assertTrue(r1.equals(r2)); 95 int h1 = r1.hashCode(); 96 int h2 = r2.hashCode(); 97 assertEquals(h1, h2); 98 } 99 100 103 public void testCloning() { 104 GanttRenderer r1 = new GanttRenderer(); 105 GanttRenderer r2 = null; 106 try { 107 r2 = (GanttRenderer) r1.clone(); 108 } 109 catch (CloneNotSupportedException e) { 110 System.err.println("GanttRendererTests.testCloning: failed to clone."); 111 } 112 assertTrue(r1 != r2); 113 assertTrue(r1.getClass() == r2.getClass()); 114 assertTrue(r1.equals(r2)); 115 } 116 117 120 public void testSerialization() { 121 122 GanttRenderer r1 = new GanttRenderer(); 123 GanttRenderer r2 = null; 124 125 try { 126 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 127 ObjectOutput out = new ObjectOutputStream (buffer); 128 out.writeObject(r1); 129 out.close(); 130 131 ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 132 r2 = (GanttRenderer) in.readObject(); 133 in.close(); 134 } 135 catch (Exception e) { 136 System.out.println(e.toString()); 137 } 138 assertEquals(r1, r2); 139 140 } 141 142 } 143 | Popular Tags |