corrected the test of parseCVS with "h:mm z" format by replacing the current date/time with a series of calls using hard-coded time values

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137574 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Steven Caswell 2003-08-06 00:42:56 +00:00
parent 8b2c1cf865
commit 76cfb62b92
1 changed files with 38 additions and 7 deletions

View File

@ -413,14 +413,45 @@ public void testParseCVS() throws Exception {
assertEquals("parseCVS format MMM d, yyyy h:mm a",
now, DateUtils.parseCVS(new SimpleDateFormat("MMM d, yyyy h:mm a").format(now.getTime())), 50);
// h:mm z
/*
* This format is difficult to test using the current time because the
* parseCVS method applies the default date of January 1, 1970 to the
* parsed time. The most straightforward way to test the parse is to
* pass in a known value, and test the output against this know value.
*/
now = Calendar.getInstance();
now.set(Calendar.MILLISECOND, 0);
now.set(Calendar.SECOND, 0);
now.set(Calendar.DAY_OF_MONTH, 1);
now.set(Calendar.MONTH, Calendar.JANUARY);
now.set(Calendar.YEAR, 1970);
assertEquals("parseCVS format h:mm z",
now, DateUtils.parseCVS(new SimpleDateFormat("H:mm z").format(now.getTime())), 50);
now.setTime(new SimpleDateFormat("h:mm z").parse("16:30 GMT"));
assertEquals("parseCVS format h:mm z 16:30 GMT",
now, DateUtils.parseCVS("16:30 GMT"), 50);
now = Calendar.getInstance();
now.setTime(new SimpleDateFormat("h:mm z").parse("16:30 EST"));
assertEquals("parseCVS format h:mm z 16:30 EST",
now, DateUtils.parseCVS("16:30 EST"), 50);
now = Calendar.getInstance();
now.setTime(new SimpleDateFormat("h:mm z").parse("16:30 GMT-05:00"));
assertEquals("parseCVS format h:mm z 16:30 GMT-05:00",
now, DateUtils.parseCVS("16:30 GMT-05:00"), 50);
now = Calendar.getInstance();
now.setTime(new SimpleDateFormat("h:mm z").parse("16:30 GMT+01:00"));
assertEquals("parseCVS format h:mm z 16:30 GMT+01:00",
now, DateUtils.parseCVS("16:30 GMT+01:00"), 50);
now = Calendar.getInstance();
now.setTime(new SimpleDateFormat("h:mm z").parse("06:30 GMT"));
assertEquals("parseCVS format h:mm z 06:30 GMT",
now, DateUtils.parseCVS("06:30 GMT"), 50);
now = Calendar.getInstance();
now.setTime(new SimpleDateFormat("h:mm z").parse("06:30 EST"));
assertEquals("parseCVS format h:mm z 06:30 EST",
now, DateUtils.parseCVS("06:30 EST"), 50);
now = Calendar.getInstance();
now.setTime(new SimpleDateFormat("h:mm z").parse("06:30 GMT-05:00"));
assertEquals("parseCVS format h:mm z 06:30 GMT-05:00",
now, DateUtils.parseCVS("06:30 GMT-05:00"), 50);
now = Calendar.getInstance();
now.setTime(new SimpleDateFormat("h:mm z").parse("06:30 GMT+01:00"));
assertEquals("parseCVS format h:mm z 06:30 GMT+01:00",
now, DateUtils.parseCVS("06:30 GMT+01:00"), 50);
now = Calendar.getInstance();
now.add(Calendar.WEEK_OF_MONTH, -1);