mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-17 11:23:19 +00:00
8057826: Minor clean-up to the java.sql Date/Time/Timestamp tests
Reviewed-by: redestad, joehw
This commit is contained in:
parent
6f337fabf4
commit
9f2d9ff4a6
@ -26,261 +26,43 @@ import java.sql.Date;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import static org.testng.Assert.*;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import util.BaseTest;
|
||||
|
||||
public class DateTests {
|
||||
public class DateTests extends BaseTest {
|
||||
|
||||
public DateTests() {
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() throws Exception {
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
public void setUpMethod() throws Exception {
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
public void tearDownMethod() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_year() throws Exception {
|
||||
String expResult = "20009-11-01";
|
||||
Date.valueOf(expResult);
|
||||
@Test(dataProvider = "invalidDateValues",
|
||||
expectedExceptions = IllegalArgumentException.class)
|
||||
public void test(String d) throws Exception {
|
||||
Date.valueOf(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_year2() throws Exception {
|
||||
String expResult = "09-11-01";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_year3() throws Exception {
|
||||
String expResult = "-11-01";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_month() throws Exception {
|
||||
String expResult = "2009-111-01";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_month3() throws Exception {
|
||||
String expResult = "2009--01";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_month4() throws Exception {
|
||||
String expResult = "2009-13-01";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_day() throws Exception {
|
||||
String expResult = "2009-11-011";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_day3() throws Exception {
|
||||
String expResult = "2009-11-";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_day4() throws Exception {
|
||||
String expResult = "2009-11-00";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_day5() throws Exception {
|
||||
String expResult = "2009-11-33";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_valueOf() throws Exception {
|
||||
String expResult = "--";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_valueOf2() throws Exception {
|
||||
String expResult = "";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_valueOf3() throws Exception {
|
||||
String expResult = null;
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_valueOf4() throws Exception {
|
||||
String expResult = "-";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_valueOf5() throws Exception {
|
||||
String expResult = "2009";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_valueOf6() throws Exception {
|
||||
String expResult = "2009-01";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_valueOf7() throws Exception {
|
||||
String expResult = "---";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_valueOf8() throws Exception {
|
||||
String expResult = "2009-13--1";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Date string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_valueOf10() {
|
||||
String expResult = "1900-1-0";
|
||||
Date.valueOf(expResult);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Test that a date created from a date string is equal to the value
|
||||
* returned from toString()
|
||||
*/
|
||||
@Test
|
||||
public void test_valueOf() {
|
||||
String expResult = "2009-08-30";
|
||||
Date d = Date.valueOf(expResult);
|
||||
assertEquals(expResult, d.toString());
|
||||
@Test(dataProvider = "validDateValues")
|
||||
public void test00(String d, String expectedD) {
|
||||
Date d1 = Date.valueOf(d);
|
||||
Date d2 = Date.valueOf(expectedD);
|
||||
assertTrue(d1.equals(d2) && d2.equals(d1)
|
||||
&& d1.toString().equals(expectedD), "Error d1 != d2");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that two dates, one with lead 0s omitted for month are equal
|
||||
*/
|
||||
@Test
|
||||
public void testValid_month_single_digit() {
|
||||
String testDate = "2009-1-01";
|
||||
String expResult = "2009-01-01";
|
||||
Date d = Date.valueOf(testDate);
|
||||
Date d2 = Date.valueOf(expResult);
|
||||
assertEquals(d, d2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that two dates, one with lead 0s omitted for day are equal
|
||||
*/
|
||||
@Test
|
||||
public void testValid_day_single_digit() {
|
||||
String testDate = "2009-11-1";
|
||||
String expResult = "2009-11-01";
|
||||
Date d = Date.valueOf(testDate);
|
||||
Date d2 = Date.valueOf(expResult);
|
||||
assertEquals(d, d2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that two dates, one with lead 0s omitted for month and day are equal
|
||||
*/
|
||||
@Test
|
||||
public void testValid_month_day_single_digit() {
|
||||
String testDate = "2009-1-1";
|
||||
String expResult = "2009-01-01";
|
||||
Date d = Date.valueOf(testDate);
|
||||
Date d2 = Date.valueOf(expResult);
|
||||
assertEquals(d, d2);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Date.after() returns false when same date is compared
|
||||
*/
|
||||
@Test
|
||||
public void test1() {
|
||||
public void test01() {
|
||||
Date d = Date.valueOf("1961-08-30");
|
||||
assertFalse(d.after(d), "Error d.after(d) = true");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Date.after() returns true when later date is compared to
|
||||
* earlier date
|
||||
*/
|
||||
@ -291,7 +73,7 @@ public class DateTests {
|
||||
assertTrue(d2.after(d), "Error d2.after(d) = false");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Date.after() returns false when earlier date is compared
|
||||
* to later date
|
||||
*/
|
||||
@ -302,7 +84,7 @@ public class DateTests {
|
||||
assertFalse(d.after(d2), "Error d.after(d2) = true");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Date.after() returns false when date compared to another
|
||||
* date created from the original date
|
||||
*/
|
||||
@ -314,7 +96,7 @@ public class DateTests {
|
||||
assertFalse(d2.after(d), "Error d2.after(d) = true");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Date.before() returns false when same date is compared
|
||||
*/
|
||||
@Test
|
||||
@ -323,7 +105,7 @@ public class DateTests {
|
||||
assertFalse(d.before(d), "Error d.before(d) = true");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Date.before() returns true when earlier date is compared
|
||||
* to later date
|
||||
*/
|
||||
@ -334,7 +116,7 @@ public class DateTests {
|
||||
assertTrue(d.before(d2), "Error d.before(d2) = false");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Date.before() returns false when later date is compared
|
||||
* to earlier date
|
||||
*/
|
||||
@ -345,7 +127,7 @@ public class DateTests {
|
||||
assertFalse(d2.before(d), "Error d2.before(d) = true");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Date.before() returns false when date compared to another
|
||||
* date created from the original date
|
||||
*/
|
||||
@ -357,7 +139,7 @@ public class DateTests {
|
||||
assertFalse(d2.before(d), "Error d2.before(d) = true");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Date.compareTo returns 0 when both Date objects are the
|
||||
* same
|
||||
*/
|
||||
@ -367,7 +149,7 @@ public class DateTests {
|
||||
assertTrue(d.compareTo(d) == 0, "Error d.compareTo(d) !=0");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Date.compareTo returns 0 when both Date objects represent
|
||||
* the same date
|
||||
*/
|
||||
@ -378,7 +160,7 @@ public class DateTests {
|
||||
assertTrue(d.compareTo(d2) == 0, "Error d.compareTo(d2) !=0");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Date.compareTo returns -1 when comparing a date to a
|
||||
* later date
|
||||
*/
|
||||
@ -389,7 +171,7 @@ public class DateTests {
|
||||
assertTrue(d.compareTo(d2) == -1, "Error d.compareTo(d2) != -1");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Date.compareTo returns 1 when comparing a date to an
|
||||
* earlier date
|
||||
*/
|
||||
@ -400,7 +182,7 @@ public class DateTests {
|
||||
assertTrue(d2.compareTo(d) == 1, "Error d.compareTo(d2) != 1");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Date made from a LocalDate are equal
|
||||
*/
|
||||
@Test
|
||||
@ -411,7 +193,7 @@ public class DateTests {
|
||||
assertTrue(d.equals(d2), "Error d != d2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Date LocalDate value, made from a LocalDate are equal
|
||||
*/
|
||||
@Test
|
||||
@ -422,7 +204,7 @@ public class DateTests {
|
||||
"Error LocalDate values are not equal");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an NPE occurs when a null LocalDate is passed to valueOf
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@ -431,7 +213,7 @@ public class DateTests {
|
||||
Date.valueOf(ld);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an UnsupportedOperationException occurs when toInstant() is
|
||||
* called
|
||||
*/
|
||||
@ -441,7 +223,7 @@ public class DateTests {
|
||||
Instant instant = d.toInstant();
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that two Date objects are equal when one is created from the
|
||||
* toString() of the other
|
||||
*/
|
||||
@ -452,7 +234,7 @@ public class DateTests {
|
||||
assertTrue(d.equals(d2) && d2.equals(d), "Error d != d2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that two Date values one created using valueOf and another via a
|
||||
* constructor are equal
|
||||
*/
|
||||
@ -464,7 +246,7 @@ public class DateTests {
|
||||
assertTrue(d.equals(d2), "Error d != d2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that two Date values one created using getTime() of the other
|
||||
* are equal
|
||||
*/
|
||||
@ -476,7 +258,7 @@ public class DateTests {
|
||||
assertTrue(d.equals(d2), "Error d != d2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Date value is equal to itself
|
||||
*/
|
||||
@Test
|
||||
@ -486,7 +268,7 @@ public class DateTests {
|
||||
assertTrue(d.equals(d), "Error d != d");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for calling getHours
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
@ -495,7 +277,7 @@ public class DateTests {
|
||||
d.getHours();
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for calling getMinutes
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
@ -504,7 +286,7 @@ public class DateTests {
|
||||
d.getMinutes();
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for calling getSeconds
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
@ -513,7 +295,7 @@ public class DateTests {
|
||||
d.getSeconds();
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for calling setHours
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
@ -522,7 +304,7 @@ public class DateTests {
|
||||
d.setHours(8);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for calling setMinutes
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
@ -531,7 +313,7 @@ public class DateTests {
|
||||
d.setMinutes(0);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for calling setSeconds
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
@ -539,4 +321,53 @@ public class DateTests {
|
||||
Date d = Date.valueOf("1961-08-30");
|
||||
d.setSeconds(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* DataProvider used to provide Date which are not valid and are used
|
||||
* to validate that an IllegalArgumentException will be thrown from the
|
||||
* valueOf method
|
||||
*/
|
||||
@DataProvider(name = "invalidDateValues")
|
||||
private Object[][] invalidDateValues() {
|
||||
return new Object[][]{
|
||||
{"20009-11-01"},
|
||||
{"09-11-01"},
|
||||
{"-11-01"},
|
||||
{"2009-111-01"},
|
||||
{"2009--01"},
|
||||
{"2009-13-01"},
|
||||
{"2009-11-011"},
|
||||
{"2009-11-"},
|
||||
{"2009-11-00"},
|
||||
{"2009-11-33"},
|
||||
{"--"},
|
||||
{""},
|
||||
{null},
|
||||
{"-"},
|
||||
{"2009"},
|
||||
{"2009-01"},
|
||||
{"---"},
|
||||
{"2009-13--1"},
|
||||
{"1900-1-0"},
|
||||
{"2009-01-01 10:50:01"},
|
||||
{"1996-12-10 12:26:19.1"},
|
||||
{"10:50:01"}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* DataProvider used to provide Dates which are valid and are used
|
||||
* to validate that an IllegalArgumentException will not be thrown from the
|
||||
* valueOf method and the corect value from toString() is returned
|
||||
*/
|
||||
@DataProvider(name = "validDateValues")
|
||||
private Object[][] validDateValues() {
|
||||
return new Object[][]{
|
||||
{"2009-08-30", "2009-08-30"},
|
||||
{"2009-01-8", "2009-01-08"},
|
||||
{"2009-1-01", "2009-01-01"},
|
||||
{"2009-1-1", "2009-01-01"}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,56 +25,35 @@ package test.sql;
|
||||
import java.sql.Time;
|
||||
import java.time.LocalTime;
|
||||
import static org.testng.Assert.*;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import util.BaseTest;
|
||||
|
||||
public class TimeTests {
|
||||
public class TimeTests extends BaseTest {
|
||||
|
||||
public TimeTests() {
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() throws Exception {
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
public void setUpMethod() throws Exception {
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
public void tearDownMethod() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for calling getYear
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void test1() {
|
||||
public void test01() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
t.getYear();
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for calling getMonth
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void test2() {
|
||||
public void test02() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
t.getMonth();
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for calling getDay
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void test3() {
|
||||
public void test03() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
t.getDay();
|
||||
}
|
||||
@ -83,62 +62,62 @@ public class TimeTests {
|
||||
* Validate an IllegalArgumentException is thrown for calling getDate
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void test4() {
|
||||
public void test04() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
t.getDate();
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for calling setYear
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void test5() {
|
||||
public void test05() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
t.setYear(8);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for calling setMonth
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void test6() {
|
||||
public void test06() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
t.setMonth(8);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for calling setDate
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void test7() {
|
||||
public void test07() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
t.setDate(30);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for calling getDate
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void test8() {
|
||||
public void test08() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
t.getDate();
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Time made from a toLocalTime() LocalTime are equal
|
||||
*/
|
||||
@Test
|
||||
public void test13() {
|
||||
public void test09() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
Time t2 = Time.valueOf(t.toLocalTime());
|
||||
assertTrue(t.equals(t2), "Error t != t2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Time LocalTime value, made from a LocalTime are equal
|
||||
*/
|
||||
@Test
|
||||
public void test14() {
|
||||
public void test10() {
|
||||
LocalTime lt = LocalTime.of(8, 30, 59);
|
||||
Time t = Time.valueOf(lt);
|
||||
System.out.println("lt=" + lt + ",t=" + t.toLocalTime());
|
||||
@ -146,231 +125,224 @@ public class TimeTests {
|
||||
"Error LocalTime values are not equal");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an NPE occurs when a null LocalDate is passed to valueOf
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void test15() throws Exception {
|
||||
public void test11() throws Exception {
|
||||
LocalTime ld = null;
|
||||
Time.valueOf(ld);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an UnsupportedOperationException occurs when toInstant() is
|
||||
* called
|
||||
*/
|
||||
@Test(expectedExceptions = UnsupportedOperationException.class)
|
||||
public void test16() throws Exception {
|
||||
public void test12() throws Exception {
|
||||
Time t = new Time(System.currentTimeMillis());
|
||||
t.toInstant();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that a Time made from valueOf(String) returns the same String
|
||||
* from Time.toString();
|
||||
*/
|
||||
@Test
|
||||
public void test17() {
|
||||
String time = "08:30:59";
|
||||
Time t = Time.valueOf(time);
|
||||
assertTrue(time.equals(t.toString()), "Error t != t2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that two Time objects are equal when one is created from the
|
||||
* toString() of the other
|
||||
* toString() of the other and that the correct value is returned from
|
||||
* toString()
|
||||
*/
|
||||
@Test
|
||||
public void test18() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
Time t2 = Time.valueOf(t.toString());
|
||||
assertTrue(t.equals(t2) && t2.equals(t), "Error t != t2");
|
||||
@Test(dataProvider = "validTimeValues")
|
||||
public void test13(String time, String expected) {
|
||||
Time t1 = Time.valueOf(time);
|
||||
Time t2 = Time.valueOf(t1.toString());
|
||||
assertTrue(t1.equals(t2) && t2.equals(t1)
|
||||
&& t1.toString().equals(expected), "Error t1 != t2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that two Time values one created using valueOf and another via a
|
||||
* constructor are equal
|
||||
*/
|
||||
@Test
|
||||
public void test19() {
|
||||
public void test14() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
Time t2 = new Time(8, 30, 59);
|
||||
assertTrue(t.equals(t2) && t2.equals(t), "Error t != t2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that two Time values one created using valueOf and another via a
|
||||
* constructor are equal
|
||||
*/
|
||||
@Test
|
||||
public void test20() {
|
||||
public void test15() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
Time t2 = new Time(t.getTime());
|
||||
assertTrue(t.equals(t2) && t2.equals(t), "Error t != t2");
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for calling valueOf with a
|
||||
* null String
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void test21() {
|
||||
String time = null;
|
||||
Time t = Time.valueOf(time);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Time string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void test22() throws Exception {
|
||||
Time.valueOf("1961-08-30");
|
||||
@Test(dataProvider = "invalidTimeValues",
|
||||
expectedExceptions = IllegalArgumentException.class)
|
||||
public void test16(String time) throws Exception {
|
||||
Time.valueOf(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Time string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void test23() throws Exception {
|
||||
Time.valueOf("8:");
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Time string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void test24() throws Exception {
|
||||
Time.valueOf("a:b:c");
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Time string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void test25() throws Exception {
|
||||
Time.valueOf("08:10");
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Time string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void test26() throws Exception {
|
||||
Time.valueOf("08:10:10:10");
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Time string
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void test27() throws Exception {
|
||||
Time.valueOf("08:10:Batman");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that Time.after() returns false when same date is compared
|
||||
*/
|
||||
@Test
|
||||
public void test28() {
|
||||
public void test17() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
assertFalse(t.after(t), "Error t.after(t) = true");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that Time.after() returns true when later date is compared to
|
||||
* earlier date
|
||||
*/
|
||||
@Test
|
||||
public void test29() {
|
||||
public void test18() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
Time t2 = new Time(System.currentTimeMillis());
|
||||
assertTrue(t2.after(t), "Error t2.after(t) = false");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that Time.after() returns false when earlier date is compared to
|
||||
* itself
|
||||
*/
|
||||
@Test
|
||||
public void test30() {
|
||||
public void test19() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
Time t2 = new Time(t.getTime());
|
||||
assertFalse(t.after(t2), "Error t.after(t2) = true");
|
||||
assertFalse(t2.after(t), "Error t2.after(t) = true");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that Time.before() returns false when same date is compared
|
||||
*/
|
||||
@Test
|
||||
public void test31() {
|
||||
public void test20() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
assertFalse(t.before(t), "Error t.before(t) = true");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that Time.before() returns true when earlier date is compared to
|
||||
* later date
|
||||
*/
|
||||
@Test
|
||||
public void test32() {
|
||||
public void test21() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
Time t2 = new Time(System.currentTimeMillis());
|
||||
assertTrue(t.before(t2), "Error t.before(t2) = false");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that Time.before() returns false when earlier date is compared
|
||||
* to itself
|
||||
*/
|
||||
@Test
|
||||
public void test33() {
|
||||
public void test22() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
Time t2 = new Time(t.getTime());
|
||||
assertFalse(t.before(t2), "Error t.after(t2) = true");
|
||||
assertFalse(t2.before(t), "Error t2.after(t) = true");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that Time.compareTo returns 0 when both Date objects are the
|
||||
* same
|
||||
*/
|
||||
@Test
|
||||
public void test34() {
|
||||
public void test23() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
assertTrue(t.compareTo(t) == 0, "Error t.compareTo(t) !=0");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate thatTime.compareTo returns 0 when both Time objects are the same
|
||||
*/
|
||||
@Test
|
||||
public void test35() {
|
||||
public void test24() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
Time t2 = new Time(t.getTime());
|
||||
assertTrue(t.compareTo(t2) == 0, "Error t.compareTo(t2) !=0");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that Time.compareTo returns 1 when comparing a later Time to an
|
||||
* earlier Time
|
||||
*/
|
||||
@Test
|
||||
public void test36() {
|
||||
public void test25() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
Time t2 = new Time(t.getTime() + 1);
|
||||
assertTrue(t2.compareTo(t) == 1, "Error t2.compareTo(t) !=1");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate thatTime.compareTo returns 1 when comparing a later Time to an
|
||||
* earlier Time
|
||||
*/
|
||||
@Test
|
||||
public void test37() {
|
||||
public void test26() {
|
||||
Time t = Time.valueOf("08:30:59");
|
||||
Time t2 = new Time(t.getTime() + 1);
|
||||
assertTrue(t.compareTo(t2) == -1, "Error t.compareTo(t2) != -1");
|
||||
}
|
||||
|
||||
/*
|
||||
* DataProvider used to provide Time values which are not valid and are used
|
||||
* to validate that an IllegalArgumentException will be thrown from the
|
||||
* valueOf method
|
||||
*/
|
||||
@DataProvider(name = "invalidTimeValues")
|
||||
private Object[][] invalidTimeValues() {
|
||||
return new Object[][]{
|
||||
{"2009-11-01 10:50:01"},
|
||||
{"1961-08-30 10:50:01.1"},
|
||||
{"1961-08-30"},
|
||||
{"00:00:00."},
|
||||
{"10:50:0.1"},
|
||||
{":00:00"},
|
||||
{"00::00"},
|
||||
{"00:00:"},
|
||||
{"::"},
|
||||
{" : : "},
|
||||
{"0a:00:00"},
|
||||
{"00:bb:00"},
|
||||
{"00:01:cc"},
|
||||
{"08:10:Batman"},
|
||||
{"08:10:10:10"},
|
||||
{"08:10"},
|
||||
{"a:b:c"},
|
||||
{null},
|
||||
{"8:"}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* DataProvider used to provide Time values which are valid and are used
|
||||
* to validate that an IllegalArgumentException will not be thrown from the
|
||||
* valueOf method. It also contains the expected return value from
|
||||
* toString()
|
||||
*/
|
||||
@DataProvider(name = "validTimeValues")
|
||||
private Object[][] validTimeValues() {
|
||||
return new Object[][]{
|
||||
{"10:50:01", "10:50:01"},
|
||||
{"01:1:1", "01:01:01"},
|
||||
{"01:01:1", "01:01:01"},
|
||||
{"1:01:1", "01:01:01"},
|
||||
{"2:02:02", "02:02:02"},
|
||||
{"2:02:2", "02:02:02"},
|
||||
{"10:50:1", "10:50:01"},
|
||||
{"00:00:00", "00:00:00"},
|
||||
{"08:30:59", "08:30:59"},
|
||||
{"9:0:1", "09:00:01"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,66 +29,27 @@ import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Calendar;
|
||||
import static org.testng.Assert.*;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import util.BaseTest;
|
||||
|
||||
public class TimestampTests {
|
||||
public class TimestampTests extends BaseTest {
|
||||
|
||||
public TimestampTests() {
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() throws Exception {
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
public void setUpMethod() throws Exception {
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
public void tearDownMethod() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Timestamp
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_timestamp() throws Exception {
|
||||
String testTS = "2009-11-01-01 10:50";
|
||||
Timestamp.valueOf(testTS);
|
||||
@Test(dataProvider = "invalidTimestampValues",
|
||||
expectedExceptions = IllegalArgumentException.class)
|
||||
public void test(String ts) throws Exception {
|
||||
Timestamp.valueOf(ts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate an IllegalArgumentException is thrown for an invalid Timestamp
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testInvalid_year3() throws Exception {
|
||||
String testTS = "aaaa-11-01 10:50";
|
||||
Timestamp.valueOf(testTS);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that two Timestamp are equal when the leading 0 in seconds is
|
||||
* omitted
|
||||
*/
|
||||
@Test
|
||||
public void test1() throws Exception {
|
||||
public void test01() throws Exception {
|
||||
String testTS = "2009-01-01 10:50:00";
|
||||
String ExpectedTS = "2009-01-01 10:50:0";
|
||||
Timestamp ts = Timestamp.valueOf(testTS);
|
||||
@ -96,23 +57,23 @@ public class TimestampTests {
|
||||
assertEquals(ts, ts2, "Error ts1 != ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate two Timestamps created from the same string are equal
|
||||
*/
|
||||
@Test
|
||||
public void test2() throws Exception {
|
||||
public void test02() throws Exception {
|
||||
String testTS = "2009-01-01 10:50:0";
|
||||
Timestamp ts = Timestamp.valueOf(testTS);
|
||||
Timestamp ts2 = Timestamp.valueOf(testTS);
|
||||
assertEquals(ts, ts2, "Error ts1 != ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that two Timestamp values one with leading 0s for month and day
|
||||
* equals same string without the leading 0s.
|
||||
*/
|
||||
@Test
|
||||
public void test3() throws Exception {
|
||||
public void test03() throws Exception {
|
||||
String testTS = "2009-1-1 10:50:0";
|
||||
String ExpectedTS = "2009-01-01 10:50:0";
|
||||
Timestamp ts = Timestamp.valueOf(testTS);
|
||||
@ -120,12 +81,12 @@ public class TimestampTests {
|
||||
assertEquals(ts, ts2, "Error ts1 != ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that two Timestamp values one with leading 0s for day omitted
|
||||
* are equal
|
||||
*/
|
||||
@Test
|
||||
public void test4() throws Exception {
|
||||
public void test04() throws Exception {
|
||||
String testTS = "2009-01-1 10:50:0";
|
||||
String ExpectedTS = "2009-01-01 10:50:0";
|
||||
Timestamp ts = Timestamp.valueOf(testTS);
|
||||
@ -133,12 +94,12 @@ public class TimestampTests {
|
||||
assertEquals(ts, ts2, "Error ts1 != ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that two Timestamp values one with leading 0s for month omitted
|
||||
* and both with leading 0s for seconds omitted are equal
|
||||
*/
|
||||
@Test
|
||||
public void test5() throws Exception {
|
||||
public void test05() throws Exception {
|
||||
String testTS = "2009-1-01 10:50:0";
|
||||
String ExpectedTS = "2009-01-01 10:50:0";
|
||||
Timestamp ts = Timestamp.valueOf(testTS);
|
||||
@ -146,11 +107,11 @@ public class TimestampTests {
|
||||
assertEquals(ts, ts2, "Error ts1 != ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that two Timestamp values one with leading 0s for month omitted
|
||||
*/
|
||||
@Test
|
||||
public void test6() throws Exception {
|
||||
public void test06() throws Exception {
|
||||
String testTS = "2005-1-01 10:20:50.00";
|
||||
String ExpectedTS = "2005-01-01 10:20:50.00";
|
||||
Timestamp ts = Timestamp.valueOf(testTS);
|
||||
@ -158,52 +119,53 @@ public class TimestampTests {
|
||||
assertEquals(ts, ts2, "Error ts1 != ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that two Timestamp values one created using valueOf and another
|
||||
* via a constructor are equal
|
||||
*/
|
||||
@Test
|
||||
public void test7() {
|
||||
public void test07() {
|
||||
|
||||
Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.001");
|
||||
Timestamp ts2 = new Timestamp(96, 11, 13, 14, 15, 25, 1000000);
|
||||
assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that two Timestamp values one created using valueOf and another
|
||||
* via a constructor are equal
|
||||
*/
|
||||
@Test
|
||||
public void test8() {
|
||||
public void test08() {
|
||||
Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.001");
|
||||
Timestamp ts2 = new Timestamp(ts1.getTime());
|
||||
assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that two Timestamp values one created using valueOf and another
|
||||
* via a constructor are equal
|
||||
*/
|
||||
@Test
|
||||
public void test9() {
|
||||
public void test09() {
|
||||
|
||||
Timestamp ts1 = Timestamp.valueOf("1996-12-13 14:15:25.0");
|
||||
Timestamp ts2 = new Timestamp(96, 11, 13, 14, 15, 25, 0);
|
||||
assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Timestamp cannot be equal to null
|
||||
*/
|
||||
@Test
|
||||
public void test10() {
|
||||
|
||||
Timestamp ts1 = Timestamp.valueOf("1961-08-30 14:15:25.745634");
|
||||
assertFalse(ts1.equals(null), "Error ts1 == null");
|
||||
Timestamp ts2 = null;
|
||||
assertFalse(ts1.equals(ts2), "Error ts1 == null");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Timestamp is equal to another timestamp created with the
|
||||
* using the same value but not equal to a Timestamp which is one day later
|
||||
*/
|
||||
@ -218,7 +180,7 @@ public class TimestampTests {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Timestamp is equal to itself
|
||||
*/
|
||||
@Test
|
||||
@ -227,19 +189,20 @@ public class TimestampTests {
|
||||
assertTrue(ts1.equals(ts1), "Error ts1 != ts1");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that two Timestamps are equal when one is created from the
|
||||
* toString() of the other
|
||||
*/
|
||||
@Test
|
||||
public void test13() {
|
||||
Timestamp ts1 = Timestamp.valueOf("1996-12-10 12:26:19.12");
|
||||
@Test(dataProvider = "validTimestampValues")
|
||||
public void test13(String ts, String expectedTS) {
|
||||
Timestamp ts1 = Timestamp.valueOf(ts);
|
||||
Timestamp ts2 = Timestamp.valueOf(ts1.toString());
|
||||
assertTrue(ts1.equals(ts2) && ts2.equals(ts1), "Error ts1 != ts2");
|
||||
assertTrue(ts1.equals(ts2) && ts2.equals(ts1)
|
||||
&& ts1.toString().equals(expectedTS), "Error ts1 != ts2");
|
||||
}
|
||||
|
||||
// Before Tests
|
||||
/**
|
||||
/*
|
||||
* Validate that Timestamp ts1 is before Timestamp ts2
|
||||
*/
|
||||
@Test
|
||||
@ -249,7 +212,7 @@ public class TimestampTests {
|
||||
assertTrue(ts1.before(ts2), "Error ts1 not before ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that Timestamp ts1 is before Timestamp ts2
|
||||
*/
|
||||
@Test
|
||||
@ -259,7 +222,7 @@ public class TimestampTests {
|
||||
assertTrue(ts1.before(ts2), "Error ts1 not before ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that Timestamp ts1 is before Timestamp ts2
|
||||
*/
|
||||
@Test
|
||||
@ -289,7 +252,7 @@ public class TimestampTests {
|
||||
assertFalse(ts1.before(ts1), "Error ts1 before ts1!");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Create 3 Timestamps and make sure the 1st is before the other two
|
||||
* Timestamps which are each greater than the one before it
|
||||
*/
|
||||
@ -302,7 +265,7 @@ public class TimestampTests {
|
||||
assertTrue(ts1.before(ts2) && ts2.before(ts3) && ts1.before(ts3));
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that Timestamp ts1 is not after Timestamp ts2
|
||||
*/
|
||||
@Test
|
||||
@ -313,7 +276,7 @@ public class TimestampTests {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that Timestamp ts1 is after Timestamp ts2
|
||||
*/
|
||||
@Test
|
||||
@ -323,7 +286,7 @@ public class TimestampTests {
|
||||
assertTrue(ts1.after(ts2), "Error ts1 not after ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a NullPointerException is thrown if a null is passed to the
|
||||
* after method
|
||||
*/
|
||||
@ -333,7 +296,7 @@ public class TimestampTests {
|
||||
ts1.after(null);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Timestamp cannot be after itself
|
||||
*/
|
||||
@Test
|
||||
@ -341,9 +304,10 @@ public class TimestampTests {
|
||||
Timestamp ts1 = Timestamp.valueOf("1999-11-10 12:26:19.3456543");
|
||||
assertFalse(ts1.after(ts1), "Error ts1 is after itself");
|
||||
}
|
||||
/**
|
||||
* Validate that a Timestamp after() works correctly with Timestamp
|
||||
* created using milliseconds
|
||||
|
||||
/*
|
||||
* Validate that a Timestamp after() works correctly with Timestamp created
|
||||
* using milliseconds
|
||||
*/
|
||||
@Test
|
||||
public void test24() {
|
||||
@ -354,7 +318,7 @@ public class TimestampTests {
|
||||
assertTrue(ts1.after(ts2) && ts2.after(ts3) && ts1.after(ts3));
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate compareTo returns 0 for Timestamps that are the same
|
||||
*/
|
||||
@Test
|
||||
@ -364,7 +328,7 @@ public class TimestampTests {
|
||||
assertTrue(ts1.compareTo(ts2) == 0, "Error ts1 != ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate compareTo returns -1 for when the 1st Timestamp is earlier than
|
||||
* the 2nd Timestamp
|
||||
*/
|
||||
@ -376,7 +340,7 @@ public class TimestampTests {
|
||||
assertTrue(ts2.compareTo(ts1) == 1, "Error ts1 is not before ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate compareTo returns 1 for when the 1st Timestamp is later than the
|
||||
* 2nd Timestamp
|
||||
*/
|
||||
@ -388,7 +352,7 @@ public class TimestampTests {
|
||||
assertTrue(ts2.compareTo(ts1) == -1, "Error ts1 not after ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate compareTo returns 0 for Timestamps that are the same
|
||||
*/
|
||||
@Test
|
||||
@ -398,7 +362,7 @@ public class TimestampTests {
|
||||
assertTrue(ts1.compareTo(ts2) == 0, "Error ts1 != ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate compareTo returns 0 for Timestamps that are the same
|
||||
*/
|
||||
@Test
|
||||
@ -408,7 +372,7 @@ public class TimestampTests {
|
||||
assertFalse(ts1.equals(d), "Error ts1 == d");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate compareTo returns 0 for Timestamps that are the same
|
||||
*/
|
||||
@Test
|
||||
@ -418,7 +382,7 @@ public class TimestampTests {
|
||||
assertTrue(ts1.equals(d), "Error ts1 != d");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate equals returns false when a Date object is passed to equals
|
||||
*/
|
||||
@Test
|
||||
@ -428,7 +392,7 @@ public class TimestampTests {
|
||||
assertFalse(ts1.equals(d), "Error ts1 != d");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate equals returns false when a Date object is passed to equals
|
||||
*/
|
||||
@Test
|
||||
@ -438,7 +402,7 @@ public class TimestampTests {
|
||||
assertFalse(ts1.equals(d), "Error ts1 != d");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate equals returns false when a Time object is passed to equals
|
||||
*/
|
||||
@Test
|
||||
@ -448,7 +412,7 @@ public class TimestampTests {
|
||||
assertFalse(ts1.equals(t1), "Error ts1 == t1");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate equals returns false when a String object is passed to equals
|
||||
*/
|
||||
@Test
|
||||
@ -457,7 +421,7 @@ public class TimestampTests {
|
||||
assertFalse(ts1.equals("1966-08-30 08:08:08"), "Error ts1 == a String");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate getTime() returns the same value from 2 timeStamps created by
|
||||
*/
|
||||
@Test
|
||||
@ -469,7 +433,7 @@ public class TimestampTests {
|
||||
assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate getTime() returns the same value from 2 timeStamps when
|
||||
* setTime() is used to specify the same value for both Timestamps
|
||||
*/
|
||||
@ -483,7 +447,7 @@ public class TimestampTests {
|
||||
assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for an invalid nanos value
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
@ -493,7 +457,7 @@ public class TimestampTests {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an IllegalArgumentException is thrown for an invalid nanos value
|
||||
*/
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
@ -501,10 +465,9 @@ public class TimestampTests {
|
||||
int nanos = 999999999;
|
||||
Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
|
||||
ts1.setNanos(nanos + 1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate you can set nanos to 999999999
|
||||
*/
|
||||
@Test
|
||||
@ -513,10 +476,9 @@ public class TimestampTests {
|
||||
Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
|
||||
ts1.setNanos(nanos);
|
||||
assertTrue(ts1.getNanos() == nanos, "Error Invalid Nanos value");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate you can set nanos to 0
|
||||
*/
|
||||
@Test
|
||||
@ -525,10 +487,9 @@ public class TimestampTests {
|
||||
Timestamp ts1 = Timestamp.valueOf("1961-08-30 00:00:00");
|
||||
ts1.setNanos(nanos);
|
||||
assertTrue(ts1.getNanos() == nanos, "Error Invalid Nanos value");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Timestamp made from a LocalDateTime are equal
|
||||
*/
|
||||
@Test
|
||||
@ -539,7 +500,7 @@ public class TimestampTests {
|
||||
assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Timestamp LocalDateTime value, made from a LocalDateTime
|
||||
* are equal
|
||||
*/
|
||||
@ -551,7 +512,7 @@ public class TimestampTests {
|
||||
"Error LocalDateTime values are not equal");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an NPE occurs when a null LocalDateTime is passed to valueOF
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@ -560,7 +521,7 @@ public class TimestampTests {
|
||||
Timestamp.valueOf(ldt);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Timestamp made from a Instant are equal
|
||||
*/
|
||||
@Test
|
||||
@ -571,7 +532,7 @@ public class TimestampTests {
|
||||
assertTrue(ts1.equals(ts2), "Error ts1 != ts2");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate that a Timestamp made from a Instant are equal
|
||||
*/
|
||||
@Test
|
||||
@ -582,7 +543,7 @@ public class TimestampTests {
|
||||
"Error Instant values do not match");
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Validate an NPE occurs when a null instant is passed to from
|
||||
*/
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
@ -592,7 +553,7 @@ public class TimestampTests {
|
||||
}
|
||||
|
||||
// Added SQE tests
|
||||
/**
|
||||
/*
|
||||
* Create a Timestamp and a 2nd Timestamp that is 1 month earlier and
|
||||
* validate that it is not before or after the original Timestamp
|
||||
*/
|
||||
@ -607,7 +568,7 @@ public class TimestampTests {
|
||||
assertFalse(ts1.before(ts2) || ts2.after(ts1));
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Create two Timestamps and validate that compareTo returns 1 to indicate
|
||||
* the 1st Timestamp is greater than the 2nd Timestamp
|
||||
*/
|
||||
@ -622,7 +583,7 @@ public class TimestampTests {
|
||||
assertTrue(ts1.compareTo(ts2) == 1);
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Create two Timestamps and validate that the 1st Timestamp is not equal to
|
||||
* the 2nd Timestamp but equal to itself
|
||||
*/
|
||||
@ -637,4 +598,114 @@ public class TimestampTests {
|
||||
assertTrue(!ts1.equals(ts2) && ts1.equals(ts1));
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate that two Timestamps are equal when one is created from the
|
||||
* toString() of the other
|
||||
*/
|
||||
@Test(dataProvider = "validateNanos")
|
||||
public void test51(String ts, int nanos) {
|
||||
Timestamp ts1 = Timestamp.valueOf(ts);
|
||||
Timestamp ts2 = Timestamp.valueOf(ts1.toString());
|
||||
assertTrue(ts1.getNanos() == nanos && ts1.equals(ts2),
|
||||
"Error with Nanos");
|
||||
}
|
||||
|
||||
/*
|
||||
* DataProvider used to provide Timestamps which are not valid and are used
|
||||
* to validate that an IllegalArgumentException will be thrown from the
|
||||
* valueOf method
|
||||
*/
|
||||
@DataProvider(name = "invalidTimestampValues")
|
||||
private Object[][] invalidTimestampValues() {
|
||||
return new Object[][]{
|
||||
{"2009-11-01-01 10:50:01"},
|
||||
{"aaaa-11-01-01 10:50"},
|
||||
{"aaaa-11-01 10:50"},
|
||||
{"1961--30 00:00:00"},
|
||||
{"--30 00:00:00"},
|
||||
{"-- 00:00:00"},
|
||||
{"1961-1- 00:00:00"},
|
||||
{"2009-11-01"},
|
||||
{"10:50:01"},
|
||||
{"1961-a-30 00:00:00"},
|
||||
{"1961-01-bb 00:00:00"},
|
||||
{"1961-08-30 00:00:00."},
|
||||
{"1961-08-30 :00:00"},
|
||||
{"1961-08-30 00::00"},
|
||||
{"1961-08-30 00:00:"},
|
||||
{"1961-08-30 ::"},
|
||||
{"1961-08-30 0a:00:00"},
|
||||
{"1961-08-30 00:bb:00"},
|
||||
{"1961-08-30 00:01:cc"},
|
||||
{"1961-08-30 00:00:00.01a"},
|
||||
{"1961-08-30 00:00:00.a"},
|
||||
{"1996-12-10 12:26:19.1234567890"},
|
||||
{null}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* DataProvider used to provide Timestamps which are valid and are used
|
||||
* to validate that an IllegalArgumentException will not be thrown from the
|
||||
* valueOf method and the corect value from toString() is returned
|
||||
*/
|
||||
@DataProvider(name = "validTimestampValues")
|
||||
private Object[][] validTimestampValues() {
|
||||
return new Object[][]{
|
||||
{"1961-08-30 00:00:00", "1961-08-30 00:00:00.0"},
|
||||
{"1961-08-30 11:22:33", "1961-08-30 11:22:33.0"},
|
||||
{"1961-8-30 00:00:00", "1961-08-30 00:00:00.0"},
|
||||
{"1966-08-1 00:00:00", "1966-08-01 00:00:00.0"},
|
||||
{"1996-12-10 12:26:19.1", "1996-12-10 12:26:19.1"},
|
||||
{"1996-12-10 12:26:19.12", "1996-12-10 12:26:19.12"},
|
||||
{"1996-12-10 12:26:19.123", "1996-12-10 12:26:19.123"},
|
||||
{"1996-12-10 12:26:19.1234", "1996-12-10 12:26:19.1234"},
|
||||
{"1996-12-10 12:26:19.12345", "1996-12-10 12:26:19.12345"},
|
||||
{"1996-12-10 12:26:19.123456", "1996-12-10 12:26:19.123456"},
|
||||
{"1996-12-10 12:26:19.1234567", "1996-12-10 12:26:19.1234567"},
|
||||
{"1996-12-10 12:26:19.12345678", "1996-12-10 12:26:19.12345678"},
|
||||
{"1996-12-10 12:26:19.123456789", "1996-12-10 12:26:19.123456789"},
|
||||
{"1996-12-10 12:26:19.000000001", "1996-12-10 12:26:19.000000001"},
|
||||
{"1996-12-10 12:26:19.000000012", "1996-12-10 12:26:19.000000012"},
|
||||
{"1996-12-10 12:26:19.000000123", "1996-12-10 12:26:19.000000123"},
|
||||
{"1996-12-10 12:26:19.000001234", "1996-12-10 12:26:19.000001234"},
|
||||
{"1996-12-10 12:26:19.000012345", "1996-12-10 12:26:19.000012345"},
|
||||
{"1996-12-10 12:26:19.000123456", "1996-12-10 12:26:19.000123456"},
|
||||
{"1996-12-10 12:26:19.001234567", "1996-12-10 12:26:19.001234567"},
|
||||
{"1996-12-10 12:26:19.12345678", "1996-12-10 12:26:19.12345678"},
|
||||
{"1996-12-10 12:26:19.0", "1996-12-10 12:26:19.0"},
|
||||
{"1996-12-10 12:26:19.01230", "1996-12-10 12:26:19.0123"}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* DataProvider used to provide Timestamp and Nanos values in order to
|
||||
* validate that the correct Nanos value is generated from the specified
|
||||
* Timestamp
|
||||
*/
|
||||
@DataProvider(name = "validateNanos")
|
||||
private Object[][] validateNanos() {
|
||||
return new Object[][]{
|
||||
{"1961-08-30 00:00:00", 0},
|
||||
{"1996-12-10 12:26:19.1", 100000000},
|
||||
{"1996-12-10 12:26:19.12", 120000000},
|
||||
{"1996-12-10 12:26:19.123", 123000000},
|
||||
{"1996-12-10 12:26:19.1234", 123400000},
|
||||
{"1996-12-10 12:26:19.12345", 123450000},
|
||||
{"1996-12-10 12:26:19.123456", 123456000},
|
||||
{"1996-12-10 12:26:19.1234567", 123456700},
|
||||
{"1996-12-10 12:26:19.12345678", 123456780},
|
||||
{"1996-12-10 12:26:19.123456789", 123456789},
|
||||
{"1996-12-10 12:26:19.000000001", 1},
|
||||
{"1996-12-10 12:26:19.000000012", 12},
|
||||
{"1996-12-10 12:26:19.000000123", 123},
|
||||
{"1996-12-10 12:26:19.000001234", 1234},
|
||||
{"1996-12-10 12:26:19.000012345", 12345},
|
||||
{"1996-12-10 12:26:19.000123456", 123456},
|
||||
{"1996-12-10 12:26:19.001234567", 1234567},
|
||||
{"1996-12-10 12:26:19.012345678", 12345678},
|
||||
{"1996-12-10 12:26:19.0", 0},
|
||||
{"1996-12-10 12:26:19.01230", 12300000}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user