1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  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 }