1 44 45 package org.jfree.chart.renderer.category.junit; 46 47 import java.io.ByteArrayInputStream ; 48 import java.io.ByteArrayOutputStream ; 49 import java.io.ObjectInput ; 50 import java.io.ObjectInputStream ; 51 import java.io.ObjectOutput ; 52 import java.io.ObjectOutputStream ; 53 54 import junit.framework.Test; 55 import junit.framework.TestCase; 56 import junit.framework.TestSuite; 57 import org.jfree.chart.renderer.AreaRendererEndType; 58 59 import org.jfree.chart.renderer.category.AreaRenderer; 60 61 64 public class AreaRendererTests extends TestCase { 65 66 71 public static Test suite() { 72 return new TestSuite(AreaRendererTests.class); 73 } 74 75 80 public AreaRendererTests(String name) { 81 super(name); 82 } 83 84 87 public void testEquals() { 88 AreaRenderer r1 = new AreaRenderer(); 89 AreaRenderer r2 = new AreaRenderer(); 90 assertEquals(r1, r2); 91 92 r1.setEndType(AreaRendererEndType.LEVEL); 93 assertFalse(r1.equals(r2)); 94 r2.setEndType(AreaRendererEndType.LEVEL); 95 assertTrue(r1.equals(r2)); 96 } 97 98 101 public void testHashcode() { 102 AreaRenderer r1 = new AreaRenderer(); 103 AreaRenderer r2 = new AreaRenderer(); 104 assertTrue(r1.equals(r2)); 105 int h1 = r1.hashCode(); 106 int h2 = r2.hashCode(); 107 assertEquals(h1, h2); 108 } 109 110 113 public void testCloning() { 114 AreaRenderer r1 = new AreaRenderer(); 115 AreaRenderer r2 = null; 116 try { 117 r2 = (AreaRenderer) r1.clone(); 118 } 119 catch (CloneNotSupportedException e) { 120 e.printStackTrace(); 121 } 122 assertTrue(r1 != r2); 123 assertTrue(r1.getClass() == r2.getClass()); 124 assertTrue(r1.equals(r2)); 125 } 126 127 130 public void testSerialization() { 131 AreaRenderer r1 = new AreaRenderer(); 132 AreaRenderer r2 = null; 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 = (AreaRenderer) in.readObject(); 142 in.close(); 143 } 144 catch (Exception e) { 145 e.printStackTrace(); 146 } 147 assertEquals(r1, r2); 148 } 149 150 } 151 | Popular Tags |