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.NumberFormat ; 53 import java.text.SimpleDateFormat ; 54 55 import junit.framework.Test; 56 import junit.framework.TestCase; 57 import junit.framework.TestSuite; 58 59 import org.jfree.chart.labels.StandardXYToolTipGenerator; 60 61 64 public class StandardXYToolTipGeneratorTests extends TestCase { 65 66 71 public static Test suite() { 72 return new TestSuite(StandardXYToolTipGeneratorTests.class); 73 } 74 75 80 public StandardXYToolTipGeneratorTests(String name) { 81 super(name); 82 } 83 84 87 public void testEquals() { 88 89 String f1 = "{1}"; 91 String f2 = "{2}"; 92 NumberFormat xnf1 = new DecimalFormat ("0.00"); 93 NumberFormat xnf2 = new DecimalFormat ("0.000"); 94 NumberFormat ynf1 = new DecimalFormat ("0.00"); 95 NumberFormat ynf2 = new DecimalFormat ("0.000"); 96 97 StandardXYToolTipGenerator g1 = null; 98 StandardXYToolTipGenerator g2 = null; 99 100 g1 = new StandardXYToolTipGenerator(f1, xnf1, ynf1); 101 g2 = new StandardXYToolTipGenerator(f1, xnf1, ynf1); 102 assertTrue(g1.equals(g2)); 103 assertTrue(g2.equals(g1)); 104 105 g1 = new StandardXYToolTipGenerator(f2, xnf1, ynf1); 106 assertFalse(g1.equals(g2)); 107 g2 = new StandardXYToolTipGenerator(f2, xnf1, ynf1); 108 assertTrue(g1.equals(g2)); 109 110 g1 = new StandardXYToolTipGenerator(f2, xnf2, ynf1); 111 assertFalse(g1.equals(g2)); 112 g2 = new StandardXYToolTipGenerator(f2, xnf2, ynf1); 113 assertTrue(g1.equals(g2)); 114 115 g1 = new StandardXYToolTipGenerator(f2, xnf2, ynf2); 116 assertFalse(g1.equals(g2)); 117 g2 = new StandardXYToolTipGenerator(f2, xnf2, ynf2); 118 assertTrue(g1.equals(g2)); 119 120 DateFormat xdf1 = new SimpleDateFormat ("d-MMM"); 121 DateFormat xdf2 = new SimpleDateFormat ("d-MMM-yyyy"); 122 DateFormat ydf1 = new SimpleDateFormat ("d-MMM"); 123 DateFormat ydf2 = new SimpleDateFormat ("d-MMM-yyyy"); 124 125 g1 = new StandardXYToolTipGenerator(f1, xdf1, ydf1); 126 g2 = new StandardXYToolTipGenerator(f1, xdf1, ydf1); 127 assertTrue(g1.equals(g2)); 128 assertTrue(g2.equals(g1)); 129 130 g1 = new StandardXYToolTipGenerator(f1, xdf2, ydf1); 131 assertFalse(g1.equals(g2)); 132 g2 = new StandardXYToolTipGenerator(f1, xdf2, ydf1); 133 assertTrue(g1.equals(g2)); 134 135 g1 = new StandardXYToolTipGenerator(f1, xdf2, ydf2); 136 assertFalse(g1.equals(g2)); 137 g2 = new StandardXYToolTipGenerator(f1, xdf2, ydf2); 138 assertTrue(g1.equals(g2)); 139 140 } 141 142 145 public void testCloning() { 146 StandardXYToolTipGenerator g1 = new StandardXYToolTipGenerator(); 147 StandardXYToolTipGenerator g2 = null; 148 try { 149 g2 = (StandardXYToolTipGenerator) g1.clone(); 150 } 151 catch (CloneNotSupportedException e) { 152 System.err.println("Failed to clone."); 153 } 154 assertTrue(g1 != g2); 155 assertTrue(g1.getClass() == g2.getClass()); 156 assertTrue(g1.equals(g2)); 157 } 158 159 162 public void testSerialization() { 163 164 StandardXYToolTipGenerator g1 = new StandardXYToolTipGenerator(); 165 StandardXYToolTipGenerator g2 = null; 166 167 try { 168 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 169 ObjectOutput out = new ObjectOutputStream (buffer); 170 out.writeObject(g1); 171 out.close(); 172 173 ObjectInput in = new ObjectInputStream ( 174 new ByteArrayInputStream (buffer.toByteArray()) 175 ); 176 g2 = (StandardXYToolTipGenerator) in.readObject(); 177 in.close(); 178 } 179 catch (Exception e) { 180 System.out.println(e.toString()); 181 } 182 assertEquals(g1, g2); 183 184 } 185 186 } 187 | Popular Tags |