1 45 46 package org.jfree.data.time.junit; 47 48 import java.io.ByteArrayInputStream ; 49 import java.io.ByteArrayOutputStream ; 50 import java.io.ObjectInput ; 51 import java.io.ObjectInputStream ; 52 import java.io.ObjectOutput ; 53 import java.io.ObjectOutputStream ; 54 import java.util.Date ; 55 import java.util.TimeZone ; 56 57 import junit.framework.Test; 58 import junit.framework.TestCase; 59 import junit.framework.TestSuite; 60 61 import org.jfree.data.time.Day; 62 import org.jfree.data.time.Hour; 63 import org.jfree.data.time.Minute; 64 import org.jfree.date.MonthConstants; 65 66 69 public class MinuteTests extends TestCase { 70 71 76 public static Test suite() { 77 return new TestSuite(MinuteTests.class); 78 } 79 80 85 public MinuteTests(String name) { 86 super(name); 87 } 88 89 92 protected void setUp() { 93 } 95 96 101 public void testEqualsSelf() { 102 Minute minute = new Minute(); 103 assertTrue(minute.equals(minute)); 104 } 105 106 109 public void testEquals() { 110 Day day1 = new Day(29, MonthConstants.MARCH, 2002); 111 Hour hour1 = new Hour(15, day1); 112 Minute minute1 = new Minute(15, hour1); 113 Day day2 = new Day(29, MonthConstants.MARCH, 2002); 114 Hour hour2 = new Hour(15, day2); 115 Minute minute2 = new Minute(15, hour2); 116 assertTrue(minute1.equals(minute2)); 117 } 118 119 123 public void testDateConstructor1() { 124 125 TimeZone zone = TimeZone.getTimeZone("GMT"); 126 Minute m1 = new Minute(new Date (1016729699999L), zone); 127 Minute m2 = new Minute(new Date (1016729700000L), zone); 128 129 assertEquals(54, m1.getMinute()); 130 assertEquals(1016729699999L, m1.getLastMillisecond(zone)); 131 132 assertEquals(55, m2.getMinute()); 133 assertEquals(1016729700000L, m2.getFirstMillisecond(zone)); 134 135 } 136 137 142 public void testDateConstructor2() { 143 144 TimeZone zone = TimeZone.getTimeZone("Asia/Singapore"); 145 Minute m1 = new Minute(new Date (1016700899999L), zone); 146 Minute m2 = new Minute(new Date (1016700900000L), zone); 147 148 assertEquals(54, m1.getMinute()); 149 assertEquals(1016700899999L, m1.getLastMillisecond(zone)); 150 151 assertEquals(55, m2.getMinute()); 152 assertEquals(1016700900000L, m2.getFirstMillisecond(zone)); 153 154 } 155 156 159 public void testSerialization() { 160 161 Minute m1 = new Minute(); 162 Minute m2 = null; 163 164 try { 165 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 166 ObjectOutput out = new ObjectOutputStream (buffer); 167 out.writeObject(m1); 168 out.close(); 169 170 ObjectInput in = new ObjectInputStream ( 171 new ByteArrayInputStream (buffer.toByteArray()) 172 ); 173 m2 = (Minute) in.readObject(); 174 in.close(); 175 } 176 catch (Exception e) { 177 System.out.println(e.toString()); 178 } 179 assertEquals(m1, m2); 180 181 } 182 183 186 public void testHashcode() { 187 Minute m1 = new Minute(45, 5, 1, 2, 2003); 188 Minute m2 = new Minute(45, 5, 1, 2, 2003); 189 assertTrue(m1.equals(m2)); 190 int h1 = m1.hashCode(); 191 int h2 = m2.hashCode(); 192 assertEquals(h1, h2); 193 } 194 195 199 public void testNotCloneable() { 200 Minute m = new Minute(45, 5, 1, 2, 2003); 201 assertFalse(m instanceof Cloneable ); 202 } 203 204 } 205 | Popular Tags |