test/java/sql/test/sql/DateTests.java

Print this page




   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.time.Instant;
  27 import java.time.LocalDate;
  28 import static org.testng.Assert.*;
  29 import org.testng.annotations.AfterClass;
  30 import org.testng.annotations.AfterMethod;
  31 import org.testng.annotations.BeforeClass;
  32 import org.testng.annotations.BeforeMethod;
  33 import org.testng.annotations.Test;

  34 
  35 public class DateTests {
  36 
  37     public DateTests() {
  38     }
  39 
  40     @BeforeClass
  41     public static void setUpClass() throws Exception {
  42     }
  43 
  44     @AfterClass
  45     public static void tearDownClass() throws Exception {
  46     }
  47 
  48     @BeforeMethod
  49     public void setUpMethod() throws Exception {
  50     }
  51 
  52     @AfterMethod
  53     public void tearDownMethod() throws Exception {
  54     }
  55 
  56     /**
  57      * Validate an IllegalArgumentException is thrown for an invalid Date string
  58      */
  59     @Test(expectedExceptions = IllegalArgumentException.class)
  60     public void testInvalid_year() throws Exception {
  61         String expResult = "20009-11-01";
  62         Date.valueOf(expResult);
  63     }
  64 
  65     /**
  66      * Validate an IllegalArgumentException is thrown for an invalid Date string
  67      */
  68     @Test(expectedExceptions = IllegalArgumentException.class)
  69     public void testInvalid_year2() throws Exception {
  70         String expResult = "09-11-01";
  71         Date.valueOf(expResult);
  72     }
  73 
  74     /**
  75      * Validate an IllegalArgumentException is thrown for an invalid Date string
  76      */
  77     @Test(expectedExceptions = IllegalArgumentException.class)
  78     public void testInvalid_year3() throws Exception {
  79         String expResult = "-11-01";
  80         Date.valueOf(expResult);
  81     }
  82 
  83     /**
  84      * Validate an IllegalArgumentException is thrown for an invalid Date string
  85      */
  86     @Test(expectedExceptions = IllegalArgumentException.class)
  87     public void testInvalid_month() throws Exception {
  88         String expResult = "2009-111-01";
  89         Date.valueOf(expResult);
  90     }
  91 
  92     /**
  93      * Validate an IllegalArgumentException is thrown for an invalid Date string
  94      */
  95     @Test(expectedExceptions = IllegalArgumentException.class)
  96     public void testInvalid_month3() throws Exception {
  97         String expResult = "2009--01";
  98         Date.valueOf(expResult);
  99     }
 100 
 101     /**
 102      * Validate an IllegalArgumentException is thrown for an invalid Date string
 103      */
 104     @Test(expectedExceptions = IllegalArgumentException.class)
 105     public void testInvalid_month4() throws Exception {
 106         String expResult = "2009-13-01";
 107         Date.valueOf(expResult);
 108     }
 109 
 110     /**
 111      * Validate an IllegalArgumentException is thrown for an invalid Date string
 112      */
 113     @Test(expectedExceptions = IllegalArgumentException.class)
 114     public void testInvalid_day() throws Exception {
 115         String expResult = "2009-11-011";
 116         Date.valueOf(expResult);
 117     }
 118 
 119     /**
 120      * Validate an IllegalArgumentException is thrown for an invalid Date string
 121      */
 122     @Test(expectedExceptions = IllegalArgumentException.class)
 123     public void testInvalid_day3() throws Exception {
 124         String expResult = "2009-11-";
 125         Date.valueOf(expResult);
 126     }
 127 
 128     /**
 129      * Validate an IllegalArgumentException is thrown for an invalid Date string
 130      */
 131     @Test(expectedExceptions = IllegalArgumentException.class)
 132     public void testInvalid_day4() throws Exception {
 133         String expResult = "2009-11-00";
 134         Date.valueOf(expResult);
 135     }
 136 
 137     /**
 138      * Validate an IllegalArgumentException is thrown for an invalid Date string
 139      */
 140     @Test(expectedExceptions = IllegalArgumentException.class)
 141     public void testInvalid_day5() throws Exception {
 142         String expResult = "2009-11-33";
 143         Date.valueOf(expResult);
 144     }
 145 
 146     /**
 147      * Validate an IllegalArgumentException is thrown for an invalid Date string
 148      */
 149     @Test(expectedExceptions = IllegalArgumentException.class)
 150     public void testInvalid_valueOf() throws Exception {
 151         String expResult = "--";
 152         Date.valueOf(expResult);
 153     }
 154 
 155     /**
 156      * Validate an IllegalArgumentException is thrown for an invalid Date string
 157      */
 158     @Test(expectedExceptions = IllegalArgumentException.class)
 159     public void testInvalid_valueOf2() throws Exception {
 160         String expResult = "";
 161         Date.valueOf(expResult);
 162     }
 163 
 164     /**
 165      * Validate an IllegalArgumentException is thrown for an invalid Date string
 166      */
 167     @Test(expectedExceptions = IllegalArgumentException.class)
 168     public void testInvalid_valueOf3() throws Exception {
 169         String expResult = null;
 170         Date.valueOf(expResult);
 171     }
 172 
 173     /**
 174      * Validate an IllegalArgumentException is thrown for an invalid Date string
 175      */
 176     @Test(expectedExceptions = IllegalArgumentException.class)
 177     public void testInvalid_valueOf4() throws Exception {
 178         String expResult = "-";
 179         Date.valueOf(expResult);
 180     }
 181 
 182     /**
 183      * Validate an IllegalArgumentException is thrown for an invalid Date string
 184      */
 185     @Test(expectedExceptions = IllegalArgumentException.class)
 186     public void testInvalid_valueOf5() throws Exception {
 187         String expResult = "2009";
 188         Date.valueOf(expResult);
 189     }
 190 
 191     /**
 192      * Validate an IllegalArgumentException is thrown for an invalid Date string
 193      */
 194     @Test(expectedExceptions = IllegalArgumentException.class)
 195     public void testInvalid_valueOf6() throws Exception {
 196         String expResult = "2009-01";
 197         Date.valueOf(expResult);
 198     }
 199 
 200     /**
 201      * Validate an IllegalArgumentException is thrown for an invalid Date string
 202      */
 203     @Test(expectedExceptions = IllegalArgumentException.class)
 204     public void testInvalid_valueOf7() throws Exception {
 205         String expResult = "---";
 206         Date.valueOf(expResult);
 207     }
 208 
 209     /**
 210      * Validate an IllegalArgumentException is thrown for an invalid Date string
 211      */
 212     @Test(expectedExceptions = IllegalArgumentException.class)
 213     public void testInvalid_valueOf8() throws Exception {
 214         String expResult = "2009-13--1";
 215         Date.valueOf(expResult);
 216     }
 217 
 218     /**
 219      * Validate an IllegalArgumentException is thrown for an invalid Date string
 220      */
 221     @Test(expectedExceptions = IllegalArgumentException.class)
 222     public void testInvalid_valueOf10() {
 223         String expResult = "1900-1-0";
 224         Date.valueOf(expResult);
 225     }
 226 
 227     /**
 228      * Test that a date created from a date string is equal to the value
 229      * returned from toString()
 230      */
 231     @Test
 232     public void test_valueOf() {
 233         String expResult = "2009-08-30";
 234         Date d = Date.valueOf(expResult);
 235         assertEquals(expResult, d.toString());

 236     }
 237 
 238     /**
 239      * Test that two dates, one with lead 0s omitted for month are equal
 240      */
 241     @Test
 242     public void testValid_month_single_digit() {
 243         String testDate = "2009-1-01";
 244         String expResult = "2009-01-01";
 245         Date d = Date.valueOf(testDate);
 246         Date d2 = Date.valueOf(expResult);
 247         assertEquals(d, d2);
 248     }
 249 
 250     /**
 251      * Test that two dates, one with lead 0s omitted for day are equal
 252      */
 253     @Test
 254     public void testValid_day_single_digit() {
 255         String testDate = "2009-11-1";
 256         String expResult = "2009-11-01";
 257         Date d = Date.valueOf(testDate);
 258         Date d2 = Date.valueOf(expResult);
 259         assertEquals(d, d2);
 260     }
 261 
 262     /**
 263      * Test that two dates, one with lead 0s omitted for month and day are equal
 264      */
 265     @Test
 266     public void testValid_month_day_single_digit() {
 267         String testDate = "2009-1-1";
 268         String expResult = "2009-01-01";
 269         Date d = Date.valueOf(testDate);
 270         Date d2 = Date.valueOf(expResult);
 271         assertEquals(d, d2);
 272     }
 273 
 274     /**
 275      * Validate that a Date.after() returns false when same date is compared
 276      */
 277     @Test
 278     public void test1() {
 279         Date d = Date.valueOf("1961-08-30");
 280         assertFalse(d.after(d), "Error d.after(d) = true");
 281     }
 282 
 283     /**
 284      * Validate that a Date.after() returns true when later date is compared to
 285      * earlier date
 286      */
 287     @Test
 288     public void test2() {
 289         Date d = Date.valueOf("1961-08-30");
 290         Date d2 = new Date(System.currentTimeMillis());
 291         assertTrue(d2.after(d), "Error d2.after(d) = false");
 292     }
 293 
 294     /**
 295      * Validate that a Date.after() returns false when earlier date is compared
 296      * to later date
 297      */
 298     @Test
 299     public void test3() {
 300         Date d = Date.valueOf("1961-08-30");
 301         Date d2 = new Date(d.getTime());
 302         assertFalse(d.after(d2), "Error d.after(d2) = true");
 303     }
 304 
 305     /**
 306      * Validate that a Date.after() returns false when date compared to another
 307      * date created from the original date
 308      */
 309     @Test
 310     public void test4() {
 311         Date d = Date.valueOf("1961-08-30");
 312         Date d2 = new Date(d.getTime());
 313         assertFalse(d.after(d2), "Error d.after(d2) = true");
 314         assertFalse(d2.after(d), "Error d2.after(d) = true");
 315     }
 316 
 317     /**
 318      * Validate that a Date.before() returns false when same date is compared
 319      */
 320     @Test
 321     public void test5() {
 322         Date d = Date.valueOf("1961-08-30");
 323         assertFalse(d.before(d), "Error d.before(d) = true");
 324     }
 325 
 326     /**
 327      * Validate that a Date.before() returns true when earlier date is compared
 328      * to later date
 329      */
 330     @Test
 331     public void test6() {
 332         Date d = Date.valueOf("1961-08-30");
 333         Date d2 = new Date(System.currentTimeMillis());
 334         assertTrue(d.before(d2), "Error d.before(d2) = false");
 335     }
 336 
 337     /**
 338      * Validate that a Date.before() returns false when later date is compared
 339      * to earlier date
 340      */
 341     @Test
 342     public void test7() {
 343         Date d = Date.valueOf("1961-08-30");
 344         Date d2 = new Date(d.getTime());
 345         assertFalse(d2.before(d), "Error d2.before(d) = true");
 346     }
 347 
 348     /**
 349      * Validate that a Date.before() returns false when date compared to another
 350      * date created from the original date
 351      */
 352     @Test
 353     public void test8() {
 354         Date d = Date.valueOf("1961-08-30");
 355         Date d2 = new Date(d.getTime());
 356         assertFalse(d.before(d2), "Error d.before(d2) = true");
 357         assertFalse(d2.before(d), "Error d2.before(d) = true");
 358     }
 359 
 360     /**
 361      * Validate that a Date.compareTo returns 0 when both Date objects are the
 362      * same
 363      */
 364     @Test
 365     public void test9() {
 366         Date d = Date.valueOf("1961-08-30");
 367         assertTrue(d.compareTo(d) == 0, "Error d.compareTo(d) !=0");
 368     }
 369 
 370     /**
 371      * Validate that a Date.compareTo returns 0 when both Date objects represent
 372      * the same date
 373      */
 374     @Test
 375     public void test10() {
 376         Date d = Date.valueOf("1961-08-30");
 377         Date d2 = new Date(d.getTime());
 378         assertTrue(d.compareTo(d2) == 0, "Error d.compareTo(d2) !=0");
 379     }
 380 
 381     /**
 382      * Validate that a Date.compareTo returns -1 when comparing a date to a
 383      * later date
 384      */
 385     @Test
 386     public void test11() {
 387         Date d = Date.valueOf("1961-08-30");
 388         Date d2 = new Date(System.currentTimeMillis());
 389         assertTrue(d.compareTo(d2) == -1, "Error d.compareTo(d2) != -1");
 390     }
 391 
 392     /**
 393      * Validate that a Date.compareTo returns 1 when comparing a date to an
 394      * earlier date
 395      */
 396     @Test
 397     public void test12() {
 398         Date d = Date.valueOf("1961-08-30");
 399         Date d2 = new Date(System.currentTimeMillis());
 400         assertTrue(d2.compareTo(d) == 1, "Error d.compareTo(d2) != 1");
 401     }
 402 
 403     /**
 404      * Validate that a Date made from a LocalDate are equal
 405      */
 406     @Test
 407     public void test13() {
 408         Date d = Date.valueOf("1961-08-30");
 409         LocalDate ldt = d.toLocalDate();
 410         Date d2 = Date.valueOf(ldt);
 411         assertTrue(d.equals(d2), "Error d != d2");
 412     }
 413 
 414     /**
 415      * Validate that a Date LocalDate value, made from a LocalDate are equal
 416      */
 417     @Test
 418     public void test14() {
 419         LocalDate ldt = LocalDate.now();
 420         Date d = Date.valueOf(ldt);
 421         assertTrue(ldt.equals(d.toLocalDate()),
 422                 "Error LocalDate values are not equal");
 423     }
 424 
 425     /**
 426      * Validate an NPE occurs when a null LocalDate is passed to valueOf
 427      */
 428     @Test(expectedExceptions = NullPointerException.class)
 429     public void test15() throws Exception {
 430         LocalDate ld = null;
 431         Date.valueOf(ld);
 432     }
 433 
 434     /**
 435      * Validate an UnsupportedOperationException occurs when toInstant() is
 436      * called
 437      */
 438     @Test(expectedExceptions = UnsupportedOperationException.class)
 439     public void test16() throws Exception {
 440         Date d = Date.valueOf("1961-08-30");
 441         Instant instant = d.toInstant();
 442     }
 443 
 444     /**
 445      * Validate that two Date objects are equal when one is created from the
 446      * toString() of the other
 447      */
 448     @Test
 449     public void test17() {
 450         Date d = Date.valueOf("1961-08-30");
 451         Date d2 = Date.valueOf(d.toString());
 452         assertTrue(d.equals(d2) && d2.equals(d), "Error d != d2");
 453     }
 454 
 455     /**
 456      * Validate that two Date values one created using valueOf and another via a
 457      * constructor are equal
 458      */
 459     @Test
 460     public void test18() {
 461 
 462         Date d = Date.valueOf("1961-08-30");
 463         Date d2 = new Date(61, 7, 30);
 464         assertTrue(d.equals(d2), "Error d != d2");
 465     }
 466 
 467     /**
 468      * Validate that two Date values one created using getTime() of the other
 469      * are equal
 470      */
 471     @Test
 472     public void test19() {
 473 
 474         Date d = Date.valueOf("1961-08-30");
 475         Date d2 = new Date(d.getTime());
 476         assertTrue(d.equals(d2), "Error d != d2");
 477     }
 478 
 479     /**
 480      * Validate that a Date value is equal to itself
 481      */
 482     @Test
 483     public void test20() {
 484 
 485         Date d = Date.valueOf("1961-08-30");
 486         assertTrue(d.equals(d), "Error d != d");
 487     }
 488 
 489     /**
 490      * Validate an IllegalArgumentException is thrown for calling getHours
 491      */
 492     @Test(expectedExceptions = IllegalArgumentException.class)
 493     public void test21() throws Exception {
 494         Date d = Date.valueOf("1961-08-30");
 495         d.getHours();
 496     }
 497 
 498     /**
 499      * Validate an IllegalArgumentException is thrown for calling getMinutes
 500      */
 501     @Test(expectedExceptions = IllegalArgumentException.class)
 502     public void test22() throws Exception {
 503         Date d = Date.valueOf("1961-08-30");
 504         d.getMinutes();
 505     }
 506 
 507     /**
 508      * Validate an IllegalArgumentException is thrown for calling getSeconds
 509      */
 510     @Test(expectedExceptions = IllegalArgumentException.class)
 511     public void test23() throws Exception {
 512         Date d = Date.valueOf("1961-08-30");
 513         d.getSeconds();
 514     }
 515 
 516     /**
 517      * Validate an IllegalArgumentException is thrown for calling setHours
 518      */
 519     @Test(expectedExceptions = IllegalArgumentException.class)
 520     public void test24() throws Exception {
 521         Date d = Date.valueOf("1961-08-30");
 522         d.setHours(8);
 523     }
 524 
 525     /**
 526      * Validate an IllegalArgumentException is thrown for calling setMinutes
 527      */
 528     @Test(expectedExceptions = IllegalArgumentException.class)
 529     public void test25() throws Exception {
 530         Date d = Date.valueOf("1961-08-30");
 531         d.setMinutes(0);
 532     }
 533 
 534     /**
 535      * Validate an IllegalArgumentException is thrown for calling setSeconds
 536      */
 537     @Test(expectedExceptions = IllegalArgumentException.class)
 538     public void test26() throws Exception {
 539         Date d = Date.valueOf("1961-08-30");
 540         d.setSeconds(0);
 541     }

















































 542 }


   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.time.Instant;
  27 import java.time.LocalDate;
  28 import static org.testng.Assert.*;
  29 import org.testng.annotations.DataProvider;



  30 import org.testng.annotations.Test;
  31 import util.BaseTest;
  32 
  33 public class DateTests extends BaseTest {
  34 
  35     /*




























  36      * Validate an IllegalArgumentException is thrown for an invalid Date string
  37      */
  38     @Test(dataProvider = "invalidDateValues",
  39             expectedExceptions = IllegalArgumentException.class)
  40     public void test(String d) throws Exception {
  41         Date.valueOf(d);









  42     }
  43 
  44     /*
















































































































































  45      * Test that a date created from a date string is equal to the value
  46      * returned from toString()
  47      */
  48     @Test(dataProvider = "validDateValues")
  49     public void test00(String d, String expectedD) {
  50         Date d1 = Date.valueOf(d);
  51         Date d2 = Date.valueOf(expectedD);
  52         assertTrue(d1.equals(d2) && d2.equals(d1)
  53                 && d1.toString().equals(expectedD), "Error d1 != d2");
  54     }
  55 
  56     /*




































  57      * Validate that a Date.after() returns false when same date is compared
  58      */
  59     @Test
  60     public void test01() {
  61         Date d = Date.valueOf("1961-08-30");
  62         assertFalse(d.after(d), "Error d.after(d) = true");
  63     }
  64 
  65     /*
  66      * Validate that a Date.after() returns true when later date is compared to
  67      * earlier date
  68      */
  69     @Test
  70     public void test2() {
  71         Date d = Date.valueOf("1961-08-30");
  72         Date d2 = new Date(System.currentTimeMillis());
  73         assertTrue(d2.after(d), "Error d2.after(d) = false");
  74     }
  75 
  76     /*
  77      * Validate that a Date.after() returns false when earlier date is compared
  78      * to later date
  79      */
  80     @Test
  81     public void test3() {
  82         Date d = Date.valueOf("1961-08-30");
  83         Date d2 = new Date(d.getTime());
  84         assertFalse(d.after(d2), "Error d.after(d2) = true");
  85     }
  86 
  87     /*
  88      * Validate that a Date.after() returns false when date compared to another
  89      * date created from the original date
  90      */
  91     @Test
  92     public void test4() {
  93         Date d = Date.valueOf("1961-08-30");
  94         Date d2 = new Date(d.getTime());
  95         assertFalse(d.after(d2), "Error d.after(d2) = true");
  96         assertFalse(d2.after(d), "Error d2.after(d) = true");
  97     }
  98 
  99     /*
 100      * Validate that a Date.before() returns false when same date is compared
 101      */
 102     @Test
 103     public void test5() {
 104         Date d = Date.valueOf("1961-08-30");
 105         assertFalse(d.before(d), "Error d.before(d) = true");
 106     }
 107 
 108     /*
 109      * Validate that a Date.before() returns true when earlier date is compared
 110      * to later date
 111      */
 112     @Test
 113     public void test6() {
 114         Date d = Date.valueOf("1961-08-30");
 115         Date d2 = new Date(System.currentTimeMillis());
 116         assertTrue(d.before(d2), "Error d.before(d2) = false");
 117     }
 118 
 119     /*
 120      * Validate that a Date.before() returns false when later date is compared
 121      * to earlier date
 122      */
 123     @Test
 124     public void test7() {
 125         Date d = Date.valueOf("1961-08-30");
 126         Date d2 = new Date(d.getTime());
 127         assertFalse(d2.before(d), "Error d2.before(d) = true");
 128     }
 129 
 130     /*
 131      * Validate that a Date.before() returns false when date compared to another
 132      * date created from the original date
 133      */
 134     @Test
 135     public void test8() {
 136         Date d = Date.valueOf("1961-08-30");
 137         Date d2 = new Date(d.getTime());
 138         assertFalse(d.before(d2), "Error d.before(d2) = true");
 139         assertFalse(d2.before(d), "Error d2.before(d) = true");
 140     }
 141 
 142     /*
 143      * Validate that a Date.compareTo returns 0 when both Date objects are the
 144      * same
 145      */
 146     @Test
 147     public void test9() {
 148         Date d = Date.valueOf("1961-08-30");
 149         assertTrue(d.compareTo(d) == 0, "Error d.compareTo(d) !=0");
 150     }
 151 
 152     /*
 153      * Validate that a Date.compareTo returns 0 when both Date objects represent
 154      * the same date
 155      */
 156     @Test
 157     public void test10() {
 158         Date d = Date.valueOf("1961-08-30");
 159         Date d2 = new Date(d.getTime());
 160         assertTrue(d.compareTo(d2) == 0, "Error d.compareTo(d2) !=0");
 161     }
 162 
 163     /*
 164      * Validate that a Date.compareTo returns -1 when comparing a date to a
 165      * later date
 166      */
 167     @Test
 168     public void test11() {
 169         Date d = Date.valueOf("1961-08-30");
 170         Date d2 = new Date(System.currentTimeMillis());
 171         assertTrue(d.compareTo(d2) == -1, "Error d.compareTo(d2) != -1");
 172     }
 173 
 174     /*
 175      * Validate that a Date.compareTo returns 1 when comparing a date to an
 176      * earlier date
 177      */
 178     @Test
 179     public void test12() {
 180         Date d = Date.valueOf("1961-08-30");
 181         Date d2 = new Date(System.currentTimeMillis());
 182         assertTrue(d2.compareTo(d) == 1, "Error d.compareTo(d2) != 1");
 183     }
 184 
 185     /*
 186      * Validate that a Date made from a LocalDate are equal
 187      */
 188     @Test
 189     public void test13() {
 190         Date d = Date.valueOf("1961-08-30");
 191         LocalDate ldt = d.toLocalDate();
 192         Date d2 = Date.valueOf(ldt);
 193         assertTrue(d.equals(d2), "Error d != d2");
 194     }
 195 
 196     /*
 197      * Validate that a Date LocalDate value, made from a LocalDate are equal
 198      */
 199     @Test
 200     public void test14() {
 201         LocalDate ldt = LocalDate.now();
 202         Date d = Date.valueOf(ldt);
 203         assertTrue(ldt.equals(d.toLocalDate()),
 204                 "Error LocalDate values are not equal");
 205     }
 206 
 207     /*
 208      * Validate an NPE occurs when a null LocalDate is passed to valueOf
 209      */
 210     @Test(expectedExceptions = NullPointerException.class)
 211     public void test15() throws Exception {
 212         LocalDate ld = null;
 213         Date.valueOf(ld);
 214     }
 215 
 216     /*
 217      * Validate an UnsupportedOperationException occurs when toInstant() is
 218      * called
 219      */
 220     @Test(expectedExceptions = UnsupportedOperationException.class)
 221     public void test16() throws Exception {
 222         Date d = Date.valueOf("1961-08-30");
 223         Instant instant = d.toInstant();
 224     }
 225 
 226     /*
 227      * Validate that two Date objects are equal when one is created from the
 228      * toString() of the other
 229      */
 230     @Test
 231     public void test17() {
 232         Date d = Date.valueOf("1961-08-30");
 233         Date d2 = Date.valueOf(d.toString());
 234         assertTrue(d.equals(d2) && d2.equals(d), "Error d != d2");
 235     }
 236 
 237     /*
 238      * Validate that two Date values one created using valueOf and another via a
 239      * constructor are equal
 240      */
 241     @Test
 242     public void test18() {
 243 
 244         Date d = Date.valueOf("1961-08-30");
 245         Date d2 = new Date(61, 7, 30);
 246         assertTrue(d.equals(d2), "Error d != d2");
 247     }
 248 
 249     /*
 250      * Validate that two Date values one created using getTime() of the other
 251      * are equal
 252      */
 253     @Test
 254     public void test19() {
 255 
 256         Date d = Date.valueOf("1961-08-30");
 257         Date d2 = new Date(d.getTime());
 258         assertTrue(d.equals(d2), "Error d != d2");
 259     }
 260 
 261     /*
 262      * Validate that a Date value is equal to itself
 263      */
 264     @Test
 265     public void test20() {
 266 
 267         Date d = Date.valueOf("1961-08-30");
 268         assertTrue(d.equals(d), "Error d != d");
 269     }
 270 
 271     /*
 272      * Validate an IllegalArgumentException is thrown for calling getHours
 273      */
 274     @Test(expectedExceptions = IllegalArgumentException.class)
 275     public void test21() throws Exception {
 276         Date d = Date.valueOf("1961-08-30");
 277         d.getHours();
 278     }
 279 
 280     /*
 281      * Validate an IllegalArgumentException is thrown for calling getMinutes
 282      */
 283     @Test(expectedExceptions = IllegalArgumentException.class)
 284     public void test22() throws Exception {
 285         Date d = Date.valueOf("1961-08-30");
 286         d.getMinutes();
 287     }
 288 
 289     /*
 290      * Validate an IllegalArgumentException is thrown for calling getSeconds
 291      */
 292     @Test(expectedExceptions = IllegalArgumentException.class)
 293     public void test23() throws Exception {
 294         Date d = Date.valueOf("1961-08-30");
 295         d.getSeconds();
 296     }
 297 
 298     /*
 299      * Validate an IllegalArgumentException is thrown for calling setHours
 300      */
 301     @Test(expectedExceptions = IllegalArgumentException.class)
 302     public void test24() throws Exception {
 303         Date d = Date.valueOf("1961-08-30");
 304         d.setHours(8);
 305     }
 306 
 307     /*
 308      * Validate an IllegalArgumentException is thrown for calling setMinutes
 309      */
 310     @Test(expectedExceptions = IllegalArgumentException.class)
 311     public void test25() throws Exception {
 312         Date d = Date.valueOf("1961-08-30");
 313         d.setMinutes(0);
 314     }
 315 
 316     /*
 317      * Validate an IllegalArgumentException is thrown for calling setSeconds
 318      */
 319     @Test(expectedExceptions = IllegalArgumentException.class)
 320     public void test26() throws Exception {
 321         Date d = Date.valueOf("1961-08-30");
 322         d.setSeconds(0);
 323     }
 324 
 325     /*
 326      * DataProvider used to provide Date which are not valid and are used
 327      * to validate that an IllegalArgumentException will be thrown from the
 328      * valueOf method
 329      */
 330     @DataProvider(name = "invalidDateValues")
 331     private Object[][] invalidDateValues() {
 332         return new Object[][]{
 333             {"20009-11-01"},
 334             {"09-11-01"},
 335             {"-11-01"},
 336             {"2009-111-01"},
 337             {"2009--01"},
 338             {"2009-13-01"},
 339             {"2009-11-011"},
 340             {"2009-11-"},
 341             {"2009-11-00"},
 342             {"2009-11-33"},
 343             {"--"},
 344             {""},
 345             {null},
 346             {"-"},
 347             {"2009"},
 348             {"2009-01"},
 349             {"---"},
 350             {"2009-13--1"},
 351             {"1900-1-0"},
 352             {"2009-01-01 10:50:01"},
 353             {"1996-12-10 12:26:19.1"},
 354             {"10:50:01"}
 355         };
 356     }
 357 
 358     /*
 359      * DataProvider used to provide Dates which are  valid and are used
 360      * to validate that an IllegalArgumentException will not be thrown from the
 361      * valueOf method and the corect value from toString() is returned
 362      */
 363     @DataProvider(name = "validDateValues")
 364     private Object[][] validDateValues() {
 365         return new Object[][]{
 366             {"2009-08-30", "2009-08-30"},
 367             {"2009-01-8", "2009-01-08"},
 368             {"2009-1-01", "2009-01-01"},
 369             {"2009-1-1", "2009-01-01"}
 370 
 371         };
 372     }
 373 }