1 41 42 package org.jfree.chart.plot.junit; 43 44 import java.io.ByteArrayInputStream ; 45 import java.io.ByteArrayOutputStream ; 46 import java.io.ObjectInput ; 47 import java.io.ObjectInputStream ; 48 import java.io.ObjectOutput ; 49 import java.io.ObjectOutputStream ; 50 51 import junit.framework.Test; 52 import junit.framework.TestCase; 53 import junit.framework.TestSuite; 54 55 import org.jfree.chart.plot.CompassPlot; 56 import org.jfree.data.general.DefaultValueDataset; 57 58 61 public class CompassPlotTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(CompassPlotTests.class); 70 } 71 72 77 public CompassPlotTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 CompassPlot plot1 = new CompassPlot(); 86 CompassPlot plot2 = new CompassPlot(); 87 assertTrue(plot1.equals(plot2)); 88 89 plot1.setLabelType(CompassPlot.VALUE_LABELS); 91 assertFalse(plot1.equals(plot2)); 92 plot2.setLabelType(CompassPlot.VALUE_LABELS); 93 assertTrue(plot1.equals(plot2)); 94 95 } 96 97 100 public void testSerialization() { 101 102 CompassPlot p1 = new CompassPlot(null); 103 CompassPlot p2 = null; 104 105 try { 106 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 107 ObjectOutput out = new ObjectOutputStream (buffer); 108 out.writeObject(p1); 109 out.close(); 110 111 ObjectInput in = new ObjectInputStream ( 112 new ByteArrayInputStream (buffer.toByteArray()) 113 ); 114 p2 = (CompassPlot) in.readObject(); 115 in.close(); 116 } 117 catch (Exception e) { 118 System.out.println(e.toString()); 119 } 120 assertEquals(p1, p2); 121 122 } 123 124 127 public void testCloning() { 128 CompassPlot p1 = new CompassPlot(new DefaultValueDataset(15.0)); 129 CompassPlot p2 = null; 130 try { 131 p2 = (CompassPlot) p1.clone(); 132 } 133 catch (CloneNotSupportedException e) { 134 e.printStackTrace(); 135 System.err.println("Failed to clone."); 136 } 137 assertTrue(p1 != p2); 138 assertTrue(p1.getClass() == p2.getClass()); 139 assertTrue(p1.equals(p2)); 140 } 141 142 } 143 | Popular Tags |