1 42 43 package org.jfree.chart.labels.junit; 44 45 import java.io.ByteArrayInputStream ; 46 import java.io.ByteArrayOutputStream ; 47 import java.io.ObjectInput ; 48 import java.io.ObjectInputStream ; 49 import java.io.ObjectOutput ; 50 import java.io.ObjectOutputStream ; 51 import java.text.DateFormat ; 52 import java.text.DecimalFormat ; 53 import java.text.NumberFormat ; 54 import java.text.SimpleDateFormat ; 55 56 import junit.framework.Test; 57 import junit.framework.TestCase; 58 import junit.framework.TestSuite; 59 60 import org.jfree.chart.labels.BubbleXYItemLabelGenerator; 61 import org.jfree.data.xy.XYSeries; 62 import org.jfree.data.xy.XYSeriesCollection; 63 64 67 public class BubbleXYItemLabelGeneratorTests extends TestCase { 68 69 74 public static Test suite() { 75 return new TestSuite(BubbleXYItemLabelGeneratorTests.class); 76 } 77 78 83 public BubbleXYItemLabelGeneratorTests(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 NumberFormat znf1 = new DecimalFormat ("0.00"); 100 NumberFormat znf2 = new DecimalFormat ("0.000"); 101 102 BubbleXYItemLabelGenerator g1 = null; 103 BubbleXYItemLabelGenerator g2 = null; 104 105 g1 = new BubbleXYItemLabelGenerator(f1, xnf1, ynf1, znf1); 106 g2 = new BubbleXYItemLabelGenerator(f1, xnf1, ynf1, znf1); 107 assertTrue(g1.equals(g2)); 108 assertTrue(g2.equals(g1)); 109 110 g1 = new BubbleXYItemLabelGenerator(f2, xnf1, ynf1, znf1); 111 assertFalse(g1.equals(g2)); 112 g2 = new BubbleXYItemLabelGenerator(f2, xnf1, ynf1, znf1); 113 assertTrue(g1.equals(g2)); 114 115 g1 = new BubbleXYItemLabelGenerator(f2, xnf2, ynf1, znf1); 116 assertFalse(g1.equals(g2)); 117 g2 = new BubbleXYItemLabelGenerator(f2, xnf2, ynf1, znf1); 118 assertTrue(g1.equals(g2)); 119 120 g1 = new BubbleXYItemLabelGenerator(f2, xnf2, ynf2, znf1); 121 assertFalse(g1.equals(g2)); 122 g2 = new BubbleXYItemLabelGenerator(f2, xnf2, ynf2, znf1); 123 assertTrue(g1.equals(g2)); 124 125 g1 = new BubbleXYItemLabelGenerator(f2, xnf2, ynf2, znf2); 126 assertFalse(g1.equals(g2)); 127 g2 = new BubbleXYItemLabelGenerator(f2, xnf2, ynf2, znf2); 128 assertTrue(g1.equals(g2)); 129 130 DateFormat xdf1 = new SimpleDateFormat ("d-MMM"); 131 DateFormat xdf2 = new SimpleDateFormat ("d-MMM-yyyy"); 132 DateFormat ydf1 = new SimpleDateFormat ("d-MMM"); 133 DateFormat ydf2 = new SimpleDateFormat ("d-MMM-yyyy"); 134 DateFormat zdf1 = new SimpleDateFormat ("d-MMM"); 135 DateFormat zdf2 = new SimpleDateFormat ("d-MMM-yyyy"); 136 137 g1 = new BubbleXYItemLabelGenerator(f1, xdf1, ydf1, zdf1); 138 g2 = new BubbleXYItemLabelGenerator(f1, xdf1, ydf1, zdf1); 139 assertTrue(g1.equals(g2)); 140 assertTrue(g2.equals(g1)); 141 142 g1 = new BubbleXYItemLabelGenerator(f1, xdf2, ydf1, zdf1); 143 assertFalse(g1.equals(g2)); 144 g2 = new BubbleXYItemLabelGenerator(f1, xdf2, ydf1, zdf1); 145 assertTrue(g1.equals(g2)); 146 147 g1 = new BubbleXYItemLabelGenerator(f1, xdf2, ydf2, zdf1); 148 assertFalse(g1.equals(g2)); 149 g2 = new BubbleXYItemLabelGenerator(f1, xdf2, ydf2, zdf1); 150 assertTrue(g1.equals(g2)); 151 152 g1 = new BubbleXYItemLabelGenerator(f1, xdf2, ydf2, zdf2); 153 assertFalse(g1.equals(g2)); 154 g2 = new BubbleXYItemLabelGenerator(f1, xdf2, ydf2, zdf2); 155 assertTrue(g1.equals(g2)); 156 } 157 158 161 public void testCloning() { 162 BubbleXYItemLabelGenerator g1 = new BubbleXYItemLabelGenerator(); 163 BubbleXYItemLabelGenerator g2 = null; 164 try { 165 g2 = (BubbleXYItemLabelGenerator) g1.clone(); 166 } 167 catch (CloneNotSupportedException e) { 168 System.err.println("Clone failed."); 169 } 170 assertTrue(g1 != g2); 171 assertTrue(g1.getClass() == g2.getClass()); 172 assertTrue(g1.equals(g2)); 173 } 174 175 178 public void testSerialization() { 179 180 BubbleXYItemLabelGenerator g1 = new BubbleXYItemLabelGenerator(); 181 BubbleXYItemLabelGenerator g2 = null; 182 183 try { 184 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 185 ObjectOutput out = new ObjectOutputStream (buffer); 186 out.writeObject(g1); 187 out.close(); 188 189 ObjectInput in = new ObjectInputStream ( 190 new ByteArrayInputStream (buffer.toByteArray())); 191 g2 = (BubbleXYItemLabelGenerator) in.readObject(); 192 in.close(); 193 } 194 catch (Exception e) { 195 System.out.println(e.toString()); 196 } 197 assertEquals(g1, g2); 198 199 } 200 201 204 public void testGenerateLabel() { 205 XYSeries s1 = new XYSeries("S1"); 208 s1.add(1.0, 2.0); 209 s1.add(2.2, 3.3); 210 XYSeriesCollection dataset = new XYSeriesCollection(s1); 211 BubbleXYItemLabelGenerator g = new BubbleXYItemLabelGenerator(); 212 assertEquals("{3}", g.generateLabel(dataset, 0, 0)); 213 assertEquals("{3}", g.generateLabel(dataset, 0, 1)); 214 } 215 216 } 217 | Popular Tags |