Fix a bug in rec. trx. handling of HWT NW and occurrence at sunday
This commit is contained in:
@@ -265,6 +265,18 @@ public class RecurringTransactionService {
|
||||
return false; // early return
|
||||
}
|
||||
|
||||
// If today is a weekend day or holiday the recurring transaction cannot be due today, because the
|
||||
// holiday weekend type says PREVIOUS_WORKDAY.
|
||||
if (this.ruleService.isHoliday(now) || this.ruleService.isWeekend(now)) {
|
||||
LOGGER.debug(String.format("Recurring transaction %s has HWT %s and today is either a holiday or weekend," +
|
||||
" thus it cannot be due in the future",
|
||||
ReflectionToStringBuilder.toString(recurringTransaction),
|
||||
recurringTransaction.getHolidayWeekendType()));
|
||||
|
||||
return false; // early return
|
||||
}
|
||||
|
||||
|
||||
boolean weekend;
|
||||
boolean holiday;
|
||||
LocalDate tomorrow = now;
|
||||
|
||||
@@ -46,7 +46,7 @@ public class RecurringTransactionService_getAllDueToday_MONTHLY_PREVIOUS_WORKDAY
|
||||
.findByDeletedFalseAndLastOccurrenceIsNullOrLastOccurrenceGreaterThanEqual(Mockito.any()))
|
||||
.thenReturn(Collections.singletonList(createRecurringTransaction(1)));
|
||||
// Today is not a holiday but tomorrow is
|
||||
Mockito.when(this.ruleService.isHoliday(Mockito.any())).thenReturn(Boolean.FALSE, Boolean.TRUE);
|
||||
Mockito.when(this.ruleService.isHoliday(Mockito.any())).thenReturn(Boolean.FALSE, Boolean.FALSE, Boolean.TRUE);
|
||||
final LocalDate now = LocalDate.now();
|
||||
|
||||
// Act
|
||||
@@ -84,6 +84,36 @@ public class RecurringTransactionService_getAllDueToday_MONTHLY_PREVIOUS_WORKDAY
|
||||
Assert.assertEquals(0, IterableUtils.size(recurringDueToday));
|
||||
}
|
||||
|
||||
/**
|
||||
* Negative test case for the following: recurringTransaction firstOccurrence = sunday the 15th,
|
||||
* intervalType = monthly and holidayWeekendType = previous_workday => should not be due today if today is the 14th,
|
||||
* as it was actually due at the 13th.
|
||||
*/
|
||||
@Test
|
||||
public void test_getAllDueToday_PreviousWorkday_weekend_notDue2() {
|
||||
// Arrange
|
||||
final LocalDate now = LocalDate.of(2019, 9, 14); // A Friday
|
||||
final RecurringTransaction recurringTransaction = new RecurringTransaction();
|
||||
|
||||
recurringTransaction.setFirstOccurrence(LocalDate.of(2019, 8, 15));
|
||||
recurringTransaction.setHolidayWeekendType(HolidayWeekendType.PREVIOUS_WORKDAY);
|
||||
recurringTransaction.setIntervalType(IntervalType.MONTHLY);
|
||||
|
||||
Mockito.when(this.recurringTransactionRepository
|
||||
.findByDeletedFalseAndLastOccurrenceIsNullOrLastOccurrenceGreaterThanEqual(Mockito.any()))
|
||||
.thenReturn(Collections.singletonList(recurringTransaction));
|
||||
Mockito.when(this.ruleService.isWeekend(Mockito.any()))
|
||||
.thenReturn(Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE);
|
||||
Mockito.when(this.ruleService.isHoliday(Mockito.any()))
|
||||
.thenReturn(Boolean.FALSE);
|
||||
|
||||
// Act
|
||||
final Iterable<RecurringTransaction> recurringDueToday = this.classUnderTest.getAllDueToday(now);
|
||||
|
||||
// Assert
|
||||
Assert.assertEquals(0, IterableUtils.size(recurringDueToday));
|
||||
}
|
||||
|
||||
private RecurringTransaction createRecurringTransaction(int days) {
|
||||
final RecurringTransaction recurringTransaction = new RecurringTransaction();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user