1 44 45 package org.jfree.date.junit; 46 47 import java.io.ByteArrayInputStream ; 48 import java.io.ByteArrayOutputStream ; 49 import java.io.ObjectInput ; 50 import java.io.ObjectInputStream ; 51 import java.io.ObjectOutput ; 52 import java.io.ObjectOutputStream ; 53 54 import junit.framework.Test; 55 import junit.framework.TestCase; 56 import junit.framework.TestSuite; 57 58 import org.jfree.date.MonthConstants; 59 import org.jfree.date.SerialDate; 60 import org.jfree.date.SpreadsheetDate; 61 62 65 public class SpreadsheetDateTests extends TestCase { 66 67 68 private SerialDate jan1Y1900; 69 70 71 private SerialDate s2; 72 73 78 public static Test suite() { 79 return new TestSuite(SpreadsheetDateTests.class); 80 } 81 82 87 public SpreadsheetDateTests(final String name) { 88 super(name); 89 } 90 91 94 protected void setUp() { 95 this.jan1Y1900 = new SpreadsheetDate(1, MonthConstants.JANUARY, 1900); 96 this.s2 = new SpreadsheetDate(2); 97 } 98 99 102 public void test1Jan1900GetDayOfWeek() { 103 final int dayOfWeek = this.jan1Y1900.getDayOfWeek(); 104 assertEquals(SerialDate.MONDAY, dayOfWeek); 105 } 106 107 110 public void test12Nov2001GetDayOfWeek() { 111 SerialDate nov12Y2001 = new SpreadsheetDate(12, 112 MonthConstants.NOVEMBER, 2001); 113 int dayOfWeek = nov12Y2001.getDayOfWeek(); 114 assertEquals(SerialDate.MONDAY, dayOfWeek); 115 } 116 117 120 public void testS2GetDayOfMonth() { 121 final int dayOfMonth = this.s2.getDayOfMonth(); 122 assertEquals(1, dayOfMonth); 123 } 124 125 128 public void testS2GetMonth() { 129 final int month = this.s2.getMonth(); 130 assertEquals(MonthConstants.JANUARY, month); 131 } 132 133 136 public void testS2GetYYYY() { 137 final int year = this.s2.getYYYY(); 138 assertEquals(1900, year); 139 } 140 141 144 public void test37986() { 145 final SpreadsheetDate d = new SpreadsheetDate(37986); 146 assertEquals(31, d.getDayOfMonth()); 147 assertEquals(MonthConstants.DECEMBER, d.getMonth()); 148 assertEquals(2003, d.getYYYY()); 149 } 150 151 154 public void test37987() { 155 final SpreadsheetDate d = new SpreadsheetDate(37987); 156 assertEquals(1, d.getDayOfMonth()); 157 assertEquals(MonthConstants.JANUARY, d.getMonth()); 158 assertEquals(2004, d.getYYYY()); 159 } 160 161 164 public void test38352() { 165 final SpreadsheetDate d = new SpreadsheetDate(38352); 166 assertEquals(31, d.getDayOfMonth()); 167 assertEquals(MonthConstants.DECEMBER, d.getMonth()); 168 assertEquals(2004, d.getYYYY()); 169 } 170 171 174 public void test38353() { 175 final SpreadsheetDate d = new SpreadsheetDate(38353); 176 assertEquals(1, d.getDayOfMonth()); 177 assertEquals(MonthConstants.JANUARY, d.getMonth()); 178 assertEquals(2005, d.getYYYY()); 179 } 180 181 184 public void test36584() { 185 final SpreadsheetDate d = new SpreadsheetDate(36584); 186 assertEquals(28, d.getDayOfMonth()); 187 assertEquals(MonthConstants.FEBRUARY, d.getMonth()); 188 assertEquals(2000, d.getYYYY()); 189 } 190 191 194 public void test36585() { 195 final SpreadsheetDate d = new SpreadsheetDate(36585); 196 assertEquals(29, d.getDayOfMonth()); 197 assertEquals(MonthConstants.FEBRUARY, d.getMonth()); 198 assertEquals(2000, d.getYYYY()); 199 } 200 201 204 public void test36586() { 205 final SpreadsheetDate d = new SpreadsheetDate(36586); 206 assertEquals(1, d.getDayOfMonth()); 207 assertEquals(MonthConstants.MARCH, d.getMonth()); 208 assertEquals(2000, d.getYYYY()); 209 } 210 211 214 public void test01Jan1900ToSerial() { 215 final int serial = this.jan1Y1900.toSerial(); 216 assertEquals(2, serial); 217 } 218 219 222 public void test28Feb1900ToSerial() { 223 SpreadsheetDate d = new SpreadsheetDate(28, MonthConstants.FEBRUARY, 224 1900); 225 assertEquals(60, d.toSerial()); 226 } 227 228 231 public void test01Mar1900ToSerial() { 232 SpreadsheetDate d = new SpreadsheetDate(1, MonthConstants.MARCH, 1900); 233 assertEquals(61, d.toSerial()); 234 } 235 236 239 public void test31Dec1999ToSerial() { 240 SpreadsheetDate d = new SpreadsheetDate(31, MonthConstants.DECEMBER, 241 1999); 242 assertEquals(36525, d.toSerial()); 243 } 244 245 248 public void test01Jan2000ToSerial() { 249 SpreadsheetDate d = new SpreadsheetDate(1, MonthConstants.JANUARY, 250 2000); 251 assertEquals(36526, d.toSerial()); 252 } 253 254 257 public void test31Jan2000ToSerial() { 258 SpreadsheetDate d = new SpreadsheetDate(31, MonthConstants.JANUARY, 259 2000); 260 assertEquals(36556, d.toSerial()); 261 } 262 263 266 public void test01Feb2000ToSerial() { 267 SpreadsheetDate d = new SpreadsheetDate(1, MonthConstants.FEBRUARY, 268 2000); 269 assertEquals(36557, d.toSerial()); 270 } 271 272 275 public void test28Feb2000ToSerial() { 276 SpreadsheetDate d = new SpreadsheetDate(28, MonthConstants.FEBRUARY, 277 2000); 278 assertEquals(36584, d.toSerial()); 279 } 280 281 284 public void test29feb2000ToSerial() { 285 SpreadsheetDate d = new SpreadsheetDate(29, MonthConstants.FEBRUARY, 286 2000); 287 assertEquals(36585, d.toSerial()); 288 } 289 290 293 public void test1mar2000ToSerial() { 294 SpreadsheetDate d = new SpreadsheetDate(1, MonthConstants.MARCH, 2000); 295 assertEquals(36586, d.toSerial()); 296 } 297 298 301 public void testSerialization() { 302 303 final SpreadsheetDate d1 = new SpreadsheetDate(15, 4, 2000); 304 SpreadsheetDate d2 = null; 305 306 try { 307 final ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 308 final ObjectOutput out = new ObjectOutputStream (buffer); 309 out.writeObject(d1); 310 out.close(); 311 312 ObjectInput in = new ObjectInputStream (new ByteArrayInputStream ( 313 buffer.toByteArray())); 314 d2 = (SpreadsheetDate) in.readObject(); 315 in.close(); 316 } 317 catch (Exception e) { 318 System.out.println(e.toString()); 319 } 320 assertEquals(d1, d2); 321 322 } 323 324 327 public void testGetDescription() { 328 SpreadsheetDate d1 = new SpreadsheetDate(15, 4, 2000); 329 assertEquals(null, d1.getDescription()); 330 d1.setDescription("XYZ"); 331 assertEquals("XYZ", d1.getDescription()); 332 } 333 334 337 public void testSetDescription() { 338 SpreadsheetDate d1 = new SpreadsheetDate(15, 4, 2000); 339 assertEquals(null, d1.getDescription()); 340 d1.setDescription("XYZ"); 341 assertEquals("XYZ", d1.getDescription()); 342 d1.setDescription(null); 343 assertEquals(null, d1.getDescription()); 344 } 345 346 } 347 | Popular Tags |