Skip to content

Commit

Permalink
Test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Jun 14, 2020
1 parent 1108207 commit 238a25f
Show file tree
Hide file tree
Showing 19 changed files with 123 additions and 145 deletions.
Expand Up @@ -42,7 +42,7 @@ class VEventUserAgentTest extends Specification {
def calendar = userAgent.publish(vevent, vevent2)

then: 'the calendar object contains method = PUBLISH'
calendar.getProperty(Property.METHOD).get() == Method.PUBLISH
calendar.getRequiredProperty(Property.METHOD) == Method.PUBLISH

and: 'the sequence property is present on all components'
calendar.components.each { it.getProperty(Property.SEQUENCE).isPresent() }
Expand Down Expand Up @@ -74,7 +74,7 @@ class VEventUserAgentTest extends Specification {
def calendar = userAgent.request(vevent, vevent2)

then: 'the calendar object contains method = REQUEST'
calendar.getProperty(Property.METHOD).get() == Method.REQUEST
calendar.getRequiredProperty(Property.METHOD) == Method.REQUEST

and: 'the sequence property is present on all components'
calendar.components.each { it.getProperty(Property.SEQUENCE).isPresent() }
Expand All @@ -100,7 +100,7 @@ class VEventUserAgentTest extends Specification {
def calendar = userAgent.delegate(request)

then: 'the calendar object contains method = REQUEST'
calendar.getProperty(Property.METHOD).get() == Method.REQUEST
calendar.getRequiredProperty(Property.METHOD) == Method.REQUEST
}

def "Reply"() {
Expand All @@ -123,7 +123,7 @@ class VEventUserAgentTest extends Specification {
def calendar = userAgent.reply(request)

then: 'the calendar object contains method = REPLY'
calendar.getProperty(Property.METHOD).get() == Method.REPLY
calendar.getRequiredProperty(Property.METHOD) == Method.REPLY
}

def "Add"() {
Expand All @@ -140,7 +140,7 @@ class VEventUserAgentTest extends Specification {
def calendar = userAgent.add(vevent)

then: 'the calendar object contains method = ADD'
calendar.getProperty(Property.METHOD).get() == Method.ADD
calendar.getRequiredProperty(Property.METHOD) == Method.ADD
}

def "Cancel"() {
Expand All @@ -156,7 +156,7 @@ class VEventUserAgentTest extends Specification {
def calendar = userAgent.cancel(vevent)

then: 'the calendar object contains method = CANCEL'
calendar.getProperty(Property.METHOD).get() == Method.CANCEL
calendar.getRequiredProperty(Property.METHOD) == Method.CANCEL
}

def "Refresh"() {
Expand All @@ -172,7 +172,7 @@ class VEventUserAgentTest extends Specification {
def calendar = userAgent.refresh(vevent)

then: 'the calendar object contains method = REFRESH'
calendar.getProperty(Property.METHOD).get() == Method.REFRESH
calendar.getRequiredProperty(Property.METHOD) == Method.REFRESH
}

def "Counter"() {
Expand All @@ -195,7 +195,7 @@ class VEventUserAgentTest extends Specification {
def calendar = userAgent.counter(request)

then: 'the calendar object contains method = COUNTER'
calendar.getProperty(Property.METHOD).get() == Method.COUNTER
calendar.getRequiredProperty(Property.METHOD) == Method.COUNTER
}

def "DeclineCounter"() {
Expand All @@ -214,6 +214,6 @@ class VEventUserAgentTest extends Specification {
def calendar = userAgent.declineCounter(counter)

then: 'the calendar object contains method = DECLINECOUNTER'
calendar.getProperty(Property.METHOD).get() == Method.DECLINE_COUNTER
calendar.getRequiredProperty(Property.METHOD) == Method.DECLINE_COUNTER
}
}
Expand Up @@ -52,7 +52,7 @@ class VFreeBusyUserAgentTest extends Specification {
def calendar = userAgent.publish(result)

then: 'the calendar object contains method = PUBLISH'
calendar.getProperty(Property.METHOD).get() == Method.PUBLISH
calendar.getRequiredProperty(Property.METHOD) == Method.PUBLISH

and: 'the sequence property is present on all components'
calendar.components.each { it.getProperty(Property.SEQUENCE).isPresent() }
Expand Down Expand Up @@ -84,7 +84,7 @@ class VFreeBusyUserAgentTest extends Specification {
def calendar = userAgent.request(vfreeBusy, vfreeBusy2)

then: 'the calendar object contains method = REQUEST'
calendar.getProperty(Property.METHOD).get() == Method.REQUEST
calendar.getRequiredProperty(Property.METHOD) == Method.REQUEST

and: 'the sequence property is present on all components'
calendar.components.each { it.getProperty(Property.SEQUENCE).isPresent() }
Expand Down Expand Up @@ -130,7 +130,7 @@ class VFreeBusyUserAgentTest extends Specification {
def calendar = userAgent.reply(request)

then: 'the calendar object contains method = REPLY'
calendar.getProperty(Property.METHOD).get() == Method.REPLY
calendar.getRequiredProperty(Property.METHOD) == Method.REPLY
}

def "Add"() {
Expand Down
Expand Up @@ -41,7 +41,7 @@ class VJournalUserAgentTest extends Specification {
def calendar = userAgent.publish(vjournal, vjournal2)

then: 'the calendar object contains method = PUBLISH'
calendar.getProperty(Property.METHOD).get() == Method.PUBLISH
calendar.getRequiredProperty(Property.METHOD) == Method.PUBLISH

and: 'the sequence property is present on all components'
calendar.components.each { it.getProperty(Property.SEQUENCE).isPresent() }
Expand Down Expand Up @@ -124,7 +124,7 @@ class VJournalUserAgentTest extends Specification {
def calendar = userAgent.add(vjournal)

then: 'the calendar object contains method = ADD'
calendar.getProperty(Property.METHOD).get() == Method.ADD
calendar.getRequiredProperty(Property.METHOD) == Method.ADD
}

def "Cancel"() {
Expand All @@ -140,7 +140,7 @@ class VJournalUserAgentTest extends Specification {
def calendar = userAgent.cancel(vjournal)

then: 'the calendar object contains method = CANCEL'
calendar.getProperty(Property.METHOD).get() == Method.CANCEL
calendar.getRequiredProperty(Property.METHOD) == Method.CANCEL
}

def "Refresh"() {
Expand Down
Expand Up @@ -41,7 +41,7 @@ class VToDoUserAgentTest extends Specification {
def calendar = userAgent.publish(vtodo, vtodo2)

then: 'the calendar object contains method = PUBLISH'
calendar.getProperty(Property.METHOD).get() == Method.PUBLISH
calendar.getRequiredProperty(Property.METHOD) == Method.PUBLISH

and: 'the sequence property is present on all components'
calendar.components.each { it.getProperty(Property.SEQUENCE).isPresent() }
Expand Down Expand Up @@ -75,7 +75,7 @@ class VToDoUserAgentTest extends Specification {
def calendar = userAgent.request(vtodo, vtodo2)

then: 'the calendar object contains method = REQUEST'
calendar.getProperty(Property.METHOD).get() == Method.REQUEST
calendar.getRequiredProperty(Property.METHOD) == Method.REQUEST

and: 'the sequence property is present on all components'
calendar.components.each { it.getProperty(Property.SEQUENCE).isPresent() }
Expand Down Expand Up @@ -103,7 +103,7 @@ class VToDoUserAgentTest extends Specification {
def calendar = userAgent.delegate(request)

then: 'the calendar object contains method = REQUEST'
calendar.getProperty(Property.METHOD).get() == Method.REQUEST
calendar.getRequiredProperty(Property.METHOD) == Method.REQUEST
}

def "Reply"() {
Expand All @@ -126,7 +126,7 @@ class VToDoUserAgentTest extends Specification {
def calendar = userAgent.reply(request)

then: 'the calendar object contains method = REPLY'
calendar.getProperty(Property.METHOD).get() == Method.REPLY
calendar.getRequiredProperty(Property.METHOD) == Method.REPLY
}

def "Add"() {
Expand All @@ -144,7 +144,7 @@ class VToDoUserAgentTest extends Specification {
def calendar = userAgent.add(vtodo)

then: 'the calendar object contains method = ADD'
calendar.getProperty(Property.METHOD).get() == Method.ADD
calendar.getRequiredProperty(Property.METHOD) == Method.ADD
}

def "Cancel"() {
Expand All @@ -160,7 +160,7 @@ class VToDoUserAgentTest extends Specification {
def calendar = userAgent.cancel(vtodo)

then: 'the calendar object contains method = CANCEL'
calendar.getProperty(Property.METHOD).get() == Method.CANCEL
calendar.getRequiredProperty(Property.METHOD) == Method.CANCEL
}

def "Refresh"() {
Expand All @@ -175,7 +175,7 @@ class VToDoUserAgentTest extends Specification {
def calendar = userAgent.refresh(vtodo)

then: 'the calendar object contains method = REFRESH'
calendar.getProperty(Property.METHOD).get() == Method.REFRESH
calendar.getRequiredProperty(Property.METHOD) == Method.REFRESH
}

def "Counter"() {
Expand All @@ -200,7 +200,7 @@ class VToDoUserAgentTest extends Specification {
def calendar = userAgent.counter(request)

then: 'the calendar object contains method = COUNTER'
calendar.getProperty(Property.METHOD).get() == Method.COUNTER
calendar.getRequiredProperty(Property.METHOD) == Method.COUNTER
}

def "DeclineCounter"() {
Expand All @@ -223,6 +223,6 @@ class VToDoUserAgentTest extends Specification {
def calendar = userAgent.declineCounter(counter)

then: 'the calendar object contains method = DECLINECOUNTER'
calendar.getProperty(Property.METHOD).get() == Method.DECLINE_COUNTER
calendar.getRequiredProperty(Property.METHOD) == Method.DECLINE_COUNTER
}
}
Expand Up @@ -33,7 +33,7 @@ class UnfoldingReaderSpec extends Specification {
Calendar parsed = new CalendarBuilder().build(new StringReader(calendarString as String))

then: 'the encoded binary is decoded correctly'
def attach = parsed.components[0].getProperty(Property.ATTACH).get()
def attach = parsed.components[0].getRequiredProperty(Property.ATTACH)
def md5 = MessageDigest.getInstance("MD5")
md5.digest(attach.binary) == md5.digest(new File('gradle/wrapper/gradle-wrapper.jar').bytes)
}
Expand Down
Expand Up @@ -39,7 +39,6 @@

import java.io.StringReader;
import java.net.URISyntaxException;
import java.util.Optional;

/**
* $Id: CalendarBuilderCustomRegistryTest.java [Nov 16, 2009]
Expand Down Expand Up @@ -119,8 +118,8 @@ public Parameter createParameter(final String value) throws URISyntaxException {

Calendar cal = builder.build(new StringReader(VEVENT_WITH_SCHEDULE_STATUS));

Optional<VEvent> event = cal.getComponent(Component.VEVENT);
VEvent eventBis = event.get().copy();
assertEquals(eventBis, event.get());
VEvent event = cal.getRequiredComponent(Component.VEVENT);
VEvent eventBis = event.copy();
assertEquals(eventBis, event);
}
}
Expand Up @@ -100,17 +100,17 @@ public void testVTimeZoneAfterVEvent() throws Exception {
assertTrue("VEVENT not found", comps.size() == 1);
VEvent vevent = (VEvent) comps.get(0);

Optional<DtStart> dtstart = vevent.getProperty(Property.DTSTART);
ZonedDateTime dateTime = (ZonedDateTime) dtstart.get().getDate();
DtStart dtstart = vevent.getRequiredProperty(Property.DTSTART);
ZonedDateTime dateTime = (ZonedDateTime) dtstart.getDate();

assertEquals("date value not correct", "20080624T130000", dtstart.get().getValue());
assertEquals("date value not correct", "20080624T130000", dtstart.getValue());
assertNotNull("timezone not present", dateTime.getZone());
assertEquals("timezone not correct",
"/softwarestudio.org/Tzfile/America/Chicago", builder.getRegistry().getTzId(dateTime.getZone().getId()));

}

public void testTwoDaylights() throws IOException, ParserException {
public void testTwoDaylights() throws IOException, ParserException, ConstraintViolationException {

System.setProperty("net.fortuna.ical4j.timezone.utcDefault", "true");

Expand Down Expand Up @@ -176,32 +176,32 @@ public void testTwoDaylights() throws IOException, ParserException {
assertEquals("2 VEVENTs not found", 2, comps.size());
VEvent vevent0 = (VEvent) comps.get(0);

Optional<DtStart<ZonedDateTime>> dtstart0 = vevent0.getProperty(Property.DTSTART);
Optional<TzId> dtstart0TzId = dtstart0.get().getParameter(Parameter.TZID);
DtStart<ZonedDateTime> dtstart0 = vevent0.getRequiredProperty(Property.DTSTART);
Optional<TzId> dtstart0TzId = dtstart0.getParameter(Parameter.TZID);

assertEquals("date value not correct", "20200503T173000", dtstart0.get().getValue());
assertEquals("date value not correct", "20200503T173000", dtstart0.getValue());
assertTrue("timezone not present", dtstart0TzId.isPresent());
assertEquals("timezone not correct", "Europe/Amsterdam", dtstart0TzId.get().getValue());

Optional<DtEnd<ZonedDateTime>> dtend0 = vevent0.getProperty(Property.DTEND);
Optional<TzId> dtend0TzId = dtend0.get().getParameter(Parameter.TZID);
DtEnd<ZonedDateTime> dtend0 = vevent0.getRequiredProperty(Property.DTEND);
Optional<TzId> dtend0TzId = dtend0.getParameter(Parameter.TZID);

assertEquals("date value not correct", "20200503T200000", dtend0.get().getValue());
assertEquals("date value not correct", "20200503T200000", dtend0.getValue());
assertTrue("timezone not present", dtend0TzId.isPresent());
assertEquals("timezone not correct", "Europe/Amsterdam", dtend0TzId.get().getValue());

VEvent vevent1 = (VEvent) comps.get(1);
Optional<DtStart<ZonedDateTime>> dtstart1 = vevent1.getProperty(Property.DTSTART);
Optional<TzId> dtstart1TzId = dtstart1.get().getParameter(Parameter.TZID);
DtStart<ZonedDateTime> dtstart1 = vevent1.getRequiredProperty(Property.DTSTART);
Optional<TzId> dtstart1TzId = dtstart1.getParameter(Parameter.TZID);

assertEquals("date value not correct", "20191006T190000", dtstart1.get().getValue());
assertNotNull("timezone not present", dtstart1TzId.isPresent());
assertEquals("date value not correct", "20191006T190000", dtstart1.getValue());
assertTrue("timezone not present", dtstart1TzId.isPresent());
assertEquals("timezone not correct", "Europe/Amsterdam", dtstart1TzId.get().getValue());

Optional<DtEnd<ZonedDateTime>> dtend1 = vevent1.getProperty(Property.DTEND);
Optional<TzId> dtend1TzId = dtend1.get().getParameter(Parameter.TZID);
DtEnd<ZonedDateTime> dtend1 = vevent1.getRequiredProperty(Property.DTEND);
Optional<TzId> dtend1TzId = dtend1.getParameter(Parameter.TZID);

assertEquals("date value not correct", "20191006T203000", dtend1.get().getValue());
assertEquals("date value not correct", "20191006T203000", dtend1.getValue());
assertTrue("timezone not present", dtend1TzId.isPresent());
assertEquals("timezone not correct", "Europe/Amsterdam", dtend1TzId.get().getValue());

Expand Down
Expand Up @@ -33,6 +33,7 @@

import junit.framework.TestCase;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.ConstraintViolationException;
import net.fortuna.ical4j.model.Property;
import net.fortuna.ical4j.util.Calendars;
import org.junit.Ignore;
Expand Down Expand Up @@ -60,10 +61,10 @@ protected void setUp() throws Exception {
/**
* Test method for {@link net.fortuna.ical4j.data.HCalendarParser#parse(java.io.Reader, net.fortuna.ical4j.data.ContentHandler)}.
*/
public void testParseReaderContentHandler() throws IOException, ParserException {
public void testParseReaderContentHandler() throws IOException, ParserException, ConstraintViolationException {
Calendar icsCalendar = Calendars.load(getClass().getResource("/samples/hcalendar/example1.ics"));
// remove prod-id which seems to be not handled by hcalendar..
icsCalendar.getProperties().remove(icsCalendar.getProperty(Property.PRODID).get());
icsCalendar.getProperties().remove(icsCalendar.getRequiredProperty(Property.PRODID));

CalendarBuilder builder = new CalendarBuilder(new HCalendarParser());
Calendar hcalCalendar = builder.build(getClass().getResourceAsStream("/samples/hcalendar/example1.html"));
Expand Down

0 comments on commit 238a25f

Please sign in to comment.