1 42 43 package org.jfree.data.statistics.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.data.statistics.HistogramBin; 57 58 61 public class HistogramBinTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(HistogramBinTests.class); 70 } 71 72 77 public HistogramBinTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 86 double start = 10.0; 87 double end = 20.0; 88 HistogramBin b1 = new HistogramBin(start, end); 89 HistogramBin b2 = new HistogramBin(start, end); 90 91 assertTrue(b1.equals(b2)); 92 assertTrue(b2.equals(b1)); 93 94 } 95 96 99 public void testCloning() { 100 double start = 10.0; 101 double end = 20.0; 102 HistogramBin b1 = new HistogramBin(start, end); 103 HistogramBin b2 = null; 104 try { 105 b2 = (HistogramBin) b1.clone(); 106 } 107 catch (CloneNotSupportedException e) { 108 System.err.println("Failed to clone."); 109 } 110 assertTrue(b1 != b2); 111 assertTrue(b1.getClass() == b2.getClass()); 112 assertTrue(b1.equals(b2)); 113 } 114 115 118 public void testSerialization() { 119 120 double start = 10.0; 121 double end = 20.0; 122 HistogramBin b1 = new HistogramBin(start, end); 123 HistogramBin b2 = null; 124 125 try { 126 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 127 ObjectOutput out = new ObjectOutputStream (buffer); 128 out.writeObject(b1); 129 out.close(); 130 131 ObjectInput in = new ObjectInputStream ( 132 new ByteArrayInputStream (buffer.toByteArray()) 133 ); 134 b2 = (HistogramBin) in.readObject(); 135 in.close(); 136 } 137 catch (Exception e) { 138 System.out.println(e.toString()); 139 } 140 assertEquals(b1, b2); 141 142 } 143 144 } 145 | Popular Tags |