1 42 43 package org.jfree.chart.renderer.category.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 52 import junit.framework.Test; 53 import junit.framework.TestCase; 54 import junit.framework.TestSuite; 55 56 import org.jfree.chart.renderer.category.StackedBarRenderer; 57 58 61 public class StackedBarRendererTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(StackedBarRendererTests.class); 70 } 71 72 77 public StackedBarRendererTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 StackedBarRenderer r1 = new StackedBarRenderer(); 86 StackedBarRenderer r2 = new StackedBarRenderer(); 87 assertTrue(r1.equals(r2)); 88 assertTrue(r2.equals(r1)); 89 90 r1.setRenderAsPercentages(true); 91 assertFalse(r1.equals(r2)); 92 r2.setRenderAsPercentages(true); 93 assertTrue(r1.equals(r2)); 94 } 95 96 99 public void testHashCode() { 100 StackedBarRenderer r1 = new StackedBarRenderer(); 101 StackedBarRenderer r2 = new StackedBarRenderer(); 102 assertTrue(r1.equals(r2)); 103 int h1 = r1.hashCode(); 104 int h2 = r2.hashCode(); 105 assertEquals(h1, h2); 106 } 107 108 111 public void testCloning() { 112 StackedBarRenderer r1 = new StackedBarRenderer(); 113 StackedBarRenderer r2 = null; 114 try { 115 r2 = (StackedBarRenderer) r1.clone(); 116 } 117 catch (CloneNotSupportedException e) { 118 System.err.println("Failed to clone."); 119 } 120 assertTrue(r1 != r2); 121 assertTrue(r1.getClass() == r2.getClass()); 122 assertTrue(r1.equals(r2)); 123 } 124 125 128 public void testSerialization() { 129 130 StackedBarRenderer r1 = new StackedBarRenderer(); 131 StackedBarRenderer r2 = null; 132 133 try { 134 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 135 ObjectOutput out = new ObjectOutputStream (buffer); 136 out.writeObject(r1); 137 out.close(); 138 139 ObjectInput in = new ObjectInputStream ( 140 new ByteArrayInputStream (buffer.toByteArray()) 141 ); 142 r2 = (StackedBarRenderer) in.readObject(); 143 in.close(); 144 } 145 catch (Exception e) { 146 System.out.println(e.toString()); 147 } 148 assertEquals(r1, r2); 149 150 } 151 152 } 153 | Popular Tags |