Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed May 20, 2020
1 parent 62ab7a6 commit 1031263
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 87 deletions.
Expand Up @@ -17,16 +17,17 @@ class VEventRecurrenceParametrizedTest extends GroovyTestCase {
String exDates
PeriodList expected

VEventRecurrenceParametrizedTest(start, startParam, end, endParam, rule, period, exDates, expected) {
VEventRecurrenceParametrizedTest(start, startParam, end, endParam, rule,
period, exDates, expectedString, CalendarDateFormat periodFormat) {
this.start = start
this.startParam = startParam
this.end = end
this.endParam = endParam
this.rule = rule
this.period = Period.parse(period)
this.exDates = exDates
this.expected = new PeriodList()
expected.each { this.expected.add(Period.parse(it)) }
this.expected = new PeriodList(periodFormat)
expectedString.each { this.expected.add(Period.parse(it)) }
}

@Parameterized.Parameters
Expand All @@ -38,51 +39,53 @@ class VEventRecurrenceParametrizedTest extends GroovyTestCase {
'20101101/20110101',
null,
['20101113/P1D', '20101129/P1D', '20101130/P1D', '20101204/P1D',
'20101220/P1D', '20101221/P1D', '20101225/P1D']],
'20101220/P1D', '20101221/P1D', '20101225/P1D'], CalendarDateFormat.DATE_FORMAT],

['20101112', 'DATE',
'20101113', 'DATE',
'FREQ=WEEKLY;WKST=MO;INTERVAL=3;BYDAY=MO,TU,SA',
'20101101/20110101',
null,
['20101113/P1D', '20101129/P1D', '20101130/P1D', '20101204/P1D',
'20101220/P1D', '20101221/P1D', '20101225/P1D']],
'20101220/P1D', '20101221/P1D', '20101225/P1D'], CalendarDateFormat.DATE_FORMAT],

['20170717', 'DATE',
'20170718', 'DATE',
'FREQ=YEARLY;COUNT=3;INTERVAL=2;BYMONTH=5;BYMONTHDAY=22,23,24,25,26,27,28;BYDAY=MO',
'20170717/20270717',
'20101129,20101221',
['20190527/P1D', '20210524/P1D',
'20230522/P1D']],
'20230522/P1D'], CalendarDateFormat.DATE_FORMAT],

['20100831T061500Z', 'DATETIME',
'20100831T064500Z', 'DATETIME',
'FREQ=MONTHLY;UNTIL=20110101',
'20100831T000000Z/20110131T000000Z',
null,
['20100831T061500Z/PT30M', '20101031T061500Z/PT30M', '20101231T061500Z/PT30M']],
['20100831T061500Z/PT30M', '20101031T061500Z/PT30M', '20101231T061500Z/PT30M'],
CalendarDateFormat.UTC_DATE_TIME_FORMAT],

['20100831T061500Z', 'DATETIME',
'20100831T064500Z', 'DATETIME',
'FREQ=MONTHLY;UNTIL=20110101',
'20100831T000000Z/20110131T000000Z',
'20101031T061500Z',
['20100831T061500Z/PT30M', '20101231T061500Z/PT30M']],
['20100831T061500Z/PT30M', '20101231T061500Z/PT30M'], CalendarDateFormat.UTC_DATE_TIME_FORMAT],

['20100831T061500Z', 'DATETIME',
'20100831T064500Z', 'DATETIME',
'FREQ=MONTHLY;UNTIL=20110101;BYMONTHDAY=31',
'20100831T000000Z/20110131T000000Z',
null,
['20100831T061500Z/PT30M', '20101031T061500Z/PT30M', '20101231T061500Z/PT30M']],
['20100831T061500Z/PT30M', '20101031T061500Z/PT30M', '20101231T061500Z/PT30M'],
CalendarDateFormat.UTC_DATE_TIME_FORMAT],

['20100831T061500Z', 'DATETIME',
'20100831T064500Z', 'DATETIME',
'FREQ=MONTHLY;UNTIL=20110101;BYMONTHDAY=31',
'20100831T000000Z/20110131T000000Z',
'20100831T061500Z',
['20101031T061500Z/PT30M', '20101231T061500Z/PT30M']]
['20101031T061500Z/PT30M', '20101231T061500Z/PT30M'], CalendarDateFormat.UTC_DATE_TIME_FORMAT]

]*.toArray()
}
Expand All @@ -97,8 +100,6 @@ class VEventRecurrenceParametrizedTest extends GroovyTestCase {
}

def actual = event.calculateRecurrenceSet(period)

println actual
assert actual == expected
assert actual == expected.getPeriods()
}
}
7 changes: 4 additions & 3 deletions src/test/java/net/fortuna/ical4j/filter/PeriodRuleTest.java
Expand Up @@ -46,6 +46,7 @@
import java.io.IOException;
import java.time.LocalDate;
import java.time.Month;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collection;
Expand Down Expand Up @@ -142,9 +143,9 @@ public static TestSuite suite() throws FileNotFoundException, IOException, Parse
ComponentList<CalendarComponent> components = new ComponentList<>();
components.add(event);

LocalDate ruleDate = LocalDate.now().withMonth(1).withDayOfMonth(1);
ZonedDateTime ruleDate = LocalDate.now().withMonth(1).withDayOfMonth(1).atStartOfDay().atZone(ZoneId.systemDefault());
while (ruleDate.getMonth() == Month.JANUARY) {
PeriodRule<CalendarComponent, LocalDate> rule = new PeriodRule<>(new Period<>(ruleDate, java.time.Period.ofDays(1),
PeriodRule<CalendarComponent, ZonedDateTime> rule = new PeriodRule<>(new Period<>(ruleDate, java.time.Period.ofDays(1),
CalendarDateFormat.DATE_FORMAT));
filter = new Filter<>(rule);
if (ruleDate.getDayOfMonth() == 25) {
Expand All @@ -164,7 +165,7 @@ public static TestSuite suite() throws FileNotFoundException, IOException, Parse
suite.addTest(new PeriodRuleTest("testFilteredIsEmpty", filter, exCal.getComponents()));

// Test exclusion of particular date patterns..
exCal = Calendars.load(PeriodRuleTest.class.getResource("/samples/valid/friday13-NOT.ics"));
exCal = Calendars.load(PeriodRuleTest.class.getResource("/samples/invalid/friday13-NOT.ics"));
period = new Period<>(startDt, java.time.Period.ofWeeks(52));
filter = new Filter<>(new PeriodRule<>(period));
suite.addTest(new PeriodRuleTest("testFilteredIsNotEmpty", filter, exCal.getComponents()));
Expand Down

0 comments on commit 1031263

Please sign in to comment.