1 42 43 package org.jfree.chart.labels.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 import java.text.NumberFormat ; 53 import java.text.SimpleDateFormat ; 54 55 import junit.framework.Test; 56 import junit.framework.TestCase; 57 import junit.framework.TestSuite; 58 59 import org.jfree.chart.labels.HighLowItemLabelGenerator; 60 61 64 public class HighLowItemLabelGeneratorTests extends TestCase { 65 66 71 public static Test suite() { 72 return new TestSuite(HighLowItemLabelGeneratorTests.class); 73 } 74 75 80 public HighLowItemLabelGeneratorTests(String name) { 81 super(name); 82 } 83 84 87 public void testEquals() { 88 HighLowItemLabelGenerator g1 = new HighLowItemLabelGenerator(); 89 HighLowItemLabelGenerator g2 = new HighLowItemLabelGenerator(); 90 assertTrue(g1.equals(g2)); 91 assertTrue(g2.equals(g1)); 92 93 g1 = new HighLowItemLabelGenerator( 94 new SimpleDateFormat ("d-MMM-yyyy"), NumberFormat.getInstance() 95 ); 96 assertFalse(g1.equals(g2)); 97 g2 = new HighLowItemLabelGenerator( 98 new SimpleDateFormat ("d-MMM-yyyy"), NumberFormat.getInstance() 99 ); 100 assertTrue(g1.equals(g2)); 101 102 g1 = new HighLowItemLabelGenerator( 103 new SimpleDateFormat ("d-MMM-yyyy"), new DecimalFormat ("0.000") 104 ); 105 assertFalse(g1.equals(g2)); 106 g2 = new HighLowItemLabelGenerator( 107 new SimpleDateFormat ("d-MMM-yyyy"), new DecimalFormat ("0.000") 108 ); 109 assertTrue(g1.equals(g2)); 110 111 } 112 113 114 117 public void testCloning() { 118 HighLowItemLabelGenerator g1 = new HighLowItemLabelGenerator(); 119 HighLowItemLabelGenerator g2 = null; 120 try { 121 g2 = (HighLowItemLabelGenerator) g1.clone(); 122 } 123 catch (CloneNotSupportedException e) { 124 System.err.println("Failed to clone."); 125 } 126 assertTrue(g1 != g2); 127 assertTrue(g1.getClass() == g2.getClass()); 128 assertTrue(g1.equals(g2)); 129 } 130 131 134 public void testSerialization() { 135 136 HighLowItemLabelGenerator g1 = new HighLowItemLabelGenerator(); 137 HighLowItemLabelGenerator g2 = null; 138 139 try { 140 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 141 ObjectOutput out = new ObjectOutputStream (buffer); 142 out.writeObject(g1); 143 out.close(); 144 145 ObjectInput in = new ObjectInputStream ( 146 new ByteArrayInputStream (buffer.toByteArray()) 147 ); 148 g2 = (HighLowItemLabelGenerator) in.readObject(); 149 in.close(); 150 } 151 catch (Exception e) { 152 System.out.println(e.toString()); 153 } 154 assertEquals(g1, g2); 155 156 } 157 158 } 159 | Popular Tags |