1 43 44 package org.jfree.chart.renderer.category.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.category.DefaultCategoryItemRenderer; 58 59 62 public class DefaultCategoryItemRendererTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(DefaultCategoryItemRendererTests.class); 71 } 72 73 78 public DefaultCategoryItemRendererTests(String name) { 79 super(name); 80 } 81 82 85 public void testEquals() { 86 DefaultCategoryItemRenderer r1 = new DefaultCategoryItemRenderer(); 87 DefaultCategoryItemRenderer r2 = new DefaultCategoryItemRenderer(); 88 assertEquals(r1, r2); 89 } 90 91 94 public void testHashcode() { 95 DefaultCategoryItemRenderer r1 = new DefaultCategoryItemRenderer(); 96 DefaultCategoryItemRenderer r2 = new DefaultCategoryItemRenderer(); 97 assertTrue(r1.equals(r2)); 98 int h1 = r1.hashCode(); 99 int h2 = r2.hashCode(); 100 assertEquals(h1, h2); 101 } 102 103 106 public void testCloning() { 107 DefaultCategoryItemRenderer r1 = new DefaultCategoryItemRenderer(); 108 DefaultCategoryItemRenderer r2 = null; 109 try { 110 r2 = (DefaultCategoryItemRenderer) r1.clone(); 111 } 112 catch (CloneNotSupportedException e) { 113 System.err.println("Failed to clone."); 114 } 115 assertTrue(r1 != r2); 116 assertTrue(r1.getClass() == r2.getClass()); 117 assertTrue(r1.equals(r2)); 118 } 119 120 123 public void testSerialization() { 124 125 DefaultCategoryItemRenderer r1 = new DefaultCategoryItemRenderer(); 126 DefaultCategoryItemRenderer r2 = null; 127 128 try { 129 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 130 ObjectOutput out = new ObjectOutputStream (buffer); 131 out.writeObject(r1); 132 out.close(); 133 134 ObjectInput in = new ObjectInputStream ( 135 new ByteArrayInputStream (buffer.toByteArray()) 136 ); 137 r2 = (DefaultCategoryItemRenderer) in.readObject(); 138 in.close(); 139 } 140 catch (Exception e) { 141 System.out.println(e.toString()); 142 } 143 assertEquals(r1, r2); 144 145 } 146 147 } 148 | Popular Tags |