1 44 45 package org.jfree.chart.labels.junit; 46 47 import java.io.ByteArrayInputStream ; 48 import java.io.ByteArrayOutputStream ; 49 import java.io.ObjectInput ; 50 import java.io.ObjectInputStream ; 51 import java.io.ObjectOutput ; 52 import java.io.ObjectOutputStream ; 53 import java.text.DateFormat ; 54 import java.text.DecimalFormat ; 55 import java.text.NumberFormat ; 56 import java.text.SimpleDateFormat ; 57 58 import junit.framework.Test; 59 import junit.framework.TestCase; 60 import junit.framework.TestSuite; 61 62 import org.jfree.chart.labels.StandardXYItemLabelGenerator; 63 64 67 public class StandardXYItemLabelGeneratorTests extends TestCase { 68 69 74 public static Test suite() { 75 return new TestSuite(StandardXYItemLabelGeneratorTests.class); 76 } 77 78 83 public StandardXYItemLabelGeneratorTests(String name) { 84 super(name); 85 } 86 87 90 public void testEquals() { 91 92 String f1 = "{1}"; 94 String f2 = "{2}"; 95 NumberFormat xnf1 = new DecimalFormat ("0.00"); 96 NumberFormat xnf2 = new DecimalFormat ("0.000"); 97 NumberFormat ynf1 = new DecimalFormat ("0.00"); 98 NumberFormat ynf2 = new DecimalFormat ("0.000"); 99 100 StandardXYItemLabelGenerator g1 = null; 101 StandardXYItemLabelGenerator g2 = null; 102 103 g1 = new StandardXYItemLabelGenerator(f1, xnf1, ynf1); 104 g2 = new StandardXYItemLabelGenerator(f1, xnf1, ynf1); 105 assertTrue(g1.equals(g2)); 106 assertTrue(g2.equals(g1)); 107 108 g1 = new StandardXYItemLabelGenerator(f2, xnf1, ynf1); 109 assertFalse(g1.equals(g2)); 110 g2 = new StandardXYItemLabelGenerator(f2, xnf1, ynf1); 111 assertTrue(g1.equals(g2)); 112 113 g1 = new StandardXYItemLabelGenerator(f2, xnf2, ynf1); 114 assertFalse(g1.equals(g2)); 115 g2 = new StandardXYItemLabelGenerator(f2, xnf2, ynf1); 116 assertTrue(g1.equals(g2)); 117 118 g1 = new StandardXYItemLabelGenerator(f2, xnf2, ynf2); 119 assertFalse(g1.equals(g2)); 120 g2 = new StandardXYItemLabelGenerator(f2, xnf2, ynf2); 121 assertTrue(g1.equals(g2)); 122 123 DateFormat xdf1 = new SimpleDateFormat ("d-MMM"); 124 DateFormat xdf2 = new SimpleDateFormat ("d-MMM-yyyy"); 125 DateFormat ydf1 = new SimpleDateFormat ("d-MMM"); 126 DateFormat ydf2 = new SimpleDateFormat ("d-MMM-yyyy"); 127 128 g1 = new StandardXYItemLabelGenerator(f1, xdf1, ydf1); 129 g2 = new StandardXYItemLabelGenerator(f1, xdf1, ydf1); 130 assertTrue(g1.equals(g2)); 131 assertTrue(g2.equals(g1)); 132 133 g1 = new StandardXYItemLabelGenerator(f1, xdf2, ydf1); 134 assertFalse(g1.equals(g2)); 135 g2 = new StandardXYItemLabelGenerator(f1, xdf2, ydf1); 136 assertTrue(g1.equals(g2)); 137 138 g1 = new StandardXYItemLabelGenerator(f1, xdf2, ydf2); 139 assertFalse(g1.equals(g2)); 140 g2 = new StandardXYItemLabelGenerator(f1, xdf2, ydf2); 141 assertTrue(g1.equals(g2)); 142 143 } 144 145 148 public void testCloning() { 149 StandardXYItemLabelGenerator g1 = new StandardXYItemLabelGenerator(); 150 StandardXYItemLabelGenerator g2 = null; 151 try { 152 g2 = (StandardXYItemLabelGenerator) g1.clone(); 153 } 154 catch (CloneNotSupportedException e) { 155 System.err.println("Clone failed."); 156 } 157 assertTrue(g1 != g2); 158 assertTrue(g1.getClass() == g2.getClass()); 159 assertTrue(g1.equals(g2)); 160 } 161 162 165 public void testSerialization() { 166 167 StandardXYItemLabelGenerator g1 = new StandardXYItemLabelGenerator(); 168 StandardXYItemLabelGenerator g2 = null; 169 170 try { 171 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 172 ObjectOutput out = new ObjectOutputStream (buffer); 173 out.writeObject(g1); 174 out.close(); 175 176 ObjectInput in = new ObjectInputStream ( 177 new ByteArrayInputStream (buffer.toByteArray())); 178 g2 = (StandardXYItemLabelGenerator) in.readObject(); 179 in.close(); 180 } 181 catch (Exception e) { 182 System.out.println(e.toString()); 183 } 184 assertEquals(g1, g2); 185 186 } 187 188 } 189 | Popular Tags |