1 43 44 package org.jfree.data.time.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 53 import junit.framework.Test; 54 import junit.framework.TestCase; 55 import junit.framework.TestSuite; 56 57 import org.jfree.data.time.FixedMillisecond; 58 59 62 public class FixedMillisecondTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(FixedMillisecondTests.class); 71 } 72 73 78 public FixedMillisecondTests(String name) { 79 super(name); 80 } 81 82 85 public void testSerialization() { 86 87 FixedMillisecond m1 = new FixedMillisecond(); 88 FixedMillisecond m2 = null; 89 90 try { 91 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 92 ObjectOutput out = new ObjectOutputStream (buffer); 93 out.writeObject(m1); 94 out.close(); 95 96 ObjectInput in = new ObjectInputStream ( 97 new ByteArrayInputStream (buffer.toByteArray()) 98 ); 99 m2 = (FixedMillisecond) in.readObject(); 100 in.close(); 101 } 102 catch (Exception e) { 103 System.out.println(e.toString()); 104 } 105 assertEquals(m1, m2); 106 107 } 108 109 112 public void testHashcode() { 113 FixedMillisecond m1 = new FixedMillisecond(500000L); 114 FixedMillisecond m2 = new FixedMillisecond(500000L); 115 assertTrue(m1.equals(m2)); 116 int h1 = m1.hashCode(); 117 int h2 = m2.hashCode(); 118 assertEquals(h1, h2); 119 } 120 121 125 public void testNotCloneable() { 126 FixedMillisecond m = new FixedMillisecond(500000L); 127 assertFalse(m instanceof Cloneable ); 128 } 129 130 } 131 | Popular Tags |