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.StackedAreaRenderer; 57 58 61 public class StackedAreaRendererTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(StackedAreaRendererTests.class); 70 } 71 72 77 public StackedAreaRendererTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 StackedAreaRenderer r1 = new StackedAreaRenderer(); 86 StackedAreaRenderer r2 = new StackedAreaRenderer(); 87 assertEquals(r1, r2); 88 89 r1.setRenderAsPercentages(true); 90 assertFalse(r1.equals(r2)); 91 r2.setRenderAsPercentages(true); 92 assertTrue(r1.equals(r2)); 93 } 94 95 98 public void testHashcode() { 99 StackedAreaRenderer r1 = new StackedAreaRenderer(); 100 StackedAreaRenderer r2 = new StackedAreaRenderer(); 101 assertTrue(r1.equals(r2)); 102 int h1 = r1.hashCode(); 103 int h2 = r2.hashCode(); 104 assertEquals(h1, h2); 105 } 106 107 110 public void testCloning() { 111 StackedAreaRenderer r1 = new StackedAreaRenderer(); 112 StackedAreaRenderer r2 = null; 113 try { 114 r2 = (StackedAreaRenderer) r1.clone(); 115 } 116 catch (CloneNotSupportedException e) { 117 e.printStackTrace(); 118 } 119 assertTrue(r1 != r2); 120 assertTrue(r1.getClass() == r2.getClass()); 121 assertTrue(r1.equals(r2)); 122 123 } 124 125 128 public void testSerialization() { 129 130 StackedAreaRenderer r1 = new StackedAreaRenderer(); 131 StackedAreaRenderer 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 r2 = (StackedAreaRenderer) in.readObject(); 142 in.close(); 143 } 144 catch (Exception e) { 145 e.printStackTrace(); 146 } 147 assertEquals(r1, r2); 148 149 } 150 151 } 152 | Popular Tags |