1 38 39 package org.jfree.chart.labels.junit; 40 41 import java.io.ByteArrayInputStream ; 42 import java.io.ByteArrayOutputStream ; 43 import java.io.ObjectInput ; 44 import java.io.ObjectInputStream ; 45 import java.io.ObjectOutput ; 46 import java.io.ObjectOutputStream ; 47 import java.text.DateFormat ; 48 49 import junit.framework.Test; 50 import junit.framework.TestCase; 51 import junit.framework.TestSuite; 52 53 import org.jfree.chart.labels.IntervalCategoryItemLabelGenerator; 54 55 60 public class IntervalCategoryItemLabelGeneratorTests extends TestCase { 61 62 67 public static Test suite() { 68 return new TestSuite(IntervalCategoryItemLabelGeneratorTests.class); 69 } 70 71 76 public IntervalCategoryItemLabelGeneratorTests(String name) { 77 super(name); 78 } 79 80 83 public void testCloning() { 84 IntervalCategoryItemLabelGenerator g1 = new IntervalCategoryItemLabelGenerator(); 85 IntervalCategoryItemLabelGenerator g2 = null; 86 try { 87 g2 = (IntervalCategoryItemLabelGenerator) g1.clone(); 88 } 89 catch (CloneNotSupportedException e) { 90 System.err.println("IntervalCategoryItemLabelGenerator.testCloning: failed to clone."); 91 } 92 assertTrue(g1 != g2); 93 assertTrue(g1.getClass() == g2.getClass()); 94 assertTrue(g1.equals(g2)); 95 } 96 97 100 public void testSerialization() { 101 102 IntervalCategoryItemLabelGenerator g1 103 = new IntervalCategoryItemLabelGenerator(DateFormat.getInstance()); 104 IntervalCategoryItemLabelGenerator g2 = null; 105 106 try { 107 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 108 ObjectOutput out = new ObjectOutputStream (buffer); 109 out.writeObject(g1); 110 out.close(); 111 112 ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 113 g2 = (IntervalCategoryItemLabelGenerator) in.readObject(); 114 in.close(); 115 } 116 catch (Exception e) { 117 System.out.println(e.toString()); 118 } 119 assertEquals(g1, g2); 120 121 } 122 123 } 124 | Popular Tags |