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