1 42 43 package org.jfree.chart.axis.junit; 44 45 import java.io.ByteArrayInputStream ; 46 import java.io.ByteArrayOutputStream ; 47 import java.io.ObjectInput ; 48 import java.io.ObjectInputStream ; 49 import java.io.ObjectOutput ; 50 import java.io.ObjectOutputStream ; 51 import java.text.DecimalFormat ; 52 53 import junit.framework.Test; 54 import junit.framework.TestCase; 55 import junit.framework.TestSuite; 56 57 import org.jfree.chart.axis.NumberTickUnit; 58 59 62 public class NumberTickUnitTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(NumberTickUnitTests.class); 71 } 72 73 78 public NumberTickUnitTests(String name) { 79 super(name); 80 } 81 82 85 public void testEquals() { 86 NumberTickUnit t1 = new NumberTickUnit(1.23, new DecimalFormat ("0.00")); 87 NumberTickUnit t2 = new NumberTickUnit(1.23, new DecimalFormat ("0.00")); 88 assertTrue(t1.equals(t2)); 89 assertTrue(t2.equals(t1)); 90 91 t1 = new NumberTickUnit(3.21, new DecimalFormat ("0.00")); 92 assertFalse(t1.equals(t2)); 93 t2 = new NumberTickUnit(3.21, new DecimalFormat ("0.00")); 94 assertTrue(t1.equals(t2)); 95 96 t1 = new NumberTickUnit(3.21, new DecimalFormat ("0.000")); 97 assertFalse(t1.equals(t2)); 98 t2 = new NumberTickUnit(3.21, new DecimalFormat ("0.000")); 99 assertTrue(t1.equals(t2)); 100 } 101 102 105 public void testHashCode() { 106 NumberTickUnit t1 = new NumberTickUnit(1.23, new DecimalFormat ("0.00")); 107 NumberTickUnit t2 = new NumberTickUnit(1.23, new DecimalFormat ("0.00")); 108 int h1 = t1.hashCode(); 109 int h2 = t2.hashCode(); 110 assertEquals(h1, h2); 111 } 112 113 116 public void testCloning() { 117 NumberTickUnit t1 = new NumberTickUnit(1.23, new DecimalFormat ("0.00")); 118 assertFalse(t1 instanceof Cloneable ); 119 } 120 121 124 public void testSerialization() { 125 NumberTickUnit t1 = new NumberTickUnit(1.23, new DecimalFormat ("0.00")); 126 NumberTickUnit t2 = null; 127 try { 128 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 129 ObjectOutput out = new ObjectOutputStream (buffer); 130 out.writeObject(t1); 131 out.close(); 132 133 ObjectInput in = new ObjectInputStream ( 134 new ByteArrayInputStream (buffer.toByteArray()) 135 ); 136 t2 = (NumberTickUnit) in.readObject(); 137 in.close(); 138 } 139 catch (Exception e) { 140 e.printStackTrace(); 141 } 142 assertEquals(t1, t2); 143 } 144 145 } 146 | Popular Tags |