1 41 42 package org.jfree.chart.labels.junit; 43 44 import java.io.ByteArrayInputStream ; 45 import java.io.ByteArrayOutputStream ; 46 import java.io.ObjectInput ; 47 import java.io.ObjectInputStream ; 48 import java.io.ObjectOutput ; 49 import java.io.ObjectOutputStream ; 50 import java.text.DateFormat ; 51 import java.text.DecimalFormat ; 52 import java.text.SimpleDateFormat ; 53 54 import junit.framework.Test; 55 import junit.framework.TestCase; 56 import junit.framework.TestSuite; 57 58 import org.jfree.chart.labels.StandardCategoryToolTipGenerator; 59 60 63 public class StandardCategoryToolTipGeneratorTests extends TestCase { 64 65 70 public static Test suite() { 71 return new TestSuite(StandardCategoryToolTipGeneratorTests.class); 72 } 73 74 79 public StandardCategoryToolTipGeneratorTests(String name) { 80 super(name); 81 } 82 83 86 public void testEquals() { 87 88 StandardCategoryToolTipGenerator g1 89 = new StandardCategoryToolTipGenerator(); 90 StandardCategoryToolTipGenerator g2 91 = new StandardCategoryToolTipGenerator(); 92 assertTrue(g1.equals(g2)); 93 assertTrue(g2.equals(g1)); 94 95 g1 = new StandardCategoryToolTipGenerator( 96 "{0}", new DecimalFormat ("0.000") 97 ); 98 assertFalse(g1.equals(g2)); 99 g2 = new StandardCategoryToolTipGenerator( 100 "{0}", new DecimalFormat ("0.000") 101 ); 102 assertTrue(g1.equals(g2)); 103 104 g1 = new StandardCategoryToolTipGenerator( 105 "{1}", new DecimalFormat ("0.000") 106 ); 107 assertFalse(g1.equals(g2)); 108 g2 = new StandardCategoryToolTipGenerator( 109 "{1}", new DecimalFormat ("0.000") 110 ); 111 assertTrue(g1.equals(g2)); 112 113 g1 = new StandardCategoryToolTipGenerator( 114 "{2}", new SimpleDateFormat ("d-MMM") 115 ); 116 assertFalse(g1.equals(g2)); 117 g2 = new StandardCategoryToolTipGenerator( 118 "{2}", new SimpleDateFormat ("d-MMM") 119 ); 120 assertTrue(g1.equals(g2)); 121 122 } 123 124 127 public void testCloning() { 128 StandardCategoryToolTipGenerator g1 129 = new StandardCategoryToolTipGenerator(); 130 StandardCategoryToolTipGenerator g2 = null; 131 try { 132 g2 = (StandardCategoryToolTipGenerator) g1.clone(); 133 } 134 catch (CloneNotSupportedException e) { 135 System.err.println("Failed to clone."); 136 } 137 assertTrue(g1 != g2); 138 assertTrue(g1.getClass() == g2.getClass()); 139 assertTrue(g1.equals(g2)); 140 } 141 142 145 public void testSerialization() { 146 147 StandardCategoryToolTipGenerator g1 148 = new StandardCategoryToolTipGenerator( 149 "{2}", DateFormat.getInstance() 150 ); 151 StandardCategoryToolTipGenerator g2 = null; 152 153 try { 154 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 155 ObjectOutput out = new ObjectOutputStream (buffer); 156 out.writeObject(g1); 157 out.close(); 158 159 ObjectInput in = new ObjectInputStream ( 160 new ByteArrayInputStream (buffer.toByteArray()) 161 ); 162 g2 = (StandardCategoryToolTipGenerator) in.readObject(); 163 in.close(); 164 } 165 catch (Exception e) { 166 System.out.println(e.toString()); 167 } 168 assertEquals(g1, g2); 169 170 } 171 172 } 173 | Popular Tags |