LANG-951: Fragments are wrong by 1 day when using fragment YEAR or MONTH - fix test that failed because of wrong assertions

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1559787 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benedikt Ritter 2014-01-20 17:33:09 +00:00
parent b3c1a78dab
commit b5a9cd944c
1 changed files with 16 additions and 16 deletions

View File

@ -402,7 +402,7 @@ public class DateUtilsFragmentTest {
public void testMillisecondsOfMonthWithDate() { public void testMillisecondsOfMonthWithDate() {
final long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.MONTH); final 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 - 1) * DateUtils.MILLIS_PER_DAY),
testResult); testResult);
} }
@ -410,7 +410,7 @@ public class DateUtilsFragmentTest {
public void testMillisecondsOfMonthWithCalendar() { public void testMillisecondsOfMonthWithCalendar() {
final long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MONTH); final 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 - 1) * DateUtils.MILLIS_PER_DAY),
testResult); testResult);
} }
@ -420,7 +420,7 @@ testResult);
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 - 1) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_SECOND, / DateUtils.MILLIS_PER_SECOND,
testResult); testResult);
} }
@ -431,7 +431,7 @@ testResult);
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 - 1) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_SECOND, / DateUtils.MILLIS_PER_SECOND,
testResult); testResult);
} }
@ -440,7 +440,7 @@ testResult);
public void testMinutesOfMonthWithDate() { public void testMinutesOfMonthWithDate() {
final long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.MONTH); final 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 - 1) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_MINUTE, / DateUtils.MILLIS_PER_MINUTE,
testResult); testResult);
} }
@ -448,7 +448,7 @@ testResult);
@Test @Test
public void testMinutesOfMonthWithCalendar() { public void testMinutesOfMonthWithCalendar() {
final long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.MONTH); final 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 - 1) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_MINUTE, / DateUtils.MILLIS_PER_MINUTE,
testResult); testResult);
} }
@ -456,7 +456,7 @@ testResult);
@Test @Test
public void testHoursOfMonthWithDate() { public void testHoursOfMonthWithDate() {
final long testResult = DateUtils.getFragmentInHours(aDate, Calendar.MONTH); final long testResult = DateUtils.getFragmentInHours(aDate, Calendar.MONTH);
assertEquals(hours + ((days * DateUtils.MILLIS_PER_DAY)) assertEquals(hours + (((days - 1) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_HOUR, / DateUtils.MILLIS_PER_HOUR,
testResult); testResult);
} }
@ -464,7 +464,7 @@ testResult);
@Test @Test
public void testHoursOfMonthWithCalendar() { public void testHoursOfMonthWithCalendar() {
final long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.MONTH); final long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.MONTH);
assertEquals( hours +((days * DateUtils.MILLIS_PER_DAY)) assertEquals( hours +(((days - 1) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_HOUR, / DateUtils.MILLIS_PER_HOUR,
testResult); testResult);
} }
@ -476,7 +476,7 @@ testResult);
final Calendar cal = Calendar.getInstance(); final 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) - 1)* DateUtils.MILLIS_PER_DAY),
testResult); testResult);
} }
@ -484,7 +484,7 @@ testResult);
public void testMillisecondsOfYearWithCalendar() { public void testMillisecondsOfYearWithCalendar() {
final long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.YEAR); final 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) - 1) * DateUtils.MILLIS_PER_DAY),
testResult); testResult);
} }
@ -496,7 +496,7 @@ testResult);
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) - 1) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_SECOND, / DateUtils.MILLIS_PER_SECOND,
testResult); testResult);
} }
@ -507,7 +507,7 @@ testResult);
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) - 1) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_SECOND, / DateUtils.MILLIS_PER_SECOND,
testResult); testResult);
} }
@ -518,7 +518,7 @@ testResult);
final Calendar cal = Calendar.getInstance(); final 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) - 1) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_MINUTE, / DateUtils.MILLIS_PER_MINUTE,
testResult); testResult);
} }
@ -526,7 +526,7 @@ testResult);
@Test @Test
public void testMinutesOfYearWithCalendar() { public void testMinutesOfYearWithCalendar() {
final long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.YEAR); final 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) - 1) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_MINUTE, / DateUtils.MILLIS_PER_MINUTE,
testResult); testResult);
} }
@ -549,7 +549,7 @@ testResult);
final long testResult = DateUtils.getFragmentInHours(aDate, Calendar.YEAR); final long testResult = DateUtils.getFragmentInHours(aDate, Calendar.YEAR);
final Calendar cal = Calendar.getInstance(); final 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) - 1) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_HOUR, / DateUtils.MILLIS_PER_HOUR,
testResult); testResult);
} }
@ -557,7 +557,7 @@ testResult);
@Test @Test
public void testHoursOfYearWithCalendar() { public void testHoursOfYearWithCalendar() {
final long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.YEAR); final 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) - 1) * DateUtils.MILLIS_PER_DAY))
/ DateUtils.MILLIS_PER_HOUR, / DateUtils.MILLIS_PER_HOUR,
testResult); testResult);
} }