test/java/sql/test/sql/TimestampTests.java

Print this page




  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package test.sql;
  24 
  25 import java.sql.Date;
  26 import java.sql.Time;
  27 import java.sql.Timestamp;
  28 import java.time.Instant;
  29 import java.time.LocalDateTime;
  30 import java.util.Calendar;
  31 import static org.testng.Assert.*;
  32 import org.testng.annotations.AfterClass;
  33 import org.testng.annotations.AfterMethod;
  34 import org.testng.annotations.BeforeClass;
  35 import org.testng.annotations.BeforeMethod;
  36 import org.testng.annotations.Test;

  37 
  38 public class TimestampTests {
  39 
  40     public TimestampTests() {
  41     }
  42 
  43     @BeforeClass
  44     public static void setUpClass() throws Exception {
  45     }
  46 
  47     @AfterClass
  48     public static void tearDownClass() throws Exception {
  49     }
  50 
  51     @BeforeMethod
  52     public void setUpMethod() throws Exception {
  53     }
  54 
  55     @AfterMethod
  56     public void tearDownMethod() throws Exception {
  57     }
  58 
  59     /**
  60      * Validate an IllegalArgumentException is thrown for an invalid Timestamp
  61      */
  62     @Test(expectedExceptions = IllegalArgumentException.class)
  63     public void testInvalid_timestamp() throws Exception {
  64         String testTS = "2009-11-01-01 10:50";
  65         Timestamp.valueOf(testTS);
  66     }
  67 
  68     /**
  69      * Validate an IllegalArgumentException is thrown for an invalid Timestamp
  70      */
  71     @Test(expectedExceptions = IllegalArgumentException.class)
  72     public void testInvalid_year2() throws Exception {
  73         String testTS = "aaaa-11-01-01 10:50";
  74         Timestamp.valueOf(testTS);
  75     }
  76 
  77     /**
  78      * Validate an IllegalArgumentException is thrown for an invalid Timestamp
  79      */
  80     @Test(expectedExceptions = IllegalArgumentException.class)
  81     public void testInvalid_year3() throws Exception {
  82         String testTS = "aaaa-11-01 10:50";
  83         Timestamp.valueOf(testTS);
  84     }
  85 
  86     /**
  87      * Validate that two Timestamp are equal when the leading 0 in seconds is
  88      * omitted
  89      */
  90     @Test
  91     public void test1() throws Exception {
  92         String testTS = "2009-01-01 10:50:00";
  93         String ExpectedTS = "2009-01-01 10:50:0";
  94         Timestamp ts = Timestamp.valueOf(testTS);
  95         Timestamp ts2 = Timestamp.valueOf(ExpectedTS);
  96         assertEquals(ts, ts2, "Error ts1 != ts2");
  97     }
  98 
  99     /**
 100      * Validate two Timestamps created from the same string are equal
 101      */
 102     @Test
 103     public void test2() throws Exception {
 104         String testTS = "2009-01-01 10:50:0";
 105         Timestamp ts = Timestamp.valueOf(testTS);
 106         Timestamp ts2 = Timestamp.valueOf(testTS);
 107         assertEquals(ts, ts2, "Error ts1 != ts2");
 108     }
 109 
 110     /**
 111      * Validate that two Timestamp values one with leading 0s for month and day
 112      * equals same string without the leading 0s.
 113      */
 114     @Test
 115     public void test3() throws Exception {
 116         String testTS = "2009-1-1 10:50:0";
 117         String ExpectedTS = "2009-01-01 10:50:0";
 118         Timestamp ts = Timestamp.valueOf(testTS);
 119         Timestamp ts2 = Timestamp.valueOf(ExpectedTS);
 120         assertEquals(ts, ts2, "Error ts1 != ts2");
 121     }
 122 
 123     /**
 124      * Validate that two Timestamp values one with leading 0s for day omitted
 125      * are equal
 126      */
 127     @Test
 128     public void test4() throws Exception {
 129         String testTS = "2009-01-1 10:50:0";
 130         String ExpectedTS = "2009-01-01 10:50:0";
 131         Timestamp ts = Timestamp.valueOf(testTS);
 132         Timestamp ts2 = Timestamp.valueOf(ExpectedTS);
 133         assertEquals(ts, ts2, "Error ts1 != ts2");
 134     }
 135 
 136     /**
 137      * Validate that two Timestamp values one with leading 0s for month omitted
 138      * and both with leading 0s for seconds omitted are equal
 139      */
 140     @Test
 141     public void test5() throws Exception {
 142         String testTS = "2009-1-01 10:50:0";
 143         String ExpectedTS = "2009-01-01 10:50:0";
 144         Timestamp ts = Timestamp.valueOf(testTS);
 145         Timestamp ts2 = Timestamp.valueOf(ExpectedTS);
 146         assertEquals(ts, ts2, "Error ts1 != ts2");
 147     }
 148 
 149     /**
 150      * Validate that two Timestamp values one with leading 0s for month omitted
 151      */
 152     @Test
 153     public void test6() throws Exception {
 154         String testTS = "2005-1-01 10:20:50.00";
 155         String ExpectedTS = "2005-01-01 10:20:50.00";
 156         Timestamp ts = Timestamp.valueOf(testTS);
 157         Timestamp ts2 = Timestamp.valueOf(ExpectedTS);
 158         assertEquals(ts, ts2, "Error ts1 != ts2");
 159     }
 160 
 161     /**
 162      * Validate that two Timestamp values one created using valueOf and another
 163      * via a constructor are equal
 164      */
 165     @Test
 166     public void test7() {
 167 
 168         Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.001");
 169         Timestamp ts2 = new Timestamp(96, 11, 13, 14, 15, 25, 1000000);
 170         assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
 171     }
 172 
 173     /**
 174      * Validate that two Timestamp values one created using valueOf and another
 175      * via a constructor are equal
 176      */
 177     @Test
 178     public void test8() {
 179         Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.001");
 180         Timestamp ts2 = new Timestamp(ts1.getTime());
 181         assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
 182     }
 183 
 184     /**
 185      * Validate that two Timestamp values one created using valueOf and another
 186      * via a constructor are equal
 187      */
 188     @Test
 189     public void test9() {
 190 
 191         Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.0");
 192         Timestamp ts2 = new Timestamp(96, 11, 13, 14, 15, 25, 0);
 193         assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
 194     }
 195 
 196     /**
 197      * Validate that a Timestamp cannot be equal to null
 198      */
 199     @Test
 200     public void test10() {
 201 
 202         Timestamp ts1 = Timestamp.valueOf("1961-08-30 14:15:25.745634");
 203         assertFalse(ts1.equals(null), "Error ts1 == null");

 204     }
 205 
 206     /**
 207      * Validate that a Timestamp is equal to another timestamp created with the
 208      * using the same value but not equal to a Timestamp which is one day later
 209      */
 210     @Test
 211     public void test11() {
 212 
 213         Timestamp ts1 = Timestamp.valueOf("1996-12-10 12:26:19.12");
 214         Timestamp ts2 = Timestamp.valueOf("1996-12-10 12:26:19.12");
 215         Timestamp ts3 = Timestamp.valueOf("1996-12-11 12:24:19.12");
 216         assertTrue(ts1.equals(ts2) && ts2.equals(ts1), "Error ts1 != ts2");
 217         assertFalse(ts1.equals(ts3) && ts3.equals(ts1), "Error ts1 == ts3");
 218 
 219     }
 220 
 221     /**
 222      * Validate that a Timestamp is equal to itself
 223      */
 224     @Test
 225     public void test12() {
 226         Timestamp ts1 = Timestamp.valueOf("1996-10-15 12:26:19.12");
 227         assertTrue(ts1.equals(ts1), "Error ts1 != ts1");
 228     }
 229 
 230     /**
 231      * Validate that two Timestamps are equal when one is created from the
 232      * toString() of the other
 233      */
 234     @Test
 235     public void test13() {
 236         Timestamp ts1 = Timestamp.valueOf("1996-12-10 12:26:19.12");
 237         Timestamp ts2 = Timestamp.valueOf(ts1.toString());
 238         assertTrue(ts1.equals(ts2) && ts2.equals(ts1), "Error ts1 != ts2");

 239     }
 240 
 241     // Before Tests
 242     /**
 243      * Validate that Timestamp ts1 is before Timestamp ts2
 244      */
 245     @Test
 246     public void test14() {
 247         Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.745634");
 248         Timestamp ts2 = Timestamp.valueOf("1996-12-13 15:15:25.645634");
 249         assertTrue(ts1.before(ts2), "Error ts1 not before ts2");
 250     }
 251 
 252     /**
 253      * Validate that Timestamp ts1 is before Timestamp ts2
 254      */
 255     @Test
 256     public void test15() {
 257         Timestamp ts1 = Timestamp.valueOf("1961-08-30 14:15:25");
 258         Timestamp ts2 = Timestamp.valueOf("1999-12-13 15:15:25");
 259         assertTrue(ts1.before(ts2), "Error ts1 not before ts2");
 260     }
 261 
 262     /**
 263      * Validate that Timestamp ts1 is before Timestamp ts2
 264      */
 265     @Test
 266     public void test16() {
 267 
 268         Timestamp ts1 = Timestamp.valueOf("1999-12-13 14:15:25.745634");
 269         Timestamp ts2 = Timestamp.valueOf("1999-11-13 15:15:25.645634");
 270         assertFalse(ts1.before(ts2), "Error ts1 before ts2");
 271     }
 272 
 273     /*
 274      * Validate that a NullPointerException is thrown if a null is passed to
 275      * the before method
 276      */
 277     @Test(expectedExceptions = NullPointerException.class)
 278     public void test17() throws Exception {
 279         Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.745634");
 280         ts1.before(null);
 281     }
 282 
 283     /*
 284      * Validate a Timestamp cannot be before itself
 285      */
 286     @Test
 287     public void test18() {
 288         Timestamp ts1 = Timestamp.valueOf("1999-11-10 12:26:19.3456543");
 289         assertFalse(ts1.before(ts1), "Error ts1 before ts1!");
 290     }
 291 
 292     /**
 293      * Create 3 Timestamps and make sure the 1st is before the other two
 294      * Timestamps which are each greater than the one before it
 295      */
 296     @Test
 297     public void test19() {
 298 
 299         Timestamp ts1 = new Timestamp(1234560000);
 300         Timestamp ts2 = new Timestamp(1234567000);
 301         Timestamp ts3 = new Timestamp(1234569000);
 302         assertTrue(ts1.before(ts2) && ts2.before(ts3) && ts1.before(ts3));
 303     }
 304 
 305     /**
 306      * Validate that Timestamp ts1 is not after Timestamp ts2
 307      */
 308     @Test
 309     public void test20() {
 310         Timestamp ts1 = Timestamp.valueOf("1999-12-13 14:15:25.745634");
 311         Timestamp ts2 = Timestamp.valueOf("1999-12-13 15:15:25.645634");
 312         assertFalse(ts1.after(ts2), "Error ts1 is after ts2");
 313 
 314     }
 315 
 316     /**
 317      * Validate that Timestamp ts1 is after Timestamp ts2
 318      */
 319     @Test
 320     public void test21() {
 321         Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.745634");
 322         Timestamp ts2 = Timestamp.valueOf("1996-11-13 15:15:25.645634");
 323         assertTrue(ts1.after(ts2), "Error ts1 not after ts2");
 324     }
 325 
 326     /**
 327      * Validate that a NullPointerException is thrown if a null is passed to the
 328      * after method
 329      */
 330     @Test(expectedExceptions = NullPointerException.class)
 331     public void test22() throws Exception {
 332         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 333         ts1.after(null);
 334     }
 335 
 336     /**
 337      * Validate that a Timestamp cannot be after itself
 338      */
 339     @Test
 340     public void test23() {
 341         Timestamp ts1 = Timestamp.valueOf("1999-11-10 12:26:19.3456543");
 342         assertFalse(ts1.after(ts1), "Error ts1 is after itself");
 343     }
 344     /**
 345      * Validate that a Timestamp after() works correctly with Timestamp
 346      * created using milliseconds

 347      */
 348     @Test
 349     public void test24() {
 350 
 351         Timestamp ts1 = new Timestamp(1234568000);
 352         Timestamp ts2 = new Timestamp(1234565000);
 353         Timestamp ts3 = new Timestamp(1234562000);
 354         assertTrue(ts1.after(ts2) && ts2.after(ts3) && ts1.after(ts3));
 355     }
 356 
 357     /**
 358      * Validate compareTo returns 0 for Timestamps that are the same
 359      */
 360     @Test
 361     public void test25() {
 362         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 363         Timestamp ts2 = new Timestamp(ts1.getTime());
 364         assertTrue(ts1.compareTo(ts2) == 0, "Error ts1 != ts2");
 365     }
 366 
 367     /**
 368      * Validate compareTo returns -1 for when the 1st Timestamp is earlier than
 369      * the 2nd Timestamp
 370      */
 371     @Test
 372     public void test26() {
 373         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 374         Timestamp ts2 = new Timestamp(ts1.getTime() + 1000);
 375         assertTrue(ts1.compareTo(ts2) == -1, "Error ts1 not before ts2");
 376         assertTrue(ts2.compareTo(ts1) == 1, "Error ts1 is not before ts2");
 377     }
 378 
 379     /**
 380      * Validate compareTo returns 1 for when the 1st Timestamp is later than the
 381      * 2nd Timestamp
 382      */
 383     @Test
 384     public void test27() {
 385         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 386         Timestamp ts2 = new Timestamp(ts1.getTime() - 1000);
 387         assertTrue(ts1.compareTo(ts2) == 1, "Error ts1 not after ts2");
 388         assertTrue(ts2.compareTo(ts1) == -1, "Error ts1 not after ts2");
 389     }
 390 
 391     /**
 392      * Validate compareTo returns 0 for Timestamps that are the same
 393      */
 394     @Test
 395     public void test28() {
 396         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 397         java.util.Date ts2 = new java.util.Date(ts1.getTime());
 398         assertTrue(ts1.compareTo(ts2) == 0, "Error ts1 != ts2");
 399     }
 400 
 401     /**
 402      * Validate compareTo returns 0 for Timestamps that are the same
 403      */
 404     @Test
 405     public void test29() {
 406         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 407         java.util.Date d = new java.util.Date(ts1.getTime());
 408         assertFalse(ts1.equals(d), "Error ts1 == d");
 409     }
 410 
 411     /**
 412      * Validate compareTo returns 0 for Timestamps that are the same
 413      */
 414     @Test
 415     public void test30() {
 416         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 417         java.util.Date d = new Timestamp(ts1.getTime());
 418         assertTrue(ts1.equals(d), "Error ts1 != d");
 419     }
 420 
 421     /**
 422      * Validate equals returns false when a Date object is passed to equals
 423      */
 424     @Test
 425     public void test31() {
 426         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 427         Date d = new Date(ts1.getTime());
 428         assertFalse(ts1.equals(d), "Error ts1 != d");
 429     }
 430 
 431     /**
 432      * Validate equals returns false when a Date object is passed to equals
 433      */
 434     @Test
 435     public void test32() {
 436         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 437         java.util.Date d = new Date(ts1.getTime());
 438         assertFalse(ts1.equals(d), "Error ts1 != d");
 439     }
 440 
 441     /**
 442      * Validate equals returns false when a Time object is passed to equals
 443      */
 444     @Test
 445     public void test33() {
 446         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 447         Time t1 = new Time(ts1.getTime());
 448         assertFalse(ts1.equals(t1), "Error ts1 == t1");
 449     }
 450 
 451     /**
 452      * Validate equals returns false when a String object is passed to equals
 453      */
 454     @Test
 455     public void test34() {
 456         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 457         assertFalse(ts1.equals("1966-08-30 08:08:08"), "Error ts1 == a String");
 458     }
 459 
 460     /**
 461      * Validate getTime() returns the same value from 2 timeStamps created by
 462      */
 463     @Test
 464     public void test35() {
 465         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 466         Timestamp ts2 = Timestamp.valueOf("1966-08-30 08:08:08");
 467         assertTrue(ts2.getTime() == ts1.getTime(),
 468                 "ts1.getTime() != ts2.getTime()");
 469         assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
 470     }
 471 
 472     /**
 473      * Validate getTime() returns the same value from 2 timeStamps when
 474      * setTime() is used to specify the same value for both Timestamps
 475      */
 476     @Test
 477     public void test36() {
 478         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 479         Timestamp ts2 = Timestamp.valueOf("1961-08-30 00:00:00");
 480         ts2.setTime(ts1.getTime());
 481         assertTrue(ts2.getTime() == ts1.getTime(),
 482                 "ts1.getTime() != ts2.getTime()");
 483         assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
 484     }
 485 
 486     /**
 487      * Validate an IllegalArgumentException is thrown for an invalid nanos value
 488      */
 489     @Test(expectedExceptions = IllegalArgumentException.class)
 490     public void test38() throws Exception {
 491         Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
 492         ts1.setNanos(-1);
 493 
 494     }
 495 
 496     /**
 497      * Validate an IllegalArgumentException is thrown for an invalid nanos value
 498      */
 499     @Test(expectedExceptions = IllegalArgumentException.class)
 500     public void test39() throws Exception {
 501         int nanos = 999999999;
 502         Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
 503         ts1.setNanos(nanos + 1);
 504 
 505     }
 506 
 507     /**
 508      * Validate you can set nanos to 999999999
 509      */
 510     @Test
 511     public void test40() throws Exception {
 512         int nanos = 999999999;
 513         Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
 514         ts1.setNanos(nanos);
 515         assertTrue(ts1.getNanos() == nanos, "Error Invalid Nanos value");
 516 
 517     }
 518 
 519     /**
 520      * Validate you can set nanos to 0
 521      */
 522     @Test
 523     public void test41() throws Exception {
 524         int nanos = 0;
 525         Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
 526         ts1.setNanos(nanos);
 527         assertTrue(ts1.getNanos() == nanos, "Error Invalid Nanos value");
 528 
 529     }
 530 
 531     /**
 532      * Validate that a Timestamp made from a LocalDateTime are equal
 533      */
 534     @Test
 535     public void test42() throws Exception {
 536         Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
 537         LocalDateTime ldt = ts1.toLocalDateTime();
 538         Timestamp ts2 = Timestamp.valueOf(ldt);
 539         assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
 540     }
 541 
 542     /**
 543      * Validate that a Timestamp LocalDateTime value, made from a LocalDateTime
 544      * are equal
 545      */
 546     @Test
 547     public void test43() throws Exception {
 548         LocalDateTime ldt = LocalDateTime.now();
 549         Timestamp ts2 = Timestamp.valueOf(ldt);
 550         assertTrue(ldt.equals(ts2.toLocalDateTime()),
 551                 "Error LocalDateTime values are not equal");
 552     }
 553 
 554     /**
 555      * Validate an NPE occurs when a null LocalDateTime is passed to valueOF
 556      */
 557     @Test(expectedExceptions = NullPointerException.class)
 558     public void test44() throws Exception {
 559         LocalDateTime ldt = null;
 560         Timestamp.valueOf(ldt);
 561     }
 562 
 563     /**
 564      * Validate that a Timestamp made from a Instant are equal
 565      */
 566     @Test
 567     public void test45() throws Exception {
 568         Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
 569         Instant instant = ts1.toInstant();
 570         Timestamp ts2 = Timestamp.from(instant);
 571         assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
 572     }
 573 
 574     /**
 575      * Validate that a Timestamp made from a Instant are equal
 576      */
 577     @Test
 578     public void test46() throws Exception {
 579         Instant instant = Instant.now();
 580         Timestamp ts2 = Timestamp.from(instant);
 581         assertTrue(instant.equals(ts2.toInstant()),
 582                 "Error Instant values do not match");
 583     }
 584 
 585     /**
 586      * Validate an NPE occurs when a null instant is passed to from
 587      */
 588     @Test(expectedExceptions = NullPointerException.class)
 589     public void test47() throws Exception {
 590         Instant instant = null;
 591         Timestamp.from(instant);
 592     }
 593 
 594     // Added SQE tests
 595     /**
 596      * Create a Timestamp and a 2nd Timestamp that is 1 month earlier and
 597      * validate that it is not before or after the original Timestamp
 598      */
 599     @Test
 600     public void test48() {
 601         Calendar cal = Calendar.getInstance();
 602         Timestamp ts1 = new Timestamp(System.currentTimeMillis());
 603         cal.setTimeInMillis(ts1.getTime());
 604         cal.add(Calendar.MONTH, -1);
 605         cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
 606         Timestamp ts2 = new Timestamp(cal.getTimeInMillis());
 607         assertFalse(ts1.before(ts2) || ts2.after(ts1));
 608     }
 609 
 610     /**
 611      * Create two Timestamps and validate that compareTo returns 1 to indicate
 612      * the 1st Timestamp is greater than the 2nd Timestamp
 613      */
 614     @Test
 615     public void test49() {
 616         Calendar cal = Calendar.getInstance();
 617         Timestamp ts1 = new Timestamp(System.currentTimeMillis());
 618         cal.setTimeInMillis(ts1.getTime());
 619         cal.add(Calendar.MONTH, -1);
 620         cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
 621         Timestamp ts2 = new Timestamp(cal.getTimeInMillis());
 622         assertTrue(ts1.compareTo(ts2) == 1);
 623     }
 624 
 625     /**
 626      * Create two Timestamps and validate that the 1st Timestamp is not equal to
 627      * the 2nd Timestamp but equal to itself
 628      */
 629     @Test
 630     public void test50() {
 631         Calendar cal = Calendar.getInstance();
 632         Timestamp ts1 = new Timestamp(System.currentTimeMillis());
 633         cal.setTimeInMillis(ts1.getTime());
 634         cal.add(Calendar.MONTH, -1);
 635         cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
 636         Timestamp ts2 = new Timestamp(cal.getTimeInMillis());
 637         assertTrue(!ts1.equals(ts2) && ts1.equals(ts1));
 638     }
 639 














































































































 640 }


  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package test.sql;
  24 
  25 import java.sql.Date;
  26 import java.sql.Time;
  27 import java.sql.Timestamp;
  28 import java.time.Instant;
  29 import java.time.LocalDateTime;
  30 import java.util.Calendar;
  31 import static org.testng.Assert.*;
  32 import org.testng.annotations.DataProvider;



  33 import org.testng.annotations.Test;
  34 import util.BaseTest;
  35 
  36 public class TimestampTests extends BaseTest {
  37 
  38     /*





































  39      * Validate an IllegalArgumentException is thrown for an invalid Timestamp
  40      */
  41     @Test(dataProvider = "invalidTimestampValues",
  42             expectedExceptions = IllegalArgumentException.class)
  43     public void test(String ts) throws Exception {
  44         Timestamp.valueOf(ts);
  45     }
  46 
  47     /*
  48      * Validate that two Timestamp are equal when the leading 0 in seconds is
  49      * omitted
  50      */
  51     @Test
  52     public void test01() throws Exception {
  53         String testTS = "2009-01-01 10:50:00";
  54         String ExpectedTS = "2009-01-01 10:50:0";
  55         Timestamp ts = Timestamp.valueOf(testTS);
  56         Timestamp ts2 = Timestamp.valueOf(ExpectedTS);
  57         assertEquals(ts, ts2, "Error ts1 != ts2");
  58     }
  59 
  60     /*
  61      * Validate two Timestamps created from the same string are equal
  62      */
  63     @Test
  64     public void test02() throws Exception {
  65         String testTS = "2009-01-01 10:50:0";
  66         Timestamp ts = Timestamp.valueOf(testTS);
  67         Timestamp ts2 = Timestamp.valueOf(testTS);
  68         assertEquals(ts, ts2, "Error ts1 != ts2");
  69     }
  70 
  71     /*
  72      * Validate that two Timestamp values one with leading 0s for month and day
  73      * equals same string without the leading 0s.
  74      */
  75     @Test
  76     public void test03() throws Exception {
  77         String testTS = "2009-1-1 10:50:0";
  78         String ExpectedTS = "2009-01-01 10:50:0";
  79         Timestamp ts = Timestamp.valueOf(testTS);
  80         Timestamp ts2 = Timestamp.valueOf(ExpectedTS);
  81         assertEquals(ts, ts2, "Error ts1 != ts2");
  82     }
  83 
  84     /*
  85      * Validate that two Timestamp values one with leading 0s for day omitted
  86      * are equal
  87      */
  88     @Test
  89     public void test04() throws Exception {
  90         String testTS = "2009-01-1 10:50:0";
  91         String ExpectedTS = "2009-01-01 10:50:0";
  92         Timestamp ts = Timestamp.valueOf(testTS);
  93         Timestamp ts2 = Timestamp.valueOf(ExpectedTS);
  94         assertEquals(ts, ts2, "Error ts1 != ts2");
  95     }
  96 
  97     /*
  98      * Validate that two Timestamp values one with leading 0s for month omitted
  99      * and both with leading 0s for seconds omitted are equal
 100      */
 101     @Test
 102     public void test05() throws Exception {
 103         String testTS = "2009-1-01 10:50:0";
 104         String ExpectedTS = "2009-01-01 10:50:0";
 105         Timestamp ts = Timestamp.valueOf(testTS);
 106         Timestamp ts2 = Timestamp.valueOf(ExpectedTS);
 107         assertEquals(ts, ts2, "Error ts1 != ts2");
 108     }
 109 
 110     /*
 111      * Validate that two Timestamp values one with leading 0s for month omitted
 112      */
 113     @Test
 114     public void test06() throws Exception {
 115         String testTS = "2005-1-01 10:20:50.00";
 116         String ExpectedTS = "2005-01-01 10:20:50.00";
 117         Timestamp ts = Timestamp.valueOf(testTS);
 118         Timestamp ts2 = Timestamp.valueOf(ExpectedTS);
 119         assertEquals(ts, ts2, "Error ts1 != ts2");
 120     }
 121 
 122     /*
 123      * Validate that two Timestamp values one created using valueOf and another
 124      * via a constructor are equal
 125      */
 126     @Test
 127     public void test07() {
 128 
 129         Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.001");
 130         Timestamp ts2 = new Timestamp(96, 11, 13, 14, 15, 25, 1000000);
 131         assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
 132     }
 133 
 134     /*
 135      * Validate that two Timestamp values one created using valueOf and another
 136      * via a constructor are equal
 137      */
 138     @Test
 139     public void test08() {
 140         Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.001");
 141         Timestamp ts2 = new Timestamp(ts1.getTime());
 142         assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
 143     }
 144 
 145     /*
 146      * Validate that two Timestamp values one created using valueOf and another
 147      * via a constructor are equal
 148      */
 149     @Test
 150     public void test09() {
 151 
 152         Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.0");
 153         Timestamp ts2 = new Timestamp(96, 11, 13, 14, 15, 25, 0);
 154         assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
 155     }
 156 
 157     /*
 158      * Validate that a Timestamp cannot be equal to null
 159      */
 160     @Test
 161     public void test10() {
 162 
 163         Timestamp ts1 = Timestamp.valueOf("1961-08-30 14:15:25.745634");
 164         Timestamp ts2 = null;
 165         assertFalse(ts1.equals(ts2), "Error ts1 == null");
 166     }
 167 
 168     /*
 169      * Validate that a Timestamp is equal to another timestamp created with the
 170      * using the same value but not equal to a Timestamp which is one day later
 171      */
 172     @Test
 173     public void test11() {
 174 
 175         Timestamp ts1 = Timestamp.valueOf("1996-12-10 12:26:19.12");
 176         Timestamp ts2 = Timestamp.valueOf("1996-12-10 12:26:19.12");
 177         Timestamp ts3 = Timestamp.valueOf("1996-12-11 12:24:19.12");
 178         assertTrue(ts1.equals(ts2) && ts2.equals(ts1), "Error ts1 != ts2");
 179         assertFalse(ts1.equals(ts3) && ts3.equals(ts1), "Error ts1 == ts3");
 180 
 181     }
 182 
 183     /*
 184      * Validate that a Timestamp is equal to itself
 185      */
 186     @Test
 187     public void test12() {
 188         Timestamp ts1 = Timestamp.valueOf("1996-10-15 12:26:19.12");
 189         assertTrue(ts1.equals(ts1), "Error ts1 != ts1");
 190     }
 191 
 192     /*
 193      * Validate that two Timestamps are equal when one is created from the
 194      * toString() of the other
 195      */
 196     @Test(dataProvider = "validTimestampValues")
 197     public void test13(String ts, String expectedTS) {
 198         Timestamp ts1 = Timestamp.valueOf(ts);
 199         Timestamp ts2 = Timestamp.valueOf(ts1.toString());
 200         assertTrue(ts1.equals(ts2) && ts2.equals(ts1)
 201                 && ts1.toString().equals(expectedTS), "Error ts1 != ts2");
 202     }
 203 
 204     // Before Tests
 205     /*
 206      * Validate that Timestamp ts1 is before Timestamp ts2
 207      */
 208     @Test
 209     public void test14() {
 210         Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.745634");
 211         Timestamp ts2 = Timestamp.valueOf("1996-12-13 15:15:25.645634");
 212         assertTrue(ts1.before(ts2), "Error ts1 not before ts2");
 213     }
 214 
 215     /*
 216      * Validate that Timestamp ts1 is before Timestamp ts2
 217      */
 218     @Test
 219     public void test15() {
 220         Timestamp ts1 = Timestamp.valueOf("1961-08-30 14:15:25");
 221         Timestamp ts2 = Timestamp.valueOf("1999-12-13 15:15:25");
 222         assertTrue(ts1.before(ts2), "Error ts1 not before ts2");
 223     }
 224 
 225     /*
 226      * Validate that Timestamp ts1 is before Timestamp ts2
 227      */
 228     @Test
 229     public void test16() {
 230 
 231         Timestamp ts1 = Timestamp.valueOf("1999-12-13 14:15:25.745634");
 232         Timestamp ts2 = Timestamp.valueOf("1999-11-13 15:15:25.645634");
 233         assertFalse(ts1.before(ts2), "Error ts1 before ts2");
 234     }
 235 
 236     /*
 237      * Validate that a NullPointerException is thrown if a null is passed to
 238      * the before method
 239      */
 240     @Test(expectedExceptions = NullPointerException.class)
 241     public void test17() throws Exception {
 242         Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.745634");
 243         ts1.before(null);
 244     }
 245 
 246     /*
 247      * Validate a Timestamp cannot be before itself
 248      */
 249     @Test
 250     public void test18() {
 251         Timestamp ts1 = Timestamp.valueOf("1999-11-10 12:26:19.3456543");
 252         assertFalse(ts1.before(ts1), "Error ts1 before ts1!");
 253     }
 254 
 255     /*
 256      * Create 3 Timestamps and make sure the 1st is before the other two
 257      * Timestamps which are each greater than the one before it
 258      */
 259     @Test
 260     public void test19() {
 261 
 262         Timestamp ts1 = new Timestamp(1234560000);
 263         Timestamp ts2 = new Timestamp(1234567000);
 264         Timestamp ts3 = new Timestamp(1234569000);
 265         assertTrue(ts1.before(ts2) && ts2.before(ts3) && ts1.before(ts3));
 266     }
 267 
 268     /*
 269      * Validate that Timestamp ts1 is not after Timestamp ts2
 270      */
 271     @Test
 272     public void test20() {
 273         Timestamp ts1 = Timestamp.valueOf("1999-12-13 14:15:25.745634");
 274         Timestamp ts2 = Timestamp.valueOf("1999-12-13 15:15:25.645634");
 275         assertFalse(ts1.after(ts2), "Error ts1 is after ts2");
 276 
 277     }
 278 
 279     /*
 280      * Validate that Timestamp ts1 is after Timestamp ts2
 281      */
 282     @Test
 283     public void test21() {
 284         Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.745634");
 285         Timestamp ts2 = Timestamp.valueOf("1996-11-13 15:15:25.645634");
 286         assertTrue(ts1.after(ts2), "Error ts1 not after ts2");
 287     }
 288 
 289     /*
 290      * Validate that a NullPointerException is thrown if a null is passed to the
 291      * after method
 292      */
 293     @Test(expectedExceptions = NullPointerException.class)
 294     public void test22() throws Exception {
 295         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 296         ts1.after(null);
 297     }
 298 
 299     /*
 300      * Validate that a Timestamp cannot be after itself
 301      */
 302     @Test
 303     public void test23() {
 304         Timestamp ts1 = Timestamp.valueOf("1999-11-10 12:26:19.3456543");
 305         assertFalse(ts1.after(ts1), "Error ts1 is after itself");
 306     }
 307 
 308     /*
 309      * Validate that a Timestamp after() works correctly with Timestamp created
 310      * using milliseconds
 311      */
 312     @Test
 313     public void test24() {
 314 
 315         Timestamp ts1 = new Timestamp(1234568000);
 316         Timestamp ts2 = new Timestamp(1234565000);
 317         Timestamp ts3 = new Timestamp(1234562000);
 318         assertTrue(ts1.after(ts2) && ts2.after(ts3) && ts1.after(ts3));
 319     }
 320 
 321     /*
 322      * Validate compareTo returns 0 for Timestamps that are the same
 323      */
 324     @Test
 325     public void test25() {
 326         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 327         Timestamp ts2 = new Timestamp(ts1.getTime());
 328         assertTrue(ts1.compareTo(ts2) == 0, "Error ts1 != ts2");
 329     }
 330 
 331     /*
 332      * Validate compareTo returns -1 for when the 1st Timestamp is earlier than
 333      * the 2nd Timestamp
 334      */
 335     @Test
 336     public void test26() {
 337         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 338         Timestamp ts2 = new Timestamp(ts1.getTime() + 1000);
 339         assertTrue(ts1.compareTo(ts2) == -1, "Error ts1 not before ts2");
 340         assertTrue(ts2.compareTo(ts1) == 1, "Error ts1 is not before ts2");
 341     }
 342 
 343     /*
 344      * Validate compareTo returns 1 for when the 1st Timestamp is later than the
 345      * 2nd Timestamp
 346      */
 347     @Test
 348     public void test27() {
 349         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 350         Timestamp ts2 = new Timestamp(ts1.getTime() - 1000);
 351         assertTrue(ts1.compareTo(ts2) == 1, "Error ts1 not after ts2");
 352         assertTrue(ts2.compareTo(ts1) == -1, "Error ts1 not after ts2");
 353     }
 354 
 355     /*
 356      * Validate compareTo returns 0 for Timestamps that are the same
 357      */
 358     @Test
 359     public void test28() {
 360         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 361         java.util.Date ts2 = new java.util.Date(ts1.getTime());
 362         assertTrue(ts1.compareTo(ts2) == 0, "Error ts1 != ts2");
 363     }
 364 
 365     /*
 366      * Validate compareTo returns 0 for Timestamps that are the same
 367      */
 368     @Test
 369     public void test29() {
 370         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 371         java.util.Date d = new java.util.Date(ts1.getTime());
 372         assertFalse(ts1.equals(d), "Error ts1 == d");
 373     }
 374 
 375     /*
 376      * Validate compareTo returns 0 for Timestamps that are the same
 377      */
 378     @Test
 379     public void test30() {
 380         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 381         java.util.Date d = new Timestamp(ts1.getTime());
 382         assertTrue(ts1.equals(d), "Error ts1 != d");
 383     }
 384 
 385     /*
 386      * Validate equals returns false when a Date object is passed to equals
 387      */
 388     @Test
 389     public void test31() {
 390         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 391         Date d = new Date(ts1.getTime());
 392         assertFalse(ts1.equals(d), "Error ts1 != d");
 393     }
 394 
 395     /*
 396      * Validate equals returns false when a Date object is passed to equals
 397      */
 398     @Test
 399     public void test32() {
 400         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 401         java.util.Date d = new Date(ts1.getTime());
 402         assertFalse(ts1.equals(d), "Error ts1 != d");
 403     }
 404 
 405     /*
 406      * Validate equals returns false when a Time object is passed to equals
 407      */
 408     @Test
 409     public void test33() {
 410         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 411         Time t1 = new Time(ts1.getTime());
 412         assertFalse(ts1.equals(t1), "Error ts1 == t1");
 413     }
 414 
 415     /*
 416      * Validate equals returns false when a String object is passed to equals
 417      */
 418     @Test
 419     public void test34() {
 420         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 421         assertFalse(ts1.equals("1966-08-30 08:08:08"), "Error ts1 == a String");
 422     }
 423 
 424     /*
 425      * Validate getTime() returns the same value from 2 timeStamps created by
 426      */
 427     @Test
 428     public void test35() {
 429         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 430         Timestamp ts2 = Timestamp.valueOf("1966-08-30 08:08:08");
 431         assertTrue(ts2.getTime() == ts1.getTime(),
 432                 "ts1.getTime() != ts2.getTime()");
 433         assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
 434     }
 435 
 436     /*
 437      * Validate getTime() returns the same value from 2 timeStamps when
 438      * setTime() is used to specify the same value for both Timestamps
 439      */
 440     @Test
 441     public void test36() {
 442         Timestamp ts1 = Timestamp.valueOf("1966-08-30 08:08:08");
 443         Timestamp ts2 = Timestamp.valueOf("1961-08-30 00:00:00");
 444         ts2.setTime(ts1.getTime());
 445         assertTrue(ts2.getTime() == ts1.getTime(),
 446                 "ts1.getTime() != ts2.getTime()");
 447         assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
 448     }
 449 
 450     /*
 451      * Validate an IllegalArgumentException is thrown for an invalid nanos value
 452      */
 453     @Test(expectedExceptions = IllegalArgumentException.class)
 454     public void test38() throws Exception {
 455         Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
 456         ts1.setNanos(-1);
 457 
 458     }
 459 
 460     /*
 461      * Validate an IllegalArgumentException is thrown for an invalid nanos value
 462      */
 463     @Test(expectedExceptions = IllegalArgumentException.class)
 464     public void test39() throws Exception {
 465         int nanos = 999999999;
 466         Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
 467         ts1.setNanos(nanos + 1);

 468     }
 469 
 470     /*
 471      * Validate you can set nanos to 999999999
 472      */
 473     @Test
 474     public void test40() throws Exception {
 475         int nanos = 999999999;
 476         Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
 477         ts1.setNanos(nanos);
 478         assertTrue(ts1.getNanos() == nanos, "Error Invalid Nanos value");

 479     }
 480 
 481     /*
 482      * Validate you can set nanos to 0
 483      */
 484     @Test
 485     public void test41() throws Exception {
 486         int nanos = 0;
 487         Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
 488         ts1.setNanos(nanos);
 489         assertTrue(ts1.getNanos() == nanos, "Error Invalid Nanos value");

 490     }
 491 
 492     /*
 493      * Validate that a Timestamp made from a LocalDateTime are equal
 494      */
 495     @Test
 496     public void test42() throws Exception {
 497         Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
 498         LocalDateTime ldt = ts1.toLocalDateTime();
 499         Timestamp ts2 = Timestamp.valueOf(ldt);
 500         assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
 501     }
 502 
 503     /*
 504      * Validate that a Timestamp LocalDateTime value, made from a LocalDateTime
 505      * are equal
 506      */
 507     @Test
 508     public void test43() throws Exception {
 509         LocalDateTime ldt = LocalDateTime.now();
 510         Timestamp ts2 = Timestamp.valueOf(ldt);
 511         assertTrue(ldt.equals(ts2.toLocalDateTime()),
 512                 "Error LocalDateTime values are not equal");
 513     }
 514 
 515     /*
 516      * Validate an NPE occurs when a null LocalDateTime is passed to valueOF
 517      */
 518     @Test(expectedExceptions = NullPointerException.class)
 519     public void test44() throws Exception {
 520         LocalDateTime ldt = null;
 521         Timestamp.valueOf(ldt);
 522     }
 523 
 524     /*
 525      * Validate that a Timestamp made from a Instant are equal
 526      */
 527     @Test
 528     public void test45() throws Exception {
 529         Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
 530         Instant instant = ts1.toInstant();
 531         Timestamp ts2 = Timestamp.from(instant);
 532         assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
 533     }
 534 
 535     /*
 536      * Validate that a Timestamp made from a Instant are equal
 537      */
 538     @Test
 539     public void test46() throws Exception {
 540         Instant instant = Instant.now();
 541         Timestamp ts2 = Timestamp.from(instant);
 542         assertTrue(instant.equals(ts2.toInstant()),
 543                 "Error Instant values do not match");
 544     }
 545 
 546     /*
 547      * Validate an NPE occurs when a null instant is passed to from
 548      */
 549     @Test(expectedExceptions = NullPointerException.class)
 550     public void test47() throws Exception {
 551         Instant instant = null;
 552         Timestamp.from(instant);
 553     }
 554 
 555     // Added SQE tests
 556     /*
 557      * Create a Timestamp and a 2nd Timestamp that is 1 month earlier and
 558      * validate that it is not before or after the original Timestamp
 559      */
 560     @Test
 561     public void test48() {
 562         Calendar cal = Calendar.getInstance();
 563         Timestamp ts1 = new Timestamp(System.currentTimeMillis());
 564         cal.setTimeInMillis(ts1.getTime());
 565         cal.add(Calendar.MONTH, -1);
 566         cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
 567         Timestamp ts2 = new Timestamp(cal.getTimeInMillis());
 568         assertFalse(ts1.before(ts2) || ts2.after(ts1));
 569     }
 570 
 571     /*
 572      * Create two Timestamps and validate that compareTo returns 1 to indicate
 573      * the 1st Timestamp is greater than the 2nd Timestamp
 574      */
 575     @Test
 576     public void test49() {
 577         Calendar cal = Calendar.getInstance();
 578         Timestamp ts1 = new Timestamp(System.currentTimeMillis());
 579         cal.setTimeInMillis(ts1.getTime());
 580         cal.add(Calendar.MONTH, -1);
 581         cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
 582         Timestamp ts2 = new Timestamp(cal.getTimeInMillis());
 583         assertTrue(ts1.compareTo(ts2) == 1);
 584     }
 585 
 586     /*
 587      * Create two Timestamps and validate that the 1st Timestamp is not equal to
 588      * the 2nd Timestamp but equal to itself
 589      */
 590     @Test
 591     public void test50() {
 592         Calendar cal = Calendar.getInstance();
 593         Timestamp ts1 = new Timestamp(System.currentTimeMillis());
 594         cal.setTimeInMillis(ts1.getTime());
 595         cal.add(Calendar.MONTH, -1);
 596         cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
 597         Timestamp ts2 = new Timestamp(cal.getTimeInMillis());
 598         assertTrue(!ts1.equals(ts2) && ts1.equals(ts1));
 599     }
 600 
 601     /*
 602      * Validate that two Timestamps are equal when one is created from the
 603      * toString() of the other
 604      */
 605     @Test(dataProvider = "validateNanos")
 606     public void test51(String ts, int nanos) {
 607         Timestamp ts1 = Timestamp.valueOf(ts);
 608         Timestamp ts2 = Timestamp.valueOf(ts1.toString());
 609         assertTrue(ts1.getNanos() == nanos && ts1.equals(ts2),
 610                 "Error with Nanos");
 611     }
 612     
 613     /*
 614      * DataProvider used to provide Timestamps which are not valid and are used
 615      * to validate that an IllegalArgumentException will be thrown from the
 616      * valueOf method
 617      */
 618     @DataProvider(name = "invalidTimestampValues")
 619     private Object[][] invalidTimestampValues() {
 620         return new Object[][]{
 621             {"2009-11-01-01 10:50:01"},
 622             {"aaaa-11-01-01 10:50"},
 623             {"aaaa-11-01 10:50"},
 624             {"1961--30 00:00:00"},
 625             {"--30 00:00:00"},
 626             {"-- 00:00:00"},
 627             {"1961-1- 00:00:00"},
 628             {"2009-11-01"},
 629             {"10:50:01"},
 630             {"1961-a-30 00:00:00"},
 631             {"1961-01-bb 00:00:00"},
 632             {"1961-08-30 00:00:00."},
 633             {"1961-08-30 :00:00"},
 634             {"1961-08-30 00::00"},
 635             {"1961-08-30 00:00:"},
 636             {"1961-08-30 ::"},
 637             {"1961-08-30 0a:00:00"},
 638             {"1961-08-30 00:bb:00"},
 639             {"1961-08-30 00:01:cc"},
 640             {"1961-08-30 00:00:00.01a"},
 641             {"1961-08-30 00:00:00.a"},
 642             {"1996-12-10 12:26:19.1234567890"},
 643             {null}
 644         };
 645     }
 646 
 647     /*
 648      * DataProvider used to provide Timestamps which are  valid and are used
 649      * to validate that an IllegalArgumentException will not be thrown from the
 650      * valueOf method and the corect value from toString() is returned
 651      */
 652     @DataProvider(name = "validTimestampValues")
 653     private Object[][] validTimestampValues() {
 654         return new Object[][]{
 655             {"1961-08-30 00:00:00", "1961-08-30 00:00:00.0"},
 656             {"1961-08-30 11:22:33", "1961-08-30 11:22:33.0"},
 657             {"1961-8-30 00:00:00", "1961-08-30 00:00:00.0"},
 658             {"1966-08-1 00:00:00", "1966-08-01 00:00:00.0"},
 659             {"1996-12-10 12:26:19.1", "1996-12-10 12:26:19.1"},
 660             {"1996-12-10 12:26:19.12", "1996-12-10 12:26:19.12"},
 661             {"1996-12-10 12:26:19.123", "1996-12-10 12:26:19.123"},
 662             {"1996-12-10 12:26:19.1234", "1996-12-10 12:26:19.1234"},
 663             {"1996-12-10 12:26:19.12345", "1996-12-10 12:26:19.12345"},
 664             {"1996-12-10 12:26:19.123456", "1996-12-10 12:26:19.123456"},
 665             {"1996-12-10 12:26:19.1234567", "1996-12-10 12:26:19.1234567"},
 666             {"1996-12-10 12:26:19.12345678", "1996-12-10 12:26:19.12345678"},
 667             {"1996-12-10 12:26:19.123456789", "1996-12-10 12:26:19.123456789"},
 668             {"1996-12-10 12:26:19.000000001", "1996-12-10 12:26:19.000000001"},
 669             {"1996-12-10 12:26:19.000000012", "1996-12-10 12:26:19.000000012"},
 670             {"1996-12-10 12:26:19.000000123", "1996-12-10 12:26:19.000000123"},
 671             {"1996-12-10 12:26:19.000001234", "1996-12-10 12:26:19.000001234"},
 672             {"1996-12-10 12:26:19.000012345", "1996-12-10 12:26:19.000012345"},
 673             {"1996-12-10 12:26:19.000123456", "1996-12-10 12:26:19.000123456"},
 674             {"1996-12-10 12:26:19.001234567", "1996-12-10 12:26:19.001234567"},
 675             {"1996-12-10 12:26:19.12345678", "1996-12-10 12:26:19.12345678"},
 676             {"1996-12-10 12:26:19.0", "1996-12-10 12:26:19.0"},
 677             {"1996-12-10 12:26:19.01230", "1996-12-10 12:26:19.0123"}
 678         };
 679     }
 680 
 681     /*
 682      * DataProvider used to provide Timestamp and Nanos values in order to
 683      * validate that the correct Nanos value is generated from the specified
 684      * Timestamp
 685      */
 686     @DataProvider(name = "validateNanos")
 687     private Object[][] validateNanos() {
 688         return new Object[][]{
 689             {"1961-08-30 00:00:00", 0},
 690             {"1996-12-10 12:26:19.1", 100000000},
 691             {"1996-12-10 12:26:19.12", 120000000},
 692             {"1996-12-10 12:26:19.123", 123000000},
 693             {"1996-12-10 12:26:19.1234", 123400000},
 694             {"1996-12-10 12:26:19.12345", 123450000},
 695             {"1996-12-10 12:26:19.123456", 123456000},
 696             {"1996-12-10 12:26:19.1234567", 123456700},
 697             {"1996-12-10 12:26:19.12345678", 123456780},
 698             {"1996-12-10 12:26:19.123456789", 123456789},
 699             {"1996-12-10 12:26:19.000000001", 1},
 700             {"1996-12-10 12:26:19.000000012", 12},
 701             {"1996-12-10 12:26:19.000000123", 123},
 702             {"1996-12-10 12:26:19.000001234", 1234},
 703             {"1996-12-10 12:26:19.000012345", 12345},
 704             {"1996-12-10 12:26:19.000123456", 123456},
 705             {"1996-12-10 12:26:19.001234567", 1234567},
 706             {"1996-12-10 12:26:19.012345678", 12345678},
 707             {"1996-12-10 12:26:19.0", 0},
 708             {"1996-12-10 12:26:19.01230", 12300000}
 709         };
 710     }
 711 }