1 42 43 package org.jfree.chart.labels.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.labels.SymbolicXYItemLabelGenerator; 57 58 61 public class SymbolicXYItemLabelGeneratorTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(SymbolicXYItemLabelGeneratorTests.class); 70 } 71 72 77 public SymbolicXYItemLabelGeneratorTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 SymbolicXYItemLabelGenerator g1 = new SymbolicXYItemLabelGenerator(); 86 SymbolicXYItemLabelGenerator g2 = new SymbolicXYItemLabelGenerator(); 87 assertTrue(g1.equals(g2)); 88 assertTrue(g2.equals(g1)); 89 } 90 91 94 public void testCloning() { 95 SymbolicXYItemLabelGenerator g1 = new SymbolicXYItemLabelGenerator(); 96 SymbolicXYItemLabelGenerator g2 = null; 97 try { 98 g2 = (SymbolicXYItemLabelGenerator) g1.clone(); 99 } 100 catch (CloneNotSupportedException e) { 101 System.err.println("Failed to clone."); 102 } 103 assertTrue(g1 != g2); 104 assertTrue(g1.getClass() == g2.getClass()); 105 assertTrue(g1.equals(g2)); 106 } 107 108 111 public void testSerialization() { 112 SymbolicXYItemLabelGenerator g1 = new SymbolicXYItemLabelGenerator(); 113 SymbolicXYItemLabelGenerator g2 = null; 114 115 try { 116 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 117 ObjectOutput out = new ObjectOutputStream (buffer); 118 out.writeObject(g1); 119 out.close(); 120 121 ObjectInput in = new ObjectInputStream ( 122 new ByteArrayInputStream (buffer.toByteArray()) 123 ); 124 g2 = (SymbolicXYItemLabelGenerator) in.readObject(); 125 in.close(); 126 } 127 catch (Exception e) { 128 System.out.println(e.toString()); 129 } 130 assertEquals(g1, g2); 131 } 132 133 } 134 | Popular Tags |