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 import java.util.Date ; 53 54 import junit.framework.Test; 55 import junit.framework.TestCase; 56 import junit.framework.TestSuite; 57 58 import org.jfree.data.time.DateRange; 59 60 63 public class DateRangeTests extends TestCase { 64 65 70 public static Test suite() { 71 return new TestSuite(DateRangeTests.class); 72 } 73 74 79 public DateRangeTests(String name) { 80 super(name); 81 } 82 83 86 public void testEquals() { 87 DateRange r1 = new DateRange(new Date (1000L), new Date (2000L)); 88 DateRange r2 = new DateRange(new Date (1000L), new Date (2000L)); 89 assertTrue(r1.equals(r2)); 90 assertTrue(r2.equals(r1)); 91 92 r1 = new DateRange(new Date (1111L), new Date (2000L)); 93 assertFalse(r1.equals(r2)); 94 r2 = new DateRange(new Date (1111L), new Date (2000L)); 95 assertTrue(r1.equals(r2)); 96 97 r1 = new DateRange(new Date (1111L), new Date (2222L)); 98 assertFalse(r1.equals(r2)); 99 r2 = new DateRange(new Date (1111L), new Date (2222L)); 100 assertTrue(r1.equals(r2)); 101 } 102 103 106 public void testSerialization() { 107 DateRange r1 = new DateRange(new Date (1000L), new Date (2000L)); 108 DateRange r2 = null; 109 110 try { 111 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 112 ObjectOutput out = new ObjectOutputStream (buffer); 113 out.writeObject(r1); 114 out.close(); 115 116 ObjectInput in = new ObjectInputStream ( 117 new ByteArrayInputStream (buffer.toByteArray()) 118 ); 119 r2 = (DateRange) in.readObject(); 120 in.close(); 121 } 122 catch (Exception e) { 123 System.out.println(e.toString()); 124 } 125 assertEquals(r1, r2); 126 } 127 128 132 public void testClone() { 133 DateRange r1 = new DateRange(new Date (1000L), new Date (2000L)); 134 assertFalse(r1 instanceof Cloneable ); 135 } 136 137 } 138 | Popular Tags |