Tab police

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@753662 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2009-03-14 14:05:13 +00:00
parent 80941d0b80
commit b43136cb1c
4 changed files with 1153 additions and 1153 deletions

View File

@ -46,8 +46,8 @@ public class CalendarUtilsTest extends TestCase {
} }
public static Test suite() { public static Test suite() {
TestSuite suite = new TestSuite(CalendarUtilsTest.class); TestSuite suite = new TestSuite(CalendarUtilsTest.class);
suite.setName("CalendarUtilsTest Tests"); suite.setName("CalendarUtilsTest Tests");
return suite; return suite;
} }

View File

@ -34,475 +34,475 @@ public class DateUtilsFragmentTest extends TestCase {
return suite; return suite;
} }
private static final int months = 7; // second final prime before 12 private static final int months = 7; // second final prime before 12
private static final int days = 23; // second final prime before 31 (and valid) private static final int days = 23; // second final prime before 31 (and valid)
private static final int hours = 19; // second final prime before 24 private static final int hours = 19; // second final prime before 24
private static final int minutes = 53; // second final prime before 60 private static final int minutes = 53; // second final prime before 60
private static final int seconds = 47; // third final prime before 60 private static final int seconds = 47; // third final prime before 60
private static final int millis = 991; // second final prime before 1000 private static final int millis = 991; // second final prime before 1000
private Date aDate; private Date aDate;
private Calendar aCalendar; private Calendar aCalendar;
@Override @Override
protected void setUp() { protected void setUp() {
aCalendar = Calendar.getInstance(); aCalendar = Calendar.getInstance();
aCalendar.set(2005, months, days, hours, minutes, seconds); aCalendar.set(2005, months, days, hours, minutes, seconds);
aCalendar.set(Calendar.MILLISECOND, millis); aCalendar.set(Calendar.MILLISECOND, millis);
aDate = aCalendar.getTime(); aDate = aCalendar.getTime();
} }
public void testNullDate() { public void testNullDate() {
try { try {
DateUtils.getFragmentInMilliseconds((Date) null, Calendar.MILLISECOND); DateUtils.getFragmentInMilliseconds((Date) null, Calendar.MILLISECOND);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
try { try {
DateUtils.getFragmentInSeconds((Date) null, Calendar.MILLISECOND); DateUtils.getFragmentInSeconds((Date) null, Calendar.MILLISECOND);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
try { try {
DateUtils.getFragmentInMinutes((Date) null, Calendar.MILLISECOND); DateUtils.getFragmentInMinutes((Date) null, Calendar.MILLISECOND);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
try { try {
DateUtils.getFragmentInHours((Date) null, Calendar.MILLISECOND); DateUtils.getFragmentInHours((Date) null, Calendar.MILLISECOND);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
try { try {
DateUtils.getFragmentInDays((Date) null, Calendar.MILLISECOND); DateUtils.getFragmentInDays((Date) null, Calendar.MILLISECOND);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
} }
public void testNullCalendar() { public void testNullCalendar() {
try { try {
DateUtils.getFragmentInMilliseconds((Calendar) null, Calendar.MILLISECOND); DateUtils.getFragmentInMilliseconds((Calendar) null, Calendar.MILLISECOND);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
try { try {
DateUtils.getFragmentInSeconds((Calendar) null, Calendar.MILLISECOND); DateUtils.getFragmentInSeconds((Calendar) null, Calendar.MILLISECOND);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
try { try {
DateUtils.getFragmentInMinutes((Calendar) null, Calendar.MILLISECOND); DateUtils.getFragmentInMinutes((Calendar) null, Calendar.MILLISECOND);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
try { try {
DateUtils.getFragmentInHours((Calendar) null, Calendar.MILLISECOND); DateUtils.getFragmentInHours((Calendar) null, Calendar.MILLISECOND);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
try { try {
DateUtils.getFragmentInDays((Calendar) null, Calendar.MILLISECOND); DateUtils.getFragmentInDays((Calendar) null, Calendar.MILLISECOND);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
} }
public void testInvalidFragmentWithDate() { public void testInvalidFragmentWithDate() {
try { try {
DateUtils.getFragmentInMilliseconds(aDate, 0); DateUtils.getFragmentInMilliseconds(aDate, 0);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
try { try {
DateUtils.getFragmentInSeconds(aDate, 0); DateUtils.getFragmentInSeconds(aDate, 0);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
try { try {
DateUtils.getFragmentInMinutes(aDate, 0); DateUtils.getFragmentInMinutes(aDate, 0);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
try { try {
DateUtils.getFragmentInHours(aDate, 0); DateUtils.getFragmentInHours(aDate, 0);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
try { try {
DateUtils.getFragmentInDays(aDate, 0); DateUtils.getFragmentInDays(aDate, 0);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
} }
public void testInvalidFragmentWithCalendar() { public void testInvalidFragmentWithCalendar() {
try { try {
DateUtils.getFragmentInMilliseconds(aCalendar, 0); DateUtils.getFragmentInMilliseconds(aCalendar, 0);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
try { try {
DateUtils.getFragmentInSeconds(aCalendar, 0); DateUtils.getFragmentInSeconds(aCalendar, 0);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
try { try {
DateUtils.getFragmentInMinutes(aCalendar, 0); DateUtils.getFragmentInMinutes(aCalendar, 0);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
try { try {
DateUtils.getFragmentInHours(aCalendar, 0); DateUtils.getFragmentInHours(aCalendar, 0);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
try { try {
DateUtils.getFragmentInDays(aCalendar, 0); DateUtils.getFragmentInDays(aCalendar, 0);
fail(); fail();
} catch(IllegalArgumentException iae) {} } catch(IllegalArgumentException iae) {}
} }
public void testMillisecondFragmentInLargerUnitWithDate() { public void testMillisecondFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInMilliseconds(aDate, Calendar.MILLISECOND)); assertEquals(0, DateUtils.getFragmentInMilliseconds(aDate, Calendar.MILLISECOND));
assertEquals(0, DateUtils.getFragmentInSeconds(aDate, Calendar.MILLISECOND)); assertEquals(0, DateUtils.getFragmentInSeconds(aDate, Calendar.MILLISECOND));
assertEquals(0, DateUtils.getFragmentInMinutes(aDate, Calendar.MILLISECOND)); assertEquals(0, DateUtils.getFragmentInMinutes(aDate, Calendar.MILLISECOND));
assertEquals(0, DateUtils.getFragmentInHours(aDate, Calendar.MILLISECOND)); assertEquals(0, DateUtils.getFragmentInHours(aDate, Calendar.MILLISECOND));
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.MILLISECOND)); assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.MILLISECOND));
} }
public void testMillisecondFragmentInLargerUnitWithCalendar() { public void testMillisecondFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MILLISECOND)); assertEquals(0, DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MILLISECOND));
assertEquals(0, DateUtils.getFragmentInSeconds(aCalendar, Calendar.MILLISECOND)); assertEquals(0, DateUtils.getFragmentInSeconds(aCalendar, Calendar.MILLISECOND));
assertEquals(0, DateUtils.getFragmentInMinutes(aCalendar, Calendar.MILLISECOND)); assertEquals(0, DateUtils.getFragmentInMinutes(aCalendar, Calendar.MILLISECOND));
assertEquals(0, DateUtils.getFragmentInHours(aCalendar, Calendar.MILLISECOND)); assertEquals(0, DateUtils.getFragmentInHours(aCalendar, Calendar.MILLISECOND));
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.MILLISECOND)); assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.MILLISECOND));
} }
public void testSecondFragmentInLargerUnitWithDate() { public void testSecondFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInSeconds(aDate, Calendar.SECOND)); assertEquals(0, DateUtils.getFragmentInSeconds(aDate, Calendar.SECOND));
assertEquals(0, DateUtils.getFragmentInMinutes(aDate, Calendar.SECOND)); assertEquals(0, DateUtils.getFragmentInMinutes(aDate, Calendar.SECOND));
assertEquals(0, DateUtils.getFragmentInHours(aDate, Calendar.SECOND)); assertEquals(0, DateUtils.getFragmentInHours(aDate, Calendar.SECOND));
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.SECOND)); assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.SECOND));
} }
public void testSecondFragmentInLargerUnitWithCalendar() { public void testSecondFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInSeconds(aCalendar, Calendar.SECOND)); assertEquals(0, DateUtils.getFragmentInSeconds(aCalendar, Calendar.SECOND));
assertEquals(0, DateUtils.getFragmentInMinutes(aCalendar, Calendar.SECOND)); assertEquals(0, DateUtils.getFragmentInMinutes(aCalendar, Calendar.SECOND));
assertEquals(0, DateUtils.getFragmentInHours(aCalendar, Calendar.SECOND)); assertEquals(0, DateUtils.getFragmentInHours(aCalendar, Calendar.SECOND));
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.SECOND)); assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.SECOND));
} }
public void testMinuteFragmentInLargerUnitWithDate() { public void testMinuteFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInMinutes(aDate, Calendar.MINUTE)); assertEquals(0, DateUtils.getFragmentInMinutes(aDate, Calendar.MINUTE));
assertEquals(0, DateUtils.getFragmentInHours(aDate, Calendar.MINUTE)); assertEquals(0, DateUtils.getFragmentInHours(aDate, Calendar.MINUTE));
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.MINUTE)); assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.MINUTE));
} }
public void testMinuteFragmentInLargerUnitWithCalendar() { public void testMinuteFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInMinutes(aCalendar, Calendar.MINUTE)); assertEquals(0, DateUtils.getFragmentInMinutes(aCalendar, Calendar.MINUTE));
assertEquals(0, DateUtils.getFragmentInHours(aCalendar, Calendar.MINUTE)); assertEquals(0, DateUtils.getFragmentInHours(aCalendar, Calendar.MINUTE));
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.MINUTE)); assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.MINUTE));
} }
public void testHourOfDayFragmentInLargerUnitWithDate() { public void testHourOfDayFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInHours(aDate, Calendar.HOUR_OF_DAY)); assertEquals(0, DateUtils.getFragmentInHours(aDate, Calendar.HOUR_OF_DAY));
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.HOUR_OF_DAY)); assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.HOUR_OF_DAY));
} }
public void testHourOfDayFragmentInLargerUnitWithCalendar() { public void testHourOfDayFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInHours(aCalendar, Calendar.HOUR_OF_DAY)); assertEquals(0, DateUtils.getFragmentInHours(aCalendar, Calendar.HOUR_OF_DAY));
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.HOUR_OF_DAY)); assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.HOUR_OF_DAY));
} }
public void testDayOfYearFragmentInLargerUnitWithDate() { public void testDayOfYearFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.DAY_OF_YEAR)); assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.DAY_OF_YEAR));
} }
public void testDayOfYearFragmentInLargerUnitWithCalendar() { public void testDayOfYearFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.DAY_OF_YEAR)); assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.DAY_OF_YEAR));
} }
public void testDateFragmentInLargerUnitWithDate() { public void testDateFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.DATE)); assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.DATE));
} }
public void testDateFragmentInLargerUnitWithCalendar() { public void testDateFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.DATE)); assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.DATE));
} }
//Calendar.SECOND as useful fragment //Calendar.SECOND as useful fragment
public void testMillisecondsOfSecondWithDate() { public void testMillisecondsOfSecondWithDate() {
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.SECOND); long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.SECOND);
assertEquals(millis, testResult); assertEquals(millis, testResult);
} }
public void testMillisecondsOfSecondWithCalendar() { public void testMillisecondsOfSecondWithCalendar() {
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.SECOND); long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.SECOND);
assertEquals(millis, testResult); assertEquals(millis, testResult);
assertEquals(aCalendar.get(Calendar.MILLISECOND), testResult); assertEquals(aCalendar.get(Calendar.MILLISECOND), testResult);
} }
//Calendar.MINUTE as useful fragment //Calendar.MINUTE as useful fragment
public void testMillisecondsOfMinuteWithDate() { public void testMillisecondsOfMinuteWithDate() {
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.MINUTE); long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.MINUTE);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND), testResult); assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND), testResult);
} }
public void testMillisecondsOfMinuteWithCalender() { public void testMillisecondsOfMinuteWithCalender() {
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MINUTE); long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MINUTE);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND), testResult); assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND), testResult);
} }
public void testSecondsofMinuteWithDate() { public void testSecondsofMinuteWithDate() {
long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.MINUTE); long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.MINUTE);
assertEquals(seconds, testResult); assertEquals(seconds, testResult);
} }
public void testSecondsofMinuteWithCalendar() { public void testSecondsofMinuteWithCalendar() {
long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.MINUTE); long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.MINUTE);
assertEquals(seconds, testResult); assertEquals(seconds, testResult);
assertEquals(aCalendar.get(Calendar.SECOND), testResult); assertEquals(aCalendar.get(Calendar.SECOND), testResult);
} }
//Calendar.HOUR_OF_DAY as useful fragment //Calendar.HOUR_OF_DAY as useful fragment
public void testMillisecondsOfHourWithDate() { public void testMillisecondsOfHourWithDate() {
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.HOUR_OF_DAY); long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.HOUR_OF_DAY);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE), testResult); assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE), testResult);
} }
public void testMillisecondsOfHourWithCalendar() { public void testMillisecondsOfHourWithCalendar() {
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.HOUR_OF_DAY); long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.HOUR_OF_DAY);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE), testResult); assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE), testResult);
} }
public void testSecondsofHourWithDate() { public void testSecondsofHourWithDate() {
long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.HOUR_OF_DAY); long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.HOUR_OF_DAY);
assertEquals( assertEquals(
seconds seconds
+ (minutes + (minutes
* DateUtils.MILLIS_PER_MINUTE / DateUtils.MILLIS_PER_SECOND), * DateUtils.MILLIS_PER_MINUTE / DateUtils.MILLIS_PER_SECOND),
testResult); testResult);
} }
public void testSecondsofHourWithCalendar() { public void testSecondsofHourWithCalendar() {
long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.HOUR_OF_DAY); long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.HOUR_OF_DAY);
assertEquals( assertEquals(
seconds seconds
+ (minutes + (minutes
* DateUtils.MILLIS_PER_MINUTE / DateUtils.MILLIS_PER_SECOND), * DateUtils.MILLIS_PER_MINUTE / DateUtils.MILLIS_PER_SECOND),
testResult); testResult);
} }
public void testMinutesOfHourWithDate() { public void testMinutesOfHourWithDate() {
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.HOUR_OF_DAY); long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.HOUR_OF_DAY);
assertEquals(minutes, testResult); assertEquals(minutes, testResult);
} }
public void testMinutesOfHourWithCalendar() { public void testMinutesOfHourWithCalendar() {
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.HOUR_OF_DAY); long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.HOUR_OF_DAY);
assertEquals(minutes, testResult); assertEquals(minutes, testResult);
} }
//Calendar.DATE and Calendar.DAY_OF_YEAR as useful fragment //Calendar.DATE and Calendar.DAY_OF_YEAR as useful fragment
public void testMillisecondsOfDayWithDate() { public void testMillisecondsOfDayWithDate() {
long testresult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.DATE); long testresult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.DATE);
long expectedValue = millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR); long expectedValue = millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR);
assertEquals(expectedValue, testresult); assertEquals(expectedValue, testresult);
testresult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.DAY_OF_YEAR); testresult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.DAY_OF_YEAR);
assertEquals(expectedValue, testresult); assertEquals(expectedValue, testresult);
} }
public void testMillisecondsOfDayWithCalendar() { public void testMillisecondsOfDayWithCalendar() {
long testresult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.DATE); long testresult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.DATE);
long expectedValue = millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR); long expectedValue = millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR);
assertEquals(expectedValue, testresult); assertEquals(expectedValue, testresult);
testresult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.DAY_OF_YEAR); testresult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.DAY_OF_YEAR);
assertEquals(expectedValue, testresult); assertEquals(expectedValue, testresult);
} }
public void testSecondsOfDayWithDate() { public void testSecondsOfDayWithDate() {
long testresult = DateUtils.getFragmentInSeconds(aDate, Calendar.DATE); long testresult = DateUtils.getFragmentInSeconds(aDate, Calendar.DATE);
long expectedValue = seconds + ((minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_SECOND; long expectedValue = seconds + ((minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_SECOND;
assertEquals(expectedValue, testresult); assertEquals(expectedValue, testresult);
testresult = DateUtils.getFragmentInSeconds(aDate, Calendar.DAY_OF_YEAR); testresult = DateUtils.getFragmentInSeconds(aDate, Calendar.DAY_OF_YEAR);
assertEquals(expectedValue, testresult); assertEquals(expectedValue, testresult);
} }
public void testSecondsOfDayWithCalendar() { public void testSecondsOfDayWithCalendar() {
long testresult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.DATE); long testresult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.DATE);
long expectedValue = seconds + ((minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_SECOND; long expectedValue = seconds + ((minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_SECOND;
assertEquals(expectedValue, testresult); assertEquals(expectedValue, testresult);
testresult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.DAY_OF_YEAR); testresult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.DAY_OF_YEAR);
assertEquals(expectedValue, testresult); assertEquals(expectedValue, testresult);
} }
public void testMinutesOfDayWithDate() { public void testMinutesOfDayWithDate() {
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.DATE); long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.DATE);
long expectedValue = minutes + ((hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_MINUTE; long expectedValue = minutes + ((hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_MINUTE;
assertEquals(expectedValue,testResult); assertEquals(expectedValue,testResult);
testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.DAY_OF_YEAR); testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.DAY_OF_YEAR);
assertEquals(expectedValue,testResult); assertEquals(expectedValue,testResult);
} }
public void testMinutesOfDayWithCalendar() { public void testMinutesOfDayWithCalendar() {
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.DATE); long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.DATE);
long expectedValue = minutes + ((hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_MINUTE; long expectedValue = minutes + ((hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_MINUTE;
assertEquals(expectedValue, testResult); assertEquals(expectedValue, testResult);
testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.DAY_OF_YEAR); testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.DAY_OF_YEAR);
assertEquals(expectedValue, testResult); assertEquals(expectedValue, testResult);
} }
public void testHoursOfDayWithDate() { public void testHoursOfDayWithDate() {
long testResult = DateUtils.getFragmentInHours(aDate, Calendar.DATE); long testResult = DateUtils.getFragmentInHours(aDate, Calendar.DATE);
long expectedValue = hours; long expectedValue = hours;
assertEquals(expectedValue,testResult); assertEquals(expectedValue,testResult);
testResult = DateUtils.getFragmentInHours(aDate, Calendar.DAY_OF_YEAR); testResult = DateUtils.getFragmentInHours(aDate, Calendar.DAY_OF_YEAR);
assertEquals(expectedValue,testResult); assertEquals(expectedValue,testResult);
} }
public void testHoursOfDayWithCalendar() { public void testHoursOfDayWithCalendar() {
long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.DATE); long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.DATE);
long expectedValue = hours; long expectedValue = hours;
assertEquals(expectedValue, testResult); assertEquals(expectedValue, testResult);
testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.DAY_OF_YEAR); testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.DAY_OF_YEAR);
assertEquals(expectedValue, testResult); assertEquals(expectedValue, testResult);
} }
//Calendar.MONTH as useful fragment //Calendar.MONTH as useful fragment
public void testMillisecondsOfMonthWithDate() { public void testMillisecondsOfMonthWithDate() {
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.MONTH); long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.MONTH);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
+ (hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY), + (hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY),
testResult); testResult);
} }
public void testMillisecondsOfMonthWithCalendar() { public void testMillisecondsOfMonthWithCalendar() {
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MONTH); long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MONTH);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
+ (hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY), + (hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY),
testResult); testResult);
} }
public void testSecondsOfMonthWithDate() { public void testSecondsOfMonthWithDate() {
long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.MONTH); long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.MONTH);
assertEquals( assertEquals(
seconds seconds
+ ((minutes * DateUtils.MILLIS_PER_MINUTE) + ((minutes * DateUtils.MILLIS_PER_MINUTE)
+ (hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY)) + (hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_SECOND, / DateUtils.MILLIS_PER_SECOND,
testResult); testResult);
} }
public void testSecondsOfMonthWithCalendar() { public void testSecondsOfMonthWithCalendar() {
long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.MONTH); long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.MONTH);
assertEquals( assertEquals(
seconds seconds
+ ((minutes * DateUtils.MILLIS_PER_MINUTE) + ((minutes * DateUtils.MILLIS_PER_MINUTE)
+ (hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY)) + (hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_SECOND, / DateUtils.MILLIS_PER_SECOND,
testResult); testResult);
} }
public void testMinutesOfMonthWithDate() { public void testMinutesOfMonthWithDate() {
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.MONTH); long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.MONTH);
assertEquals(minutes assertEquals(minutes
+ ((hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY)) + ((hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_MINUTE, / DateUtils.MILLIS_PER_MINUTE,
testResult); testResult);
} }
public void testMinutesOfMonthWithCalendar() { public void testMinutesOfMonthWithCalendar() {
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.MONTH); long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.MONTH);
assertEquals( minutes +((hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY)) assertEquals( minutes +((hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_MINUTE, / DateUtils.MILLIS_PER_MINUTE,
testResult); testResult);
} }
public void testHoursOfMonthWithDate() { public void testHoursOfMonthWithDate() {
long testResult = DateUtils.getFragmentInHours(aDate, Calendar.MONTH); long testResult = DateUtils.getFragmentInHours(aDate, Calendar.MONTH);
assertEquals(hours + ((days * DateUtils.MILLIS_PER_DAY)) assertEquals(hours + ((days * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_HOUR, / DateUtils.MILLIS_PER_HOUR,
testResult); testResult);
} }
public void testHoursOfMonthWithCalendar() { public void testHoursOfMonthWithCalendar() {
long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.MONTH); long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.MONTH);
assertEquals( hours +((days * DateUtils.MILLIS_PER_DAY)) assertEquals( hours +((days * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_HOUR, / DateUtils.MILLIS_PER_HOUR,
testResult); testResult);
} }
//Calendar.YEAR as useful fragment //Calendar.YEAR as useful fragment
public void testMillisecondsOfYearWithDate() { public void testMillisecondsOfYearWithDate() {
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.YEAR); long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.YEAR);
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.setTime(aDate); cal.setTime(aDate);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
+ (hours * DateUtils.MILLIS_PER_HOUR) + (cal.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY), + (hours * DateUtils.MILLIS_PER_HOUR) + (cal.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY),
testResult); testResult);
} }
public void testMillisecondsOfYearWithCalendar() { public void testMillisecondsOfYearWithCalendar() {
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.YEAR); long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.YEAR);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
+ (hours * DateUtils.MILLIS_PER_HOUR) + (aCalendar.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY), + (hours * DateUtils.MILLIS_PER_HOUR) + (aCalendar.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY),
testResult); testResult);
} }
public void testSecondsOfYearWithDate() { public void testSecondsOfYearWithDate() {
long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.YEAR); long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.YEAR);
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.setTime(aDate); cal.setTime(aDate);
assertEquals( assertEquals(
seconds seconds
+ ((minutes * DateUtils.MILLIS_PER_MINUTE) + ((minutes * DateUtils.MILLIS_PER_MINUTE)
+ (hours * DateUtils.MILLIS_PER_HOUR) + (cal.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY)) + (hours * DateUtils.MILLIS_PER_HOUR) + (cal.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_SECOND, / DateUtils.MILLIS_PER_SECOND,
testResult); testResult);
} }
public void testSecondsOfYearWithCalendar() { public void testSecondsOfYearWithCalendar() {
long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.YEAR); long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.YEAR);
assertEquals( assertEquals(
seconds seconds
+ ((minutes * DateUtils.MILLIS_PER_MINUTE) + ((minutes * DateUtils.MILLIS_PER_MINUTE)
+ (hours * DateUtils.MILLIS_PER_HOUR) + (aCalendar.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY)) + (hours * DateUtils.MILLIS_PER_HOUR) + (aCalendar.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_SECOND, / DateUtils.MILLIS_PER_SECOND,
testResult); testResult);
} }
public void testMinutesOfYearWithDate() { public void testMinutesOfYearWithDate() {
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.YEAR); long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.YEAR);
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.setTime(aDate); cal.setTime(aDate);
assertEquals(minutes assertEquals(minutes
+ ((hours * DateUtils.MILLIS_PER_HOUR) + (cal.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY)) + ((hours * DateUtils.MILLIS_PER_HOUR) + (cal.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_MINUTE, / DateUtils.MILLIS_PER_MINUTE,
testResult); testResult);
} }
public void testMinutesOfYearWithCalendar() { public void testMinutesOfYearWithCalendar() {
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.YEAR); long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.YEAR);
assertEquals( minutes +((hours * DateUtils.MILLIS_PER_HOUR) + (aCalendar.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY)) assertEquals( minutes +((hours * DateUtils.MILLIS_PER_HOUR) + (aCalendar.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_MINUTE, / DateUtils.MILLIS_PER_MINUTE,
testResult); testResult);
} }
public void testHoursOfYearWithDate() { public void testHoursOfYearWithDate() {
long testResult = DateUtils.getFragmentInHours(aDate, Calendar.YEAR); long testResult = DateUtils.getFragmentInHours(aDate, Calendar.YEAR);
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.setTime(aDate); cal.setTime(aDate);
assertEquals(hours + ((cal.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY)) assertEquals(hours + ((cal.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_HOUR, / DateUtils.MILLIS_PER_HOUR,
testResult); testResult);
} }
public void testHoursOfYearWithCalendar() { public void testHoursOfYearWithCalendar() {
long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.YEAR); long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.YEAR);
assertEquals( hours +((aCalendar.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY)) assertEquals( hours +((aCalendar.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_HOUR, / DateUtils.MILLIS_PER_HOUR,
testResult); testResult);
} }
} }

View File

@ -439,150 +439,150 @@ public class DateUtilsTest extends TestCase {
assertDate(result, 2000, 6, 5, 4, 3, 2, 0); assertDate(result, 2000, 6, 5, 4, 3, 2, 0);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
public void testSetYears() throws Exception { public void testSetYears() throws Exception {
Date base = new Date(MILLIS_TEST); Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setYears(base, 2000); Date result = DateUtils.setYears(base, 2000);
assertNotSame(base, result); assertNotSame(base, result);
assertDate(base, 2000, 6, 5, 4, 3, 2, 1); assertDate(base, 2000, 6, 5, 4, 3, 2, 1);
assertDate(result, 2000, 6, 5, 4, 3, 2, 1); assertDate(result, 2000, 6, 5, 4, 3, 2, 1);
result = DateUtils.setYears(base, 2008); result = DateUtils.setYears(base, 2008);
assertNotSame(base, result); assertNotSame(base, result);
assertDate(base, 2000, 6, 5, 4, 3, 2, 1); assertDate(base, 2000, 6, 5, 4, 3, 2, 1);
assertDate(result, 2008, 6, 5, 4, 3, 2, 1); assertDate(result, 2008, 6, 5, 4, 3, 2, 1);
result = DateUtils.setYears(base, 2005); result = DateUtils.setYears(base, 2005);
assertNotSame(base, result); assertNotSame(base, result);
assertDate(base, 2000, 6, 5, 4, 3, 2, 1); assertDate(base, 2000, 6, 5, 4, 3, 2, 1);
assertDate(result, 2005, 6, 5, 4, 3, 2, 1); assertDate(result, 2005, 6, 5, 4, 3, 2, 1);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
public void testSetMonths() throws Exception { public void testSetMonths() throws Exception {
Date base = new Date(MILLIS_TEST); Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setMonths(base, 5); Date result = DateUtils.setMonths(base, 5);
assertNotSame(base, result); assertNotSame(base, result);
assertDate(base, 2000, 6, 5, 4, 3, 2, 1); assertDate(base, 2000, 6, 5, 4, 3, 2, 1);
assertDate(result, 2000, 5, 5, 4, 3, 2, 1); assertDate(result, 2000, 5, 5, 4, 3, 2, 1);
result = DateUtils.setMonths(base, 1); result = DateUtils.setMonths(base, 1);
assertNotSame(base, result); assertNotSame(base, result);
assertDate(base, 2000, 6, 5, 4, 3, 2, 1); assertDate(base, 2000, 6, 5, 4, 3, 2, 1);
assertDate(result, 2000, 1, 5, 4, 3, 2, 1); assertDate(result, 2000, 1, 5, 4, 3, 2, 1);
try { try {
result = DateUtils.setMonths(base, 12); result = DateUtils.setMonths(base, 12);
fail("DateUtils.setMonths did not throw an expected IllegalArguementException."); fail("DateUtils.setMonths did not throw an expected IllegalArguementException.");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
} }
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
public void testSetDays() throws Exception { public void testSetDays() throws Exception {
Date base = new Date(MILLIS_TEST); Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setDays(base, 1); Date result = DateUtils.setDays(base, 1);
assertNotSame(base, result); assertNotSame(base, result);
assertDate(base, 2000, 6, 5, 4, 3, 2, 1); assertDate(base, 2000, 6, 5, 4, 3, 2, 1);
assertDate(result, 2000, 6, 1, 4, 3, 2, 1); assertDate(result, 2000, 6, 1, 4, 3, 2, 1);
result = DateUtils.setDays(base, 29); result = DateUtils.setDays(base, 29);
assertNotSame(base, result); assertNotSame(base, result);
assertDate(base, 2000, 6, 5, 4, 3, 2, 1); assertDate(base, 2000, 6, 5, 4, 3, 2, 1);
assertDate(result, 2000, 6, 29, 4, 3, 2, 1); assertDate(result, 2000, 6, 29, 4, 3, 2, 1);
try { try {
result = DateUtils.setDays(base, 32); result = DateUtils.setDays(base, 32);
fail("DateUtils.setDays did not throw an expected IllegalArguementException."); fail("DateUtils.setDays did not throw an expected IllegalArguementException.");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
} }
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
public void testSetHours() throws Exception { public void testSetHours() throws Exception {
Date base = new Date(MILLIS_TEST); Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setHours(base, 0); Date result = DateUtils.setHours(base, 0);
assertNotSame(base, result); assertNotSame(base, result);
assertDate(base, 2000, 6, 5, 4, 3, 2, 1); assertDate(base, 2000, 6, 5, 4, 3, 2, 1);
assertDate(result, 2000, 6, 5, 0, 3, 2, 1); assertDate(result, 2000, 6, 5, 0, 3, 2, 1);
result = DateUtils.setHours(base, 23); result = DateUtils.setHours(base, 23);
assertNotSame(base, result); assertNotSame(base, result);
assertDate(base, 2000, 6, 5, 4, 3, 2, 1); assertDate(base, 2000, 6, 5, 4, 3, 2, 1);
assertDate(result, 2000, 6, 5, 23, 3, 2, 1); assertDate(result, 2000, 6, 5, 23, 3, 2, 1);
try { try {
result = DateUtils.setHours(base, 24); result = DateUtils.setHours(base, 24);
fail("DateUtils.setHours did not throw an expected IllegalArguementException."); fail("DateUtils.setHours did not throw an expected IllegalArguementException.");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
} }
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
public void testSetMinutes() throws Exception { public void testSetMinutes() throws Exception {
Date base = new Date(MILLIS_TEST); Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setMinutes(base, 0); Date result = DateUtils.setMinutes(base, 0);
assertNotSame(base, result); assertNotSame(base, result);
assertDate(base, 2000, 6, 5, 4, 3, 2, 1); assertDate(base, 2000, 6, 5, 4, 3, 2, 1);
assertDate(result, 2000, 6, 5, 4, 0, 2, 1); assertDate(result, 2000, 6, 5, 4, 0, 2, 1);
result = DateUtils.setMinutes(base, 59); result = DateUtils.setMinutes(base, 59);
assertNotSame(base, result); assertNotSame(base, result);
assertDate(base, 2000, 6, 5, 4, 3, 2, 1); assertDate(base, 2000, 6, 5, 4, 3, 2, 1);
assertDate(result, 2000, 6, 5, 4, 59, 2, 1); assertDate(result, 2000, 6, 5, 4, 59, 2, 1);
try { try {
result = DateUtils.setMinutes(base, 60); result = DateUtils.setMinutes(base, 60);
fail("DateUtils.setMinutes did not throw an expected IllegalArguementException."); fail("DateUtils.setMinutes did not throw an expected IllegalArguementException.");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
} }
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
public void testSetSeconds() throws Exception { public void testSetSeconds() throws Exception {
Date base = new Date(MILLIS_TEST); Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setSeconds(base, 0); Date result = DateUtils.setSeconds(base, 0);
assertNotSame(base, result); assertNotSame(base, result);
assertDate(base, 2000, 6, 5, 4, 3, 2, 1); assertDate(base, 2000, 6, 5, 4, 3, 2, 1);
assertDate(result, 2000, 6, 5, 4, 3, 0, 1); assertDate(result, 2000, 6, 5, 4, 3, 0, 1);
result = DateUtils.setSeconds(base, 59); result = DateUtils.setSeconds(base, 59);
assertNotSame(base, result); assertNotSame(base, result);
assertDate(base, 2000, 6, 5, 4, 3, 2, 1); assertDate(base, 2000, 6, 5, 4, 3, 2, 1);
assertDate(result, 2000, 6, 5, 4, 3, 59, 1); assertDate(result, 2000, 6, 5, 4, 3, 59, 1);
try { try {
result = DateUtils.setSeconds(base, 60); result = DateUtils.setSeconds(base, 60);
fail("DateUtils.setSeconds did not throw an expected IllegalArguementException."); fail("DateUtils.setSeconds did not throw an expected IllegalArguementException.");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
} }
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
public void testSetMilliseconds() throws Exception { public void testSetMilliseconds() throws Exception {
Date base = new Date(MILLIS_TEST); Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setMilliseconds(base, 0); Date result = DateUtils.setMilliseconds(base, 0);
assertNotSame(base, result); assertNotSame(base, result);
assertDate(base, 2000, 6, 5, 4, 3, 2, 1); assertDate(base, 2000, 6, 5, 4, 3, 2, 1);
assertDate(result, 2000, 6, 5, 4, 3, 2, 0); assertDate(result, 2000, 6, 5, 4, 3, 2, 0);
result = DateUtils.setMilliseconds(base, 999); result = DateUtils.setMilliseconds(base, 999);
assertNotSame(base, result); assertNotSame(base, result);
assertDate(base, 2000, 6, 5, 4, 3, 2, 1); assertDate(base, 2000, 6, 5, 4, 3, 2, 1);
assertDate(result, 2000, 6, 5, 4, 3, 2, 999); assertDate(result, 2000, 6, 5, 4, 3, 2, 999);
try { try {
result = DateUtils.setMilliseconds(base, 1000); result = DateUtils.setMilliseconds(base, 1000);
fail("DateUtils.setMilliseconds did not throw an expected IllegalArguementException."); fail("DateUtils.setMilliseconds did not throw an expected IllegalArguementException.");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
} }
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
private void assertDate(Date date, int year, int month, int day, int hour, int min, int sec, int mil) throws Exception { private void assertDate(Date date, int year, int month, int day, int hour, int min, int sec, int mil) throws Exception {