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.DecimalFormat ; 54 import java.text.NumberFormat ; 55 56 import junit.framework.Test; 57 import junit.framework.TestCase; 58 import junit.framework.TestSuite; 59 60 import org.jfree.chart.labels.StandardPieSectionLabelGenerator; 61 62 65 public class StandardPieSectionLabelGeneratorTests extends TestCase { 66 67 72 public static Test suite() { 73 return new TestSuite(StandardPieSectionLabelGeneratorTests.class); 74 } 75 76 81 public StandardPieSectionLabelGeneratorTests(String name) { 82 super(name); 83 } 84 85 88 public void testEquals() { 89 StandardPieSectionLabelGenerator g1 90 = new StandardPieSectionLabelGenerator(); 91 StandardPieSectionLabelGenerator g2 92 = new StandardPieSectionLabelGenerator(); 93 assertTrue(g1.equals(g2)); 94 assertTrue(g2.equals(g1)); 95 96 g1 = new StandardPieSectionLabelGenerator( 97 "{0}", new DecimalFormat ("#,##0.00"), 98 NumberFormat.getPercentInstance() 99 ); 100 assertFalse(g1.equals(g2)); 101 g2 = new StandardPieSectionLabelGenerator( 102 "{0}", new DecimalFormat ("#,##0.00"), 103 NumberFormat.getPercentInstance() 104 ); 105 assertTrue(g1.equals(g2)); 106 107 g1 = new StandardPieSectionLabelGenerator( 108 "{0} {1}", new DecimalFormat ("#,##0.00"), 109 NumberFormat.getPercentInstance() 110 ); 111 assertFalse(g1.equals(g2)); 112 g2 = new StandardPieSectionLabelGenerator( 113 "{0} {1}", new DecimalFormat ("#,##0.00"), 114 NumberFormat.getPercentInstance() 115 ); 116 assertTrue(g1.equals(g2)); 117 118 g1 = new StandardPieSectionLabelGenerator( 119 "{0} {1}", new DecimalFormat ("#,##0"), 120 NumberFormat.getPercentInstance() 121 ); 122 assertFalse(g1.equals(g2)); 123 g2 = new StandardPieSectionLabelGenerator( 124 "{0} {1}", new DecimalFormat ("#,##0"), 125 NumberFormat.getPercentInstance() 126 ); 127 assertTrue(g1.equals(g2)); 128 129 g1 = new StandardPieSectionLabelGenerator( 130 "{0} {1}", new DecimalFormat ("#,##0"), new DecimalFormat ("0.000%") 131 ); 132 assertFalse(g1.equals(g2)); 133 g2 = new StandardPieSectionLabelGenerator( 134 "{0} {1}", new DecimalFormat ("#,##0"), new DecimalFormat ("0.000%") 135 ); 136 assertTrue(g1.equals(g2)); 137 } 138 139 142 public void testCloning() { 143 StandardPieSectionLabelGenerator g1 144 = new StandardPieSectionLabelGenerator(); 145 StandardPieSectionLabelGenerator g2 = null; 146 try { 147 g2 = (StandardPieSectionLabelGenerator) g1.clone(); 148 } 149 catch (CloneNotSupportedException e) { 150 System.err.println("Failed to clone."); 151 } 152 assertTrue(g1 != g2); 153 assertTrue(g1.getClass() == g2.getClass()); 154 assertTrue(g1.equals(g2)); 155 } 156 157 160 public void testSerialization() { 161 162 StandardPieSectionLabelGenerator g1 163 = new StandardPieSectionLabelGenerator(); 164 StandardPieSectionLabelGenerator g2 = null; 165 166 try { 167 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 168 ObjectOutput out = new ObjectOutputStream (buffer); 169 out.writeObject(g1); 170 out.close(); 171 172 ObjectInput in = new ObjectInputStream ( 173 new ByteArrayInputStream (buffer.toByteArray()) 174 ); 175 g2 = (StandardPieSectionLabelGenerator) in.readObject(); 176 in.close(); 177 } 178 catch (Exception e) { 179 e.printStackTrace(); 180 } 181 assertEquals(g1, g2); 182 183 } 184 185 190 public static void main(String [] args) { 191 junit.textui.TestRunner.run(suite()); 192 } 193 194 } 195 | Popular Tags |