1 43 44 package org.jfree.chart.labels.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 import java.util.List ; 53 54 import junit.framework.Test; 55 import junit.framework.TestCase; 56 import junit.framework.TestSuite; 57 58 import org.jfree.chart.labels.CustomXYToolTipGenerator; 59 60 63 public class CustomXYItemLabelGeneratorTests extends TestCase { 64 65 70 public static Test suite() { 71 return new TestSuite(CustomXYItemLabelGeneratorTests.class); 72 } 73 74 79 public CustomXYItemLabelGeneratorTests(String name) { 80 super(name); 81 } 82 83 86 public void testCloning() { 87 CustomXYToolTipGenerator g1 = new CustomXYToolTipGenerator(); 88 CustomXYToolTipGenerator g2 = null; 89 try { 90 g2 = (CustomXYToolTipGenerator) g1.clone(); 91 } 92 catch (CloneNotSupportedException e) { 93 System.err.println("Failed to clone."); 94 } 95 assertTrue(g1 != g2); 96 assertTrue(g1.getClass() == g2.getClass()); 97 assertTrue(g1.equals(g2)); 98 } 99 100 103 public void testSerialization() { 104 105 List t1 = new java.util.ArrayList (); 106 t1.add("Tooltip A1"); 107 t1.add("Tooltip A2"); 108 t1.add("Tooltip A3"); 109 110 List t2 = new java.util.ArrayList (); 111 t2.add("Tooltip B1"); 112 t2.add("Tooltip B2"); 113 t2.add("Tooltip B3"); 114 115 CustomXYToolTipGenerator g1 = new CustomXYToolTipGenerator(); 116 g1.addToolTipSeries(t1); 117 g1.addToolTipSeries(t2); 118 CustomXYToolTipGenerator g2 = null; 119 120 try { 121 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 122 ObjectOutput out = new ObjectOutputStream (buffer); 123 out.writeObject(g1); 124 out.close(); 125 126 ObjectInput in = new ObjectInputStream ( 127 new ByteArrayInputStream (buffer.toByteArray()) 128 ); 129 g2 = (CustomXYToolTipGenerator) in.readObject(); 130 in.close(); 131 } 132 catch (Exception e) { 133 System.out.println(e.toString()); 134 } 135 assertEquals(g1, g2); 136 137 } 138 139 } 140 | Popular Tags |