@Test(dataProvider = "next") public void test_next(RollConvention conv, LocalDate input, Frequency freq, LocalDate expected) { assertEquals(conv.next(input, freq), expected); }
/** * Resolves the sequence to a list of steps. * * @param existingSteps the existing list of steps * @param rollConv the roll convention * @return the steps */ List<ValueStep> resolve(List<ValueStep> existingSteps, RollConvention rollConv) { ImmutableList.Builder<ValueStep> steps = ImmutableList.builder(); steps.addAll(existingSteps); LocalDate prev = firstStepDate; LocalDate date = firstStepDate; while (!date.isAfter(lastStepDate)) { steps.add(ValueStep.of(date, adjustment)); prev = date; date = rollConv.next(date, frequency); } if (!prev.equals(lastStepDate)) { throw new IllegalArgumentException(Messages.format( "ValueStepSequence lastStepDate did not match frequency '{}' using roll convention '{}', {} != {}", frequency, rollConv, lastStepDate, prev)); } return steps.build(); }
public void test_ofDayOfMonth_next_oneMonth() { for (int start = 1; start <= 5; start++) { for (int i = 1; i <= 30; i++) { RollConvention test = RollConvention.ofDayOfMonth(i); LocalDate expected = date(2014, AUGUST, i); assertEquals(test.next(date(2014, JULY, start), P1M), expected); } } }
/** * Checks if this period is regular according to the specified frequency and roll convention. * <p> * A schedule period is normally created from a frequency and roll convention. * These can therefore be used to determine if the period is regular, which simply * means that the period end date can be generated from the start date and vice versa. * * @param frequency the frequency * @param rollConvention the roll convention * @return true if the period is regular */ public boolean isRegular(Frequency frequency, RollConvention rollConvention) { ArgChecker.notNull(frequency, "frequency"); ArgChecker.notNull(rollConvention, "rollConvention"); return rollConvention.next(unadjustedStartDate, frequency).equals(unadjustedEndDate) && rollConvention.previous(unadjustedEndDate, frequency).equals(unadjustedStartDate); }
public void test_ofDayOfMonth_next_oneDay() { for (int start = 1; start <= 5; start++) { for (int i = 1; i <= 30; i++) { RollConvention test = RollConvention.ofDayOfMonth(i); LocalDate expected = date(2014, JULY, i); if (i <= start) { expected = expected.plusMonths(1); } assertEquals(test.next(date(2014, JULY, start), P1D), expected); } } }
public void test_ofDayOfWeek_next_oneDay() { for (DayOfWeek dow : DayOfWeek.values()) { RollConvention test = RollConvention.ofDayOfWeek(dow); assertEquals( test.next(date(2014, AUGUST, 14), P1D), date(2014, AUGUST, 15).with(TemporalAdjusters.nextOrSame(dow))); } }
public void test_ofDayOfWeek_next_oneMonth() { for (DayOfWeek dow : DayOfWeek.values()) { RollConvention test = RollConvention.ofDayOfWeek(dow); assertEquals( test.next(date(2014, AUGUST, 14), P1W), date(2014, AUGUST, 21).with(TemporalAdjusters.nextOrSame(dow))); } }
@Test(dataProvider = "types") public void test_null(RollConvention type) { assertThrowsIllegalArg(() -> type.adjust(null)); assertThrowsIllegalArg(() -> type.matches(null)); assertThrowsIllegalArg(() -> type.next(date(2014, JULY, 1), null)); assertThrowsIllegalArg(() -> type.next(null, P3M)); assertThrowsIllegalArg(() -> type.previous(date(2014, JULY, 1), null)); assertThrowsIllegalArg(() -> type.previous(null, P3M)); }