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