Patches to increase test coverage from Nathan Beyer [nbeyer@kc.rr.com]
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@232202 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
030267a91b
commit
9dfd3b4e8e
|
@ -18,6 +18,7 @@ package org.apache.commons.lang.time;
|
|||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
@ -61,6 +62,40 @@ public class DateFormatUtilsTest extends TestCase {
|
|||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
public void testFormat() {
|
||||
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
c.set(2005,0,1,12,0,0);
|
||||
c.setTimeZone(TimeZone.getDefault());
|
||||
StringBuffer buffer = new StringBuffer ();
|
||||
int year = c.get(Calendar.YEAR);
|
||||
int month = c.get(Calendar.MONTH) + 1;
|
||||
int day = c.get(Calendar.DAY_OF_MONTH);
|
||||
int hour = c.get(Calendar.HOUR_OF_DAY);
|
||||
buffer.append (year);
|
||||
buffer.append(month);
|
||||
buffer.append(day);
|
||||
buffer.append(hour);
|
||||
assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime(), "yyyyMdH"));
|
||||
|
||||
assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime().getTime(), "yyyyMdH"));
|
||||
|
||||
assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime(), "yyyyMdH", Locale.US));
|
||||
|
||||
assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime().getTime(), "yyyyMdH", Locale.US));
|
||||
}
|
||||
|
||||
public void testFormatUTC() {
|
||||
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
c.set(2005,0,1,12,0,0);
|
||||
assertEquals ("2005-01-01T12:00:00", DateFormatUtils.formatUTC(c.getTime(), DateFormatUtils.ISO_DATETIME_FORMAT.getPattern()));
|
||||
|
||||
assertEquals ("2005-01-01T12:00:00", DateFormatUtils.formatUTC(c.getTime().getTime(), DateFormatUtils.ISO_DATETIME_FORMAT.getPattern()));
|
||||
|
||||
assertEquals ("2005-01-01T12:00:00", DateFormatUtils.formatUTC(c.getTime(), DateFormatUtils.ISO_DATETIME_FORMAT.getPattern(), Locale.US));
|
||||
|
||||
assertEquals ("2005-01-01T12:00:00", DateFormatUtils.formatUTC(c.getTime().getTime(), DateFormatUtils.ISO_DATETIME_FORMAT.getPattern(), Locale.US));
|
||||
}
|
||||
|
||||
public void testDateTimeISO(){
|
||||
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
|
||||
Calendar cal = Calendar.getInstance(timeZone);
|
||||
|
|
|
@ -303,6 +303,8 @@ public class DateUtilsTest extends TestCase {
|
|||
assertEquals("round semimonth-2 failed",
|
||||
dateParser.parse("November 16, 2001"),
|
||||
DateUtils.round(date2, DateUtils.SEMI_MONTH));
|
||||
|
||||
|
||||
assertEquals("round date-1 failed",
|
||||
dateParser.parse("February 13, 2002"),
|
||||
DateUtils.round(date1, Calendar.DATE));
|
||||
|
|
Loading…
Reference in New Issue