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

Print this page
rev 10524 : 8055055: Improve numeric parsing in java.sql

*** 67,76 **** --- 67,122 ---- /** * Validate an IllegalArgumentException is thrown for an invalid Timestamp */ @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalid_timestamp2() throws Exception { + String testTS = "2009-11- 10:50:10"; + Timestamp.valueOf(testTS); + } + + /** + * Validate an IllegalArgumentException is thrown for an invalid Timestamp + */ + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalid_timestamp3() throws Exception { + String testTS = "2009-11-01 10:50"; + Timestamp.valueOf(testTS); + } + + /** + * Validate an IllegalArgumentException is thrown for an invalid Timestamp + */ + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalid_timestamp4() throws Exception { + String testTS = "2009-11-01 :50:01"; + Timestamp.valueOf(testTS); + } + + /** + * Validate an IllegalArgumentException is thrown for an invalid Timestamp + */ + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalid_timestamp5() throws Exception { + String testTS = "-11-01 10:50:10"; + Timestamp.valueOf(testTS); + } + + /** + * Validate an IllegalArgumentException is thrown for an invalid Timestamp + * (too high nanosecond precision) + */ + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalid_timestamp6() throws Exception { + String testTS = "2009-11-01 10:50:01.0000000001"; + Timestamp.valueOf(testTS); + } + + /** + * Validate an IllegalArgumentException is thrown for an invalid Timestamp + */ + @Test(expectedExceptions = IllegalArgumentException.class) public void testInvalid_year2() throws Exception { String testTS = "aaaa-11-01-01 10:50"; Timestamp.valueOf(testTS); }
*** 635,640 **** --- 681,707 ---- cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); Timestamp ts2 = new Timestamp(cal.getTimeInMillis()); assertTrue(!ts1.equals(ts2) && ts1.equals(ts1)); } + /** + * Validate that the nanoseconds are correctly interpreted and truncated + */ + @Test + public void test51() throws Exception { + { + int nanos = 471100000; + String testTS = "2009-01-01 10:50:00.4711"; + Timestamp ts = Timestamp.valueOf(testTS); + assertEquals(ts.getNanos(), nanos, "Error ts.getNanos() != nanos"); + assertEquals(ts.toString(), testTS, "Error ts.toString() != testTS"); + } + { + int nanos = 4711; + String testTS = "2009-01-01 10:50:00.000004711"; + Timestamp ts = Timestamp.valueOf(testTS); + assertEquals(ts.getNanos(), nanos, "Error ts.getNanos() != nanos"); + assertEquals(ts.toString(), testTS, "Error ts.toString() != testTS"); + } + } + }