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 52 import junit.framework.Test; 53 import junit.framework.TestCase; 54 import junit.framework.TestSuite; 55 56 import org.jfree.chart.labels.StandardCategorySeriesLabelGenerator; 57 import org.jfree.data.category.DefaultCategoryDataset; 58 59 62 public class StandardCategorySeriesLabelGeneratorTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(StandardCategorySeriesLabelGeneratorTests.class); 71 } 72 73 78 public StandardCategorySeriesLabelGeneratorTests(String name) { 79 super(name); 80 } 81 82 85 public void testGenerateLabel() { 86 StandardCategorySeriesLabelGenerator g 87 = new StandardCategorySeriesLabelGenerator("{0}"); 88 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 89 dataset.addValue(1.0, "R0", "C0"); 90 dataset.addValue(2.0, "R0", "C1"); 91 dataset.addValue(3.0, "R1", "C0"); 92 dataset.addValue(null, "R1", "C1"); 93 String s = g.generateLabel(dataset, 0); 94 assertEquals("R0", s); 95 } 96 97 100 public void testEquals() { 101 StandardCategorySeriesLabelGenerator g1 102 = new StandardCategorySeriesLabelGenerator(); 103 StandardCategorySeriesLabelGenerator g2 104 = new StandardCategorySeriesLabelGenerator(); 105 assertTrue(g1.equals(g2)); 106 assertTrue(g2.equals(g1)); 107 108 g1 = new StandardCategorySeriesLabelGenerator("{1}"); 109 assertFalse(g1.equals(g2)); 110 g2 = new StandardCategorySeriesLabelGenerator("{1}"); 111 assertTrue(g1.equals(g2)); 112 } 113 114 117 public void testCloning() { 118 StandardCategorySeriesLabelGenerator g1 119 = new StandardCategorySeriesLabelGenerator("{1}"); 120 StandardCategorySeriesLabelGenerator g2 = null; 121 try { 122 g2 = (StandardCategorySeriesLabelGenerator) g1.clone(); 123 } 124 catch (CloneNotSupportedException e) { 125 System.err.println("Failed to clone."); 126 } 127 assertTrue(g1 != g2); 128 assertTrue(g1.getClass() == g2.getClass()); 129 assertTrue(g1.equals(g2)); 130 } 131 132 135 public void testSerialization() { 136 137 StandardCategorySeriesLabelGenerator g1 138 = new StandardCategorySeriesLabelGenerator("{2}"); 139 StandardCategorySeriesLabelGenerator g2 = null; 140 141 try { 142 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 143 ObjectOutput out = new ObjectOutputStream (buffer); 144 out.writeObject(g1); 145 out.close(); 146 147 ObjectInput in = new ObjectInputStream ( 148 new ByteArrayInputStream (buffer.toByteArray())); 149 g2 = (StandardCategorySeriesLabelGenerator) in.readObject(); 150 in.close(); 151 } 152 catch (Exception e) { 153 System.out.println(e.toString()); 154 } 155 assertEquals(g1, g2); 156 157 } 158 159 } 160 | Popular Tags |