1 43 44 package org.jfree.chart.renderer.xy.junit; 45 46 import java.io.ByteArrayInputStream ; 47 import java.io.ByteArrayOutputStream ; 48 import java.io.ObjectInput ; 49 import java.io.ObjectInputStream ; 50 import java.io.ObjectOutput ; 51 import java.io.ObjectOutputStream ; 52 53 import junit.framework.Test; 54 import junit.framework.TestCase; 55 import junit.framework.TestSuite; 56 57 import org.jfree.chart.renderer.xy.ClusteredXYBarRenderer; 58 59 62 public class ClusteredXYBarRendererTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(ClusteredXYBarRendererTests.class); 71 } 72 73 78 public ClusteredXYBarRendererTests(String name) { 79 super(name); 80 } 81 82 85 public void testEquals() { 86 ClusteredXYBarRenderer r1 = new ClusteredXYBarRenderer(); 87 ClusteredXYBarRenderer r2 = new ClusteredXYBarRenderer(); 88 assertEquals(r1, r2); 89 assertEquals(r2, r1); 90 91 r1 = new ClusteredXYBarRenderer(1.2, false); 92 assertFalse(r1.equals(r2)); 93 r2 = new ClusteredXYBarRenderer(1.2, false); 94 assertTrue(r1.equals(r2)); 95 96 r1 = new ClusteredXYBarRenderer(1.2, true); 97 assertFalse(r1.equals(r2)); 98 r2 = new ClusteredXYBarRenderer(1.2, true); 99 assertTrue(r1.equals(r2)); 100 } 101 102 105 public void testHashcode() { 106 ClusteredXYBarRenderer r1 = new ClusteredXYBarRenderer(); 107 ClusteredXYBarRenderer r2 = new ClusteredXYBarRenderer(); 108 assertTrue(r1.equals(r2)); 109 int h1 = r1.hashCode(); 110 int h2 = r2.hashCode(); 111 assertEquals(h1, h2); 112 } 113 114 117 public void testCloning() { 118 ClusteredXYBarRenderer r1 = new ClusteredXYBarRenderer(); 119 ClusteredXYBarRenderer r2 = null; 120 try { 121 r2 = (ClusteredXYBarRenderer) r1.clone(); 122 } 123 catch (CloneNotSupportedException e) { 124 System.err.println("Failed to clone."); 125 } 126 assertTrue(r1 != r2); 127 assertTrue(r1.getClass() == r2.getClass()); 128 assertTrue(r1.equals(r2)); 129 } 130 131 134 public void testSerialization() { 135 136 ClusteredXYBarRenderer r1 = new ClusteredXYBarRenderer(); 137 ClusteredXYBarRenderer r2 = null; 138 139 try { 140 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 141 ObjectOutput out = new ObjectOutputStream (buffer); 142 out.writeObject(r1); 143 out.close(); 144 145 ObjectInput in = new ObjectInputStream ( 146 new ByteArrayInputStream (buffer.toByteArray()) 147 ); 148 r2 = (ClusteredXYBarRenderer) in.readObject(); 149 in.close(); 150 } 151 catch (Exception e) { 152 System.out.println(e.toString()); 153 } 154 assertEquals(r1, r2); 155 156 } 157 158 } 159 | Popular Tags |