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.StandardXYZToolTipGenerator; 60 61 64 public class StandardXYZToolTipGeneratorTests extends TestCase { 65 66 71 public static Test suite() { 72 return new TestSuite(StandardXYZToolTipGeneratorTests.class); 73 } 74 75 80 public StandardXYZToolTipGeneratorTests(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 NumberFormat znf1 = new DecimalFormat ("0.00"); 97 NumberFormat znf2 = new DecimalFormat ("0.000"); 98 99 DateFormat xdf1 = new SimpleDateFormat ("d-MMM"); 100 DateFormat xdf2 = new SimpleDateFormat ("d-MMM-yyyy"); 101 DateFormat ydf1 = new SimpleDateFormat ("d-MMM"); 102 DateFormat ydf2 = new SimpleDateFormat ("d-MMM-yyyy"); 103 DateFormat zdf1 = new SimpleDateFormat ("d-MMM"); 104 DateFormat zdf2 = new SimpleDateFormat ("d-MMM-yyyy"); 105 106 StandardXYZToolTipGenerator g1 = null; 107 StandardXYZToolTipGenerator g2 = null; 108 109 g1 = new StandardXYZToolTipGenerator(f1, xnf1, ynf1, znf1); 110 g2 = new StandardXYZToolTipGenerator(f1, xnf1, ynf1, znf1); 111 assertTrue(g1.equals(g2)); 112 113 g1 = new StandardXYZToolTipGenerator(f2, xnf1, ynf1, znf1); 115 assertFalse(g1.equals(g2)); 116 g2 = new StandardXYZToolTipGenerator(f2, xnf1, ynf1, znf1); 117 assertTrue(g1.equals(g2)); 118 119 g1 = new StandardXYZToolTipGenerator(f2, xnf2, ynf1, znf1); 121 assertFalse(g1.equals(g2)); 122 g2 = new StandardXYZToolTipGenerator(f2, xnf2, ynf1, znf1); 123 assertTrue(g1.equals(g2)); 124 125 g1 = new StandardXYZToolTipGenerator(f2, xnf2, ynf2, znf1); 127 assertFalse(g1.equals(g2)); 128 g2 = new StandardXYZToolTipGenerator(f2, xnf2, ynf2, znf1); 129 assertTrue(g1.equals(g2)); 130 131 g1 = new StandardXYZToolTipGenerator(f2, xnf2, ynf2, znf2); 133 assertFalse(g1.equals(g2)); 134 g2 = new StandardXYZToolTipGenerator(f2, xnf2, ynf2, znf2); 135 assertTrue(g1.equals(g2)); 136 137 g1 = new StandardXYZToolTipGenerator(f2, xdf1, ydf1, zdf1); 138 g2 = new StandardXYZToolTipGenerator(f2, xdf1, ydf1, zdf1); 139 assertTrue(g1.equals(g2)); 140 141 g1 = new StandardXYZToolTipGenerator(f2, xdf2, ydf1, zdf1); 143 assertFalse(g1.equals(g2)); 144 g2 = new StandardXYZToolTipGenerator(f2, xdf2, ydf1, zdf1); 145 assertTrue(g1.equals(g2)); 146 147 g1 = new StandardXYZToolTipGenerator(f2, xdf2, ydf2, zdf1); 149 assertFalse(g1.equals(g2)); 150 g2 = new StandardXYZToolTipGenerator(f2, xdf2, ydf2, zdf1); 151 assertTrue(g1.equals(g2)); 152 153 g1 = new StandardXYZToolTipGenerator(f2, xdf2, ydf2, zdf2); 155 assertFalse(g1.equals(g2)); 156 g2 = new StandardXYZToolTipGenerator(f2, xdf2, ydf2, zdf2); 157 assertTrue(g1.equals(g2)); 158 159 } 160 161 164 public void testCloning() { 165 StandardXYZToolTipGenerator g1 = new StandardXYZToolTipGenerator(); 166 StandardXYZToolTipGenerator g2 = null; 167 try { 168 g2 = (StandardXYZToolTipGenerator) g1.clone(); 169 } 170 catch (CloneNotSupportedException e) { 171 System.err.println("Failed to clone."); 172 } 173 assertTrue(g1 != g2); 174 assertTrue(g1.getClass() == g2.getClass()); 175 assertTrue(g1.equals(g2)); 176 } 177 178 181 public void testSerialization() { 182 183 StandardXYZToolTipGenerator g1 = new StandardXYZToolTipGenerator(); 184 StandardXYZToolTipGenerator g2 = null; 185 186 try { 187 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 188 ObjectOutput out = new ObjectOutputStream (buffer); 189 out.writeObject(g1); 190 out.close(); 191 192 ObjectInput in = new ObjectInputStream ( 193 new ByteArrayInputStream (buffer.toByteArray()) 194 ); 195 g2 = (StandardXYZToolTipGenerator) in.readObject(); 196 in.close(); 197 } 198 catch (Exception e) { 199 System.out.println(e.toString()); 200 } 201 assertEquals(g1, g2); 202 203 } 204 205 } 206 | Popular Tags |