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.StackedBarRenderer; 52 53 58 public class StackedBarRendererTests extends TestCase { 59 60 65 public static Test suite() { 66 return new TestSuite(StackedBarRendererTests.class); 67 } 68 69 74 public StackedBarRendererTests(String name) { 75 super(name); 76 } 77 78 81 public void testEquals() { 82 StackedBarRenderer r1 = new StackedBarRenderer(); 83 StackedBarRenderer r2 = new StackedBarRenderer(); 84 assertEquals(r1, r2); 85 } 86 87 90 public void testHashcode() { 91 StackedBarRenderer r1 = new StackedBarRenderer(); 92 StackedBarRenderer r2 = new StackedBarRenderer(); 93 assertTrue(r1.equals(r2)); 94 int h1 = r1.hashCode(); 95 int h2 = r2.hashCode(); 96 assertEquals(h1, h2); 97 } 98 99 102 public void testCloning() { 103 StackedBarRenderer r1 = new StackedBarRenderer(); 104 StackedBarRenderer r2 = null; 105 try { 106 r2 = (StackedBarRenderer) r1.clone(); 107 } 108 catch (CloneNotSupportedException e) { 109 System.err.println("StackedBarRendererTests.testCloning: failed to clone."); 110 } 111 assertTrue(r1 != r2); 112 assertTrue(r1.getClass() == r2.getClass()); 113 assertTrue(r1.equals(r2)); 114 } 115 116 119 public void testSerialization() { 120 121 StackedBarRenderer r1 = new StackedBarRenderer(); 122 StackedBarRenderer r2 = null; 123 124 try { 125 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 126 ObjectOutput out = new ObjectOutputStream (buffer); 127 out.writeObject(r1); 128 out.close(); 129 130 ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 131 r2 = (StackedBarRenderer) in.readObject(); 132 in.close(); 133 } 134 catch (Exception e) { 135 System.out.println(e.toString()); 136 } 137 assertEquals(r1, r2); 138 139 } 140 141 } 142 | Popular Tags |