1 43 44 package org.jfree.chart.labels.junit; 45 46 import java.io.ByteArrayInputStream ; 47 import java.io.ByteArrayOutputStream ; 48 import java.io.ObjectInput ; 49 import java.io.ObjectInputStream ; 50 import java.io.ObjectOutput ; 51 import java.io.ObjectOutputStream ; 52 import java.text.DateFormat ; 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.IntervalCategoryItemLabelGenerator; 61 62 65 public class IntervalCategoryLabelGeneratorTests extends TestCase { 66 67 72 public static Test suite() { 73 return new TestSuite(IntervalCategoryLabelGeneratorTests.class); 74 } 75 76 81 public IntervalCategoryLabelGeneratorTests(String name) { 82 super(name); 83 } 84 85 88 public void testEquals() { 89 90 IntervalCategoryItemLabelGenerator g1 91 = new IntervalCategoryItemLabelGenerator(); 92 IntervalCategoryItemLabelGenerator g2 93 = new IntervalCategoryItemLabelGenerator(); 94 assertTrue(g1.equals(g2)); 95 assertTrue(g2.equals(g1)); 96 97 g1 = new IntervalCategoryItemLabelGenerator( 98 "{3} - {4}", new DecimalFormat ("0.000") 99 ); 100 assertFalse(g1.equals(g2)); 101 g2 = new IntervalCategoryItemLabelGenerator( 102 "{3} - {4}", new DecimalFormat ("0.000") 103 ); 104 assertTrue(g1.equals(g2)); 105 106 g1 = new IntervalCategoryItemLabelGenerator( 107 "{3} - {4}", new SimpleDateFormat ("d-MMM") 108 ); 109 assertFalse(g1.equals(g2)); 110 g2 = new IntervalCategoryItemLabelGenerator( 111 "{3} - {4}", new SimpleDateFormat ("d-MMM") 112 ); 113 assertTrue(g1.equals(g2)); 114 115 } 116 117 120 public void testCloning() { 121 IntervalCategoryItemLabelGenerator g1 122 = new IntervalCategoryItemLabelGenerator(); 123 IntervalCategoryItemLabelGenerator g2 = null; 124 try { 125 g2 = (IntervalCategoryItemLabelGenerator) g1.clone(); 126 } 127 catch (CloneNotSupportedException e) { 128 System.err.println("Failed to clone."); 129 } 130 assertTrue(g1 != g2); 131 assertTrue(g1.getClass() == g2.getClass()); 132 assertTrue(g1.equals(g2)); 133 } 134 135 138 public void testSerialization() { 139 140 IntervalCategoryItemLabelGenerator g1 141 = new IntervalCategoryItemLabelGenerator( 142 "{3} - {4}", DateFormat.getInstance() 143 ); 144 IntervalCategoryItemLabelGenerator g2 = null; 145 146 try { 147 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 148 ObjectOutput out = new ObjectOutputStream (buffer); 149 out.writeObject(g1); 150 out.close(); 151 152 ObjectInput in = new ObjectInputStream ( 153 new ByteArrayInputStream (buffer.toByteArray()) 154 ); 155 g2 = (IntervalCategoryItemLabelGenerator) in.readObject(); 156 in.close(); 157 } 158 catch (Exception e) { 159 System.out.println(e.toString()); 160 } 161 assertEquals(g1, g2); 162 163 } 164 165 } 166 | Popular Tags |