1 38 39 package org.jfree.chart.labels.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 import java.util.List ; 48 49 import junit.framework.Test; 50 import junit.framework.TestCase; 51 import junit.framework.TestSuite; 52 53 import org.jfree.chart.labels.CustomXYToolTipGenerator; 54 55 60 public class CustomXYToolTipGeneratorTests extends TestCase { 61 62 67 public static Test suite() { 68 return new TestSuite(CustomXYToolTipGeneratorTests.class); 69 } 70 71 76 public CustomXYToolTipGeneratorTests(String name) { 77 super(name); 78 } 79 80 83 public void testCloning() { 84 CustomXYToolTipGenerator g1 = new CustomXYToolTipGenerator(); 85 CustomXYToolTipGenerator g2 = null; 86 try { 87 g2 = (CustomXYToolTipGenerator) g1.clone(); 88 } 89 catch (CloneNotSupportedException e) { 90 System.err.println("StandardXYToolTipGenerator.testCloning: failed to clone."); 91 } 92 assertTrue(g1 != g2); 93 assertTrue(g1.getClass() == g2.getClass()); 94 assertTrue(g1.equals(g2)); 95 } 96 97 100 public void testSerialization() { 101 102 List t1 = new java.util.ArrayList (); 103 t1.add("Tooltip A1"); 104 t1.add("Tooltip A2"); 105 t1.add("Tooltip A3"); 106 107 List t2 = new java.util.ArrayList (); 108 t2.add("Tooltip B1"); 109 t2.add("Tooltip B2"); 110 t2.add("Tooltip B3"); 111 112 CustomXYToolTipGenerator g1 = new CustomXYToolTipGenerator(); 113 g1.addToolTipSeries(t1); 114 g1.addToolTipSeries(t2); 115 CustomXYToolTipGenerator g2 = null; 116 117 try { 118 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 119 ObjectOutput out = new ObjectOutputStream (buffer); 120 out.writeObject(g1); 121 out.close(); 122 123 ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 124 g2 = (CustomXYToolTipGenerator) 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 } 135 | Popular Tags |