1 38 39 package org.jfree.chart.renderer.junit; 40 41 import java.io.ByteArrayInputStream ; 42 import java.io.ByteArrayOutputStream ; 43 import java.io.ObjectInput ; 44 import java.io.ObjectInputStream ; 45 import java.io.ObjectOutput ; 46 import java.io.ObjectOutputStream ; 47 48 import junit.framework.Test; 49 import junit.framework.TestCase; 50 import junit.framework.TestSuite; 51 52 import org.jfree.chart.renderer.DefaultCategoryItemRenderer; 53 54 59 public class DefaultCategoryItemRendererTests extends TestCase { 60 61 66 public static Test suite() { 67 return new TestSuite(DefaultCategoryItemRendererTests.class); 68 } 69 70 75 public DefaultCategoryItemRendererTests(String name) { 76 super(name); 77 } 78 79 82 public void testEquals() { 83 DefaultCategoryItemRenderer r1 = new DefaultCategoryItemRenderer(); 84 DefaultCategoryItemRenderer r2 = new DefaultCategoryItemRenderer(); 85 assertEquals(r1, r2); 86 87 } 88 89 92 public void testHashcode() { 93 DefaultCategoryItemRenderer r1 = new DefaultCategoryItemRenderer(); 94 DefaultCategoryItemRenderer r2 = new DefaultCategoryItemRenderer(); 95 assertTrue(r1.equals(r2)); 96 int h1 = r1.hashCode(); 97 int h2 = r2.hashCode(); 98 assertEquals(h1, h2); 99 } 100 101 104 public void testCloning() { 105 DefaultCategoryItemRenderer r1 = new DefaultCategoryItemRenderer(); 106 DefaultCategoryItemRenderer r2 = null; 107 try { 108 r2 = (DefaultCategoryItemRenderer) r1.clone(); 109 } 110 catch (CloneNotSupportedException e) { 111 System.err.println("DefaultCategoryItemRendererTests.testCloning: failed to clone."); 112 } 113 assertTrue(r1 != r2); 114 assertTrue(r1.getClass() == r2.getClass()); 115 assertTrue(r1.equals(r2)); 116 } 117 118 121 public void testSerialization() { 122 123 DefaultCategoryItemRenderer r1 = new DefaultCategoryItemRenderer(); 124 DefaultCategoryItemRenderer r2 = null; 125 126 try { 127 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 128 ObjectOutput out = new ObjectOutputStream (buffer); 129 out.writeObject(r1); 130 out.close(); 131 132 ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 133 r2 = (DefaultCategoryItemRenderer) in.readObject(); 134 in.close(); 135 } 136 catch (Exception e) { 137 System.out.println(e.toString()); 138 } 139 assertEquals(r1, r2); 140 141 } 142 143 } 144 | Popular Tags |