1 48 49 package org.jfree.chart.labels.junit; 50 51 import java.io.ByteArrayInputStream ; 52 import java.io.ByteArrayOutputStream ; 53 import java.io.ObjectInput ; 54 import java.io.ObjectInputStream ; 55 import java.io.ObjectOutput ; 56 import java.io.ObjectOutputStream ; 57 import java.text.DecimalFormat ; 58 import java.text.NumberFormat ; 59 60 import junit.framework.Test; 61 import junit.framework.TestCase; 62 import junit.framework.TestSuite; 63 64 import org.jfree.chart.labels.StandardPieToolTipGenerator; 65 66 69 public class StandardPieToolTipGeneratorTests extends TestCase { 70 71 76 public static Test suite() { 77 return new TestSuite(StandardPieToolTipGeneratorTests.class); 78 } 79 80 85 public StandardPieToolTipGeneratorTests(String name) { 86 super(name); 87 } 88 89 92 public void testEquals() { 93 StandardPieToolTipGenerator g1 = new StandardPieToolTipGenerator(); 94 StandardPieToolTipGenerator g2 = new StandardPieToolTipGenerator(); 95 assertTrue(g1.equals(g2)); 96 assertTrue(g2.equals(g1)); 97 98 g1 = new StandardPieToolTipGenerator("{0}", 99 new DecimalFormat ("#,##0.00"), 100 NumberFormat.getPercentInstance()); 101 assertFalse(g1.equals(g2)); 102 g2 = new StandardPieToolTipGenerator("{0}", 103 new DecimalFormat ("#,##0.00"), 104 NumberFormat.getPercentInstance()); 105 assertTrue(g1.equals(g2)); 106 107 g1 = new StandardPieToolTipGenerator("{0} {1}", 108 new DecimalFormat ("#,##0.00"), 109 NumberFormat.getPercentInstance()); 110 assertFalse(g1.equals(g2)); 111 g2 = new StandardPieToolTipGenerator("{0} {1}", 112 new DecimalFormat ("#,##0.00"), 113 NumberFormat.getPercentInstance()); 114 assertTrue(g1.equals(g2)); 115 116 g1 = new StandardPieToolTipGenerator("{0} {1}", 117 new DecimalFormat ("#,##0"), NumberFormat.getPercentInstance()); 118 assertFalse(g1.equals(g2)); 119 g2 = new StandardPieToolTipGenerator("{0} {1}", 120 new DecimalFormat ("#,##0"), NumberFormat.getPercentInstance()); 121 assertTrue(g1.equals(g2)); 122 123 g1 = new StandardPieToolTipGenerator("{0} {1}", 124 new DecimalFormat ("#,##0"), new DecimalFormat ("0.000%")); 125 assertFalse(g1.equals(g2)); 126 g2 = new StandardPieToolTipGenerator("{0} {1}", 127 new DecimalFormat ("#,##0"), new DecimalFormat ("0.000%")); 128 assertTrue(g1.equals(g2)); 129 } 130 131 134 public void testCloning() { 135 StandardPieToolTipGenerator g1 = new StandardPieToolTipGenerator(); 136 StandardPieToolTipGenerator g2 = null; 137 try { 138 g2 = (StandardPieToolTipGenerator) g1.clone(); 139 } 140 catch (CloneNotSupportedException e) { 141 System.err.println("Failed to clone."); 142 } 143 assertTrue(g1 != g2); 144 assertTrue(g1.getClass() == g2.getClass()); 145 assertTrue(g1.equals(g2)); 146 assertTrue(g1.getNumberFormat() != g2.getNumberFormat()); 147 assertTrue(g1.getPercentFormat() != g2.getPercentFormat()); 148 } 149 150 153 public void testSerialization() { 154 155 StandardPieToolTipGenerator g1 = new StandardPieToolTipGenerator(); 156 StandardPieToolTipGenerator g2 = null; 157 158 try { 159 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 160 ObjectOutput out = new ObjectOutputStream (buffer); 161 out.writeObject(g1); 162 out.close(); 163 164 ObjectInput in = new ObjectInputStream ( 165 new ByteArrayInputStream (buffer.toByteArray())); 166 g2 = (StandardPieToolTipGenerator) in.readObject(); 167 in.close(); 168 } 169 catch (Exception e) { 170 e.printStackTrace(); 171 } 172 assertEquals(g1, g2); 173 174 } 175 176 } 177 | Popular Tags |