1 41 42 package org.jfree.chart.labels.junit; 43 44 import java.io.ByteArrayInputStream ; 45 import java.io.ByteArrayOutputStream ; 46 import java.io.ObjectInput ; 47 import java.io.ObjectInputStream ; 48 import java.io.ObjectOutput ; 49 import java.io.ObjectOutputStream ; 50 import java.text.DecimalFormat ; 51 52 import junit.framework.Test; 53 import junit.framework.TestCase; 54 import junit.framework.TestSuite; 55 56 import org.jfree.chart.labels.BoxAndWhiskerToolTipGenerator; 57 58 61 public class BoxAndWhiskerToolTipGeneratorTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(BoxAndWhiskerToolTipGeneratorTests.class); 70 } 71 72 77 public BoxAndWhiskerToolTipGeneratorTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 86 BoxAndWhiskerToolTipGenerator g1 = new BoxAndWhiskerToolTipGenerator(); 88 BoxAndWhiskerToolTipGenerator g2 = new BoxAndWhiskerToolTipGenerator(); 89 assertTrue(g1.equals(g2)); 90 assertTrue(g2.equals(g1)); 91 92 g1 = new BoxAndWhiskerToolTipGenerator( 94 "{0} --> {1} {2}", new DecimalFormat ("0.0") 95 ); 96 g2 = new BoxAndWhiskerToolTipGenerator( 97 "{1} {2}", new DecimalFormat ("0.0") 98 ); 99 assertFalse(g1.equals(g2)); 100 g2 = new BoxAndWhiskerToolTipGenerator( 101 "{0} --> {1} {2}", new DecimalFormat ("0.0") 102 ); 103 assertTrue(g1.equals(g2)); 104 105 g1 = new BoxAndWhiskerToolTipGenerator( 107 "{0} --> {1} {2}", new DecimalFormat ("0.0") 108 ); 109 g2 = new BoxAndWhiskerToolTipGenerator( 110 "{0} --> {1} {2}", new DecimalFormat ("0.00") 111 ); 112 assertFalse(g1.equals(g2)); 113 g2 = new BoxAndWhiskerToolTipGenerator( 114 "{0} --> {1} {2}", new DecimalFormat ("0.0") 115 ); 116 assertTrue(g1.equals(g2)); 117 } 118 119 122 public void testCloning() { 123 BoxAndWhiskerToolTipGenerator g1 = new BoxAndWhiskerToolTipGenerator(); 124 BoxAndWhiskerToolTipGenerator g2 = null; 125 try { 126 g2 = (BoxAndWhiskerToolTipGenerator) g1.clone(); 127 } 128 catch (CloneNotSupportedException e) { 129 System.err.println("Failed to clone."); 130 } 131 assertTrue(g1 != g2); 132 assertTrue(g1.getClass() == g2.getClass()); 133 assertTrue(g1.equals(g2)); 134 } 135 136 139 public void testSerialization() { 140 141 BoxAndWhiskerToolTipGenerator g1 = new BoxAndWhiskerToolTipGenerator(); 142 BoxAndWhiskerToolTipGenerator g2 = null; 143 144 try { 145 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 146 ObjectOutput out = new ObjectOutputStream (buffer); 147 out.writeObject(g1); 148 out.close(); 149 150 ObjectInput in = new ObjectInputStream ( 151 new ByteArrayInputStream (buffer.toByteArray()) 152 ); 153 g2 = (BoxAndWhiskerToolTipGenerator) in.readObject(); 154 in.close(); 155 } 156 catch (Exception e) { 157 System.out.println(e.toString()); 158 } 159 assertEquals(g1, g2); 160 161 } 162 163 } 164 | Popular Tags |