From 6beda1b3120f837c19c3a9e39fe49399199bad4a Mon Sep 17 00:00:00 2001 From: Ben Fortuna Date: Sat, 28 Mar 2020 09:18:38 +1100 Subject: [PATCH] Use optional as return type from ComponentList.getComponent --- .../net/fortuna/ical4j/model/Calendar.java | 7 +-- .../fortuna/ical4j/model/ComponentList.java | 7 +-- .../fortuna/ical4j/model/TimeZoneLoader.java | 17 +++---- .../ical4j/model/component/VTimeZone.java | 4 +- .../validate/CalendarValidatorImpl.java | 44 +++++++++---------- .../ical4j/validate/ComponentValidator.java | 2 +- .../CalendarBuilderCustomRegistryTest.java | 5 ++- .../fortuna/ical4j/model/TimeZoneTest.java | 4 +- .../component/VAvailabilityTestCase.java | 5 ++- .../ical4j/model/component/VEventTest.java | 11 ++--- .../ical4j/model/property/AttachTest.java | 5 ++- .../ical4j/model/property/AttendeeTest.java | 2 +- .../ical4j/model/property/CategoriesTest.java | 6 +-- .../model/property/DescriptionTest.java | 10 +++-- .../ical4j/model/property/ExDateTest.java | 22 +++++----- .../ical4j/model/property/LocationTest.java | 14 +++--- .../ical4j/model/property/SummaryTest.java | 10 +++-- 17 files changed, 94 insertions(+), 81 deletions(-) diff --git a/src/main/java/net/fortuna/ical4j/model/Calendar.java b/src/main/java/net/fortuna/ical4j/model/Calendar.java index 48ec500e6..f01dfb268 100644 --- a/src/main/java/net/fortuna/ical4j/model/Calendar.java +++ b/src/main/java/net/fortuna/ical4j/model/Calendar.java @@ -47,6 +47,7 @@ import java.net.URISyntaxException; import java.text.ParseException; import java.util.List; +import java.util.Optional; /** * $Id$ [Apr 5, 2004] @@ -144,7 +145,7 @@ public class Calendar implements Serializable { * Default constructor. */ public Calendar() { - this(new PropertyList(), new ComponentList()); + this(new PropertyList(), new ComponentList<>()); } /** @@ -225,8 +226,8 @@ public final ComponentList getComponents(final * @param name name of the component to retrieve * @return the first matching component in the component list with the specified name */ - public final CalendarComponent getComponent(final String name) { - return getComponents().getComponent(name); + public final Optional getComponent(final String name) { + return (Optional) getComponents().getComponent(name); } /** diff --git a/src/main/java/net/fortuna/ical4j/model/ComponentList.java b/src/main/java/net/fortuna/ical4j/model/ComponentList.java index 1204c23c4..3a28f394c 100644 --- a/src/main/java/net/fortuna/ical4j/model/ComponentList.java +++ b/src/main/java/net/fortuna/ical4j/model/ComponentList.java @@ -36,6 +36,7 @@ import java.text.ParseException; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; /** @@ -96,13 +97,13 @@ public final String toString() { * @param aName name of component to return * @return a component or null if no matching component found */ - public final T getComponent(final String aName) { + public final Optional getComponent(final String aName) { for (final T c : this) { if (c.getName().equals(aName)) { - return c; + return Optional.of(c); } } - return null; + return Optional.empty(); } /** diff --git a/src/main/java/net/fortuna/ical4j/model/TimeZoneLoader.java b/src/main/java/net/fortuna/ical4j/model/TimeZoneLoader.java index 735fa7149..0398a5d32 100644 --- a/src/main/java/net/fortuna/ical4j/model/TimeZoneLoader.java +++ b/src/main/java/net/fortuna/ical4j/model/TimeZoneLoader.java @@ -108,13 +108,14 @@ public VTimeZone loadVTimeZone(String id) throws IOException, ParserException, P try (InputStream in = resource.openStream()) { final CalendarBuilder builder = new CalendarBuilder(); final Calendar calendar = builder.build(in); - final VTimeZone vTimeZone = (VTimeZone) calendar.getComponent(Component.VTIMEZONE); + final Optional vTimeZone = calendar.getComponent(Component.VTIMEZONE); // load any available updates for the timezone.. can be explicility enabled via configuration - if ("true".equals(Configurator.getProperty(UPDATE_ENABLED).orElse("false"))) { - return updateDefinition(vTimeZone); + if (vTimeZone.isPresent() + && "true".equals(Configurator.getProperty(UPDATE_ENABLED).orElse("false"))) { + return updateDefinition(vTimeZone.get()); } - if (vTimeZone != null) { - cache.putIfAbsent(id, vTimeZone); + if (vTimeZone.isPresent()) { + cache.putIfAbsent(id, vTimeZone.get()); } } } else { @@ -149,9 +150,9 @@ private VTimeZone updateDefinition(VTimeZone vTimeZone) throws IOException, Pars final CalendarBuilder builder = new CalendarBuilder(); final Calendar calendar = builder.build(connection.getInputStream()); - final VTimeZone updatedVTimeZone = (VTimeZone) calendar.getComponent(Component.VTIMEZONE); - if (updatedVTimeZone != null) { - return updatedVTimeZone; + final Optional updatedVTimeZone = calendar.getComponent(Component.VTIMEZONE); + if (updatedVTimeZone.isPresent()) { + return updatedVTimeZone.get(); } } return vTimeZone; diff --git a/src/main/java/net/fortuna/ical4j/model/component/VTimeZone.java b/src/main/java/net/fortuna/ical4j/model/component/VTimeZone.java index 0448dc97c..1a2660b5e 100644 --- a/src/main/java/net/fortuna/ical4j/model/component/VTimeZone.java +++ b/src/main/java/net/fortuna/ical4j/model/component/VTimeZone.java @@ -204,8 +204,8 @@ public final void validate(final boolean recurse) /* * ; one of 'standardc' or 'daylightc' MUST occur ..; and each MAY occur more than once. standardc / daylightc / */ - if (getObservances().getComponent(Observance.STANDARD) == null - && getObservances().getComponent(Observance.DAYLIGHT) == null) { + if (!getObservances().getComponent(Observance.STANDARD).isPresent() + && !getObservances().getComponent(Observance.DAYLIGHT).isPresent()) { throw new ValidationException("Sub-components [" + Observance.STANDARD + "," + Observance.DAYLIGHT + "] must be specified at least once"); diff --git a/src/main/java/net/fortuna/ical4j/validate/CalendarValidatorImpl.java b/src/main/java/net/fortuna/ical4j/validate/CalendarValidatorImpl.java index eaea18720..a6cef3a52 100644 --- a/src/main/java/net/fortuna/ical4j/validate/CalendarValidatorImpl.java +++ b/src/main/java/net/fortuna/ical4j/validate/CalendarValidatorImpl.java @@ -72,7 +72,7 @@ public void validate(Calendar target) throws ValidationException { // validate properties.. for (final Property property : target.getProperties()) { - boolean isCalendarProperty = calendarProperties.stream().filter(calProp -> calProp.isInstance(property)) != null; + boolean isCalendarProperty = calendarProperties.stream().anyMatch(calProp -> calProp.isInstance(property)); if (!(property instanceof XProperty) && !isCalendarProperty) { throw new ValidationException("Invalid property: " + property.getName()); @@ -120,7 +120,7 @@ public static class PublishValidator implements Validator { @Override public void validate(Calendar target) throws ValidationException { - if (target.getComponent(Component.VEVENT) != null) { + if (target.getComponent(Component.VEVENT).isPresent()) { ComponentValidator.assertNone(Component.VFREEBUSY, target.getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, target.getComponents()); @@ -128,13 +128,13 @@ public void validate(Calendar target) throws ValidationException { ComponentValidator.assertNone(Component.VTODO, target.getComponents()); } } - else if (target.getComponent(Component.VFREEBUSY) != null) { + else if (target.getComponent(Component.VFREEBUSY).isPresent()) { ComponentValidator.assertNone(Component.VTODO, target.getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, target.getComponents()); ComponentValidator.assertNone(Component.VTIMEZONE, target.getComponents()); ComponentValidator.assertNone(Component.VALARM, target.getComponents()); } - else if (target.getComponent(Component.VTODO) != null) { + else if (target.getComponent(Component.VTODO).isPresent()) { // ComponentValidator.assertNone(Component.VFREEBUSY, target.getComponents()); // ComponentValidator.assertNone(Component.VEVENT, target.getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, target.getComponents()); @@ -151,18 +151,18 @@ public static class RequestValidator implements Validator { @Override public void validate(Calendar target) throws ValidationException { - if (target.getComponent(Component.VEVENT) != null) { + if (target.getComponent(Component.VEVENT).isPresent()) { ComponentValidator.assertNone(Component.VFREEBUSY, target.getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, target.getComponents()); ComponentValidator.assertNone(Component.VTODO, target.getComponents()); } - else if (target.getComponent(Component.VFREEBUSY) != null) { + else if (target.getComponent(Component.VFREEBUSY).isPresent()) { ComponentValidator.assertNone(Component.VTODO, target.getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, target.getComponents()); ComponentValidator.assertNone(Component.VTIMEZONE, target.getComponents()); ComponentValidator.assertNone(Component.VALARM, target.getComponents()); } - else if (target.getComponent(Component.VTODO) != null) { + else if (target.getComponent(Component.VTODO).isPresent()) { // ComponentValidator.assertNone(Component.VFREEBUSY, target.getComponents()); // ComponentValidator.assertNone(Component.VEVENT, target.getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, target.getComponents()); @@ -174,7 +174,7 @@ public static class ReplyValidator implements Validator { @Override public void validate(Calendar target) throws ValidationException { - if (target.getComponent(Component.VEVENT) != null) { + if (target.getComponent(Component.VEVENT).isPresent()) { ComponentValidator.assertOneOrLess(Component.VTIMEZONE, target.getComponents()); ComponentValidator.assertNone(Component.VALARM, target.getComponents()); @@ -182,13 +182,13 @@ public void validate(Calendar target) throws ValidationException { ComponentValidator.assertNone(Component.VJOURNAL, target.getComponents()); ComponentValidator.assertNone(Component.VTODO, target.getComponents()); } - else if (target.getComponent(Component.VFREEBUSY) != null) { + else if (target.getComponent(Component.VFREEBUSY).isPresent()) { ComponentValidator.assertNone(Component.VTODO, target.getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, target.getComponents()); ComponentValidator.assertNone(Component.VTIMEZONE, target.getComponents()); ComponentValidator.assertNone(Component.VALARM, target.getComponents()); } - else if (target.getComponent(Component.VTODO) != null) { + else if (target.getComponent(Component.VTODO).isPresent()) { ComponentValidator.assertOneOrLess(Component.VTIMEZONE, target.getComponents()); ComponentValidator.assertNone(Component.VALARM, target.getComponents()); @@ -203,17 +203,17 @@ public static class AddValidator implements Validator { @Override public void validate(Calendar target) throws ValidationException { - if (target.getComponent(Component.VEVENT) != null) { + if (target.getComponent(Component.VEVENT).isPresent()) { ComponentValidator.assertNone(Component.VFREEBUSY, target.getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, target.getComponents()); ComponentValidator.assertNone(Component.VTODO, target.getComponents()); } - else if (target.getComponent(Component.VTODO) != null) { + else if (target.getComponent(Component.VTODO).isPresent()) { ComponentValidator.assertNone(Component.VFREEBUSY, target.getComponents()); // ComponentValidator.assertNone(Component.VEVENT, target.getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, target.getComponents()); } - else if (target.getComponent(Component.VJOURNAL) != null) { + else if (target.getComponent(Component.VJOURNAL).isPresent()) { ComponentValidator.assertOneOrLess(Component.VTIMEZONE, target.getComponents()); ComponentValidator.assertNone(Component.VFREEBUSY, target.getComponents()); @@ -227,13 +227,13 @@ public static class CancelValidator implements Validator { @Override public void validate(Calendar target) throws ValidationException { - if (target.getComponent(Component.VEVENT) != null) { + if (target.getComponent(Component.VEVENT).isPresent()) { ComponentValidator.assertNone(Component.VALARM, target.getComponents()); ComponentValidator.assertNone(Component.VFREEBUSY, target.getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, target.getComponents()); ComponentValidator.assertNone(Component.VTODO, target.getComponents()); } - else if (target.getComponent(Component.VTODO) != null) { + else if (target.getComponent(Component.VTODO).isPresent()) { ComponentValidator.assertOneOrLess(Component.VTIMEZONE, target.getComponents()); ComponentValidator.assertNone(Component.VALARM, target.getComponents()); @@ -241,7 +241,7 @@ else if (target.getComponent(Component.VTODO) != null) { // ComponentValidator.assertNone(Component.VEVENT, target.getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, target.getComponents()); } - else if (target.getComponent(Component.VJOURNAL) != null) { + else if (target.getComponent(Component.VJOURNAL).isPresent()) { ComponentValidator.assertNone(Component.VALARM, target.getComponents()); ComponentValidator.assertNone(Component.VFREEBUSY, target.getComponents()); // ComponentValidator.assertNone(Component.VEVENT, target.getComponents()); @@ -254,13 +254,13 @@ public static class RefreshValidator implements Validator { @Override public void validate(Calendar target) throws ValidationException { - if (target.getComponent(Component.VEVENT) != null) { + if (target.getComponent(Component.VEVENT).isPresent()) { ComponentValidator.assertNone(Component.VALARM, target.getComponents()); ComponentValidator.assertNone(Component.VFREEBUSY, target.getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, target.getComponents()); ComponentValidator.assertNone(Component.VTODO, target.getComponents()); } - else if (target.getComponent(Component.VTODO) != null) { + else if (target.getComponent(Component.VTODO).isPresent()) { ComponentValidator.assertNone(Component.VALARM, target.getComponents()); ComponentValidator.assertNone(Component.VFREEBUSY, target.getComponents()); // ComponentValidator.assertNone(Component.VEVENT, target.getComponents()); @@ -274,12 +274,12 @@ public static class CounterValidator implements Validator { @Override public void validate(Calendar target) throws ValidationException { - if (target.getComponent(Component.VEVENT) != null) { + if (target.getComponent(Component.VEVENT).isPresent()) { ComponentValidator.assertNone(Component.VFREEBUSY, target.getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, target.getComponents()); ComponentValidator.assertNone(Component.VTODO, target.getComponents()); } - else if (target.getComponent(Component.VTODO) != null) { + else if (target.getComponent(Component.VTODO).isPresent()) { ComponentValidator.assertOneOrLess(Component.VTIMEZONE, target.getComponents()); ComponentValidator.assertNone(Component.VFREEBUSY, target.getComponents()); @@ -293,14 +293,14 @@ public static class DeclineCounterValidator implements Validator { @Override public void validate(Calendar target) throws ValidationException { - if (target.getComponent(Component.VEVENT) != null) { + if (target.getComponent(Component.VEVENT).isPresent()) { ComponentValidator.assertNone(Component.VFREEBUSY, target.getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, target.getComponents()); ComponentValidator.assertNone(Component.VTODO, target.getComponents()); ComponentValidator.assertNone(Component.VTIMEZONE, target.getComponents()); ComponentValidator.assertNone(Component.VALARM, target.getComponents()); } - else if (target.getComponent(Component.VTODO) != null) { + else if (target.getComponent(Component.VTODO).isPresent()) { ComponentValidator.assertNone(Component.VALARM, target.getComponents()); ComponentValidator.assertNone(Component.VFREEBUSY, target.getComponents()); // ComponentValidator.assertNone(Component.VEVENT, target.getComponents()); diff --git a/src/main/java/net/fortuna/ical4j/validate/ComponentValidator.java b/src/main/java/net/fortuna/ical4j/validate/ComponentValidator.java index 3c33164eb..e67418c79 100644 --- a/src/main/java/net/fortuna/ical4j/validate/ComponentValidator.java +++ b/src/main/java/net/fortuna/ical4j/validate/ComponentValidator.java @@ -89,7 +89,7 @@ public void validate(T target) throws ValidationException { * @throws ValidationException where the assertion fails */ public static void assertNone(String componentName, ComponentList components) throws ValidationException { - assertFalse(input -> input.getComponent(componentName) != null, ASSERT_NONE_MESSAGE, false, + assertFalse(input -> input.getComponent(componentName).isPresent(), ASSERT_NONE_MESSAGE, false, components, componentName); } diff --git a/src/test/java/net/fortuna/ical4j/data/CalendarBuilderCustomRegistryTest.java b/src/test/java/net/fortuna/ical4j/data/CalendarBuilderCustomRegistryTest.java index d1b93c5bb..3f7d3ed0f 100644 --- a/src/test/java/net/fortuna/ical4j/data/CalendarBuilderCustomRegistryTest.java +++ b/src/test/java/net/fortuna/ical4j/data/CalendarBuilderCustomRegistryTest.java @@ -39,6 +39,7 @@ import java.io.StringReader; import java.net.URISyntaxException; +import java.util.Optional; /** * $Id: CalendarBuilderCustomRegistryTest.java [Nov 16, 2009] @@ -118,8 +119,8 @@ public Parameter createParameter(final String value) throws URISyntaxException { Calendar cal = builder.build(new StringReader(VEVENT_WITH_SCHEDULE_STATUS)); - VEvent event = (VEvent)cal.getComponent(Component.VEVENT); - VEvent eventBis = (VEvent)event.copy(); + Optional event = cal.getComponent(Component.VEVENT); + VEvent eventBis = event.get().copy(); assertEquals(eventBis, event); } } diff --git a/src/test/java/net/fortuna/ical4j/model/TimeZoneTest.java b/src/test/java/net/fortuna/ical4j/model/TimeZoneTest.java index 182ccb82c..db9937a98 100644 --- a/src/test/java/net/fortuna/ical4j/model/TimeZoneTest.java +++ b/src/test/java/net/fortuna/ical4j/model/TimeZoneTest.java @@ -179,8 +179,8 @@ public TimeZoneTest(String testMethod, String vtimezoneDef, String zuluDateTimeS String expectedLocalDateTimeStr) throws Exception { super(testMethod); net.fortuna.ical4j.model.Calendar cal = new CalendarBuilder().build(new StringReader(vtimezoneDef)); - VTimeZone vtz = (VTimeZone) cal.getComponent(VTimeZone.VTIMEZONE); - this.timezone = new TimeZone(vtz); + Optional vtz = cal.getComponent(VTimeZone.VTIMEZONE); + this.timezone = new TimeZone(vtz.get()); this.zuluDateTimeStr = zuluDateTimeStr; this.expectedLocalDateTimeStr = expectedLocalDateTimeStr; } diff --git a/src/test/java/net/fortuna/ical4j/model/component/VAvailabilityTestCase.java b/src/test/java/net/fortuna/ical4j/model/component/VAvailabilityTestCase.java index b42b708fc..a0a5fe949 100644 --- a/src/test/java/net/fortuna/ical4j/model/component/VAvailabilityTestCase.java +++ b/src/test/java/net/fortuna/ical4j/model/component/VAvailabilityTestCase.java @@ -41,6 +41,7 @@ import java.io.IOException; import java.io.Reader; import java.io.StringReader; +import java.util.Optional; /** @@ -54,9 +55,9 @@ public void testVAvailability() throws ParserException, IOException String availability = getVAvailabilityICal(); Reader reader = new StringReader(availability); Calendar calendar = calendarBuilder.build(reader); - Component availabilityComponent = calendar.getComponent(Component.VAVAILABILITY); + Optional availabilityComponent = calendar.getComponent(Component.VAVAILABILITY); Assert.assertNotNull(availabilityComponent); - Assert.assertFalse(((VAvailability) availabilityComponent).getAvailable().isEmpty()); + Assert.assertFalse(availabilityComponent.get().getAvailable().isEmpty()); String iCalString = calendar.toString(); Assert.assertTrue(iCalString.contains("BEGIN:AVAILABLE")); Assert.assertEquals(iCalString.trim(), availability); diff --git a/src/test/java/net/fortuna/ical4j/model/component/VEventTest.java b/src/test/java/net/fortuna/ical4j/model/component/VEventTest.java index d0eed89cb..b1766961d 100644 --- a/src/test/java/net/fortuna/ical4j/model/component/VEventTest.java +++ b/src/test/java/net/fortuna/ical4j/model/component/VEventTest.java @@ -55,6 +55,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.List; +import java.util.Optional; import static net.fortuna.ical4j.model.WeekDay.*; import static org.junit.Assert.assertNotEquals; @@ -383,12 +384,12 @@ public final void testGetConsumedTime3() throws Exception { net.fortuna.ical4j.model.Calendar calendar = loadCalendar(resource); - VEvent vev = (VEvent) calendar.getComponent(Component.VEVENT); + Optional vev = calendar.getComponent(Component.VEVENT); - LocalDate start = (LocalDate) vev.getStartDate().getDate(); + LocalDate start = (LocalDate) vev.get().getStartDate().getDate(); LocalDate latest = LocalDate.now().plusYears(1); - List> pl = vev.getConsumedTime(new Period<>(start, latest)); + List> pl = vev.get().getConsumedTime(new Period<>(start, latest)); assertTrue(!pl.isEmpty()); } @@ -477,12 +478,12 @@ public void testGetConsumedTimeWithExDate2() throws IOException, ParserException InputStream in = getClass().getResourceAsStream("/samples/valid/friday13.ics"); net.fortuna.ical4j.model.Calendar calendar = new CalendarBuilder().build(in); - VEvent event = (VEvent) calendar.getComponent(Component.VEVENT); + Optional event = calendar.getComponent(Component.VEVENT); LocalDate start = LocalDate.now().withYear(1997).withMonth(8).withDayOfMonth(2); LocalDate end = start.withDayOfMonth(4); - List> periods = event.getConsumedTime(new Period<>(start, end)); + List> periods = event.get().getConsumedTime(new Period<>(start, end)); assertTrue(periods.isEmpty()); } diff --git a/src/test/java/net/fortuna/ical4j/model/property/AttachTest.java b/src/test/java/net/fortuna/ical4j/model/property/AttachTest.java index d66237136..cb729662c 100644 --- a/src/test/java/net/fortuna/ical4j/model/property/AttachTest.java +++ b/src/test/java/net/fortuna/ical4j/model/property/AttachTest.java @@ -51,6 +51,7 @@ import java.time.LocalDate; import java.util.ArrayList; import java.util.List; +import java.util.Optional; /** * $Id$ @@ -118,9 +119,9 @@ public void testAttachParameterListString() throws IOException, URISyntaxExcepti CalendarBuilder builder = new CalendarBuilder(); Calendar cout = builder.build(new StringReader(sw.toString())); - VEvent eout = (VEvent) cout.getComponent(Component.VEVENT); + Optional eout = cout.getComponent(Component.VEVENT); - Attach aout = (Attach) eout.getProperty(Property.ATTACH); + Attach aout = (Attach) eout.get().getProperty(Property.ATTACH); assertNotNull(aout); assertEquals(attach, aout); diff --git a/src/test/java/net/fortuna/ical4j/model/property/AttendeeTest.java b/src/test/java/net/fortuna/ical4j/model/property/AttendeeTest.java index 23f018257..c5ad17e02 100644 --- a/src/test/java/net/fortuna/ical4j/model/property/AttendeeTest.java +++ b/src/test/java/net/fortuna/ical4j/model/property/AttendeeTest.java @@ -103,7 +103,7 @@ public void testRelaxedParsing() throws IOException, ParserException { CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING, true); Calendar calendar = Calendars.load(getClass().getResource("/samples/invalid/groupwise.ics")); - Attendee attendee = (Attendee) calendar.getComponent(Component.VEVENT).getProperty(Property.ATTENDEE); + Attendee attendee = calendar.getComponent(Component.VEVENT).get().getProperty(Property.ATTENDEE); assertNotNull(attendee.getCalAddress()); } } diff --git a/src/test/java/net/fortuna/ical4j/model/property/CategoriesTest.java b/src/test/java/net/fortuna/ical4j/model/property/CategoriesTest.java index c879a9d4a..4edf36d79 100644 --- a/src/test/java/net/fortuna/ical4j/model/property/CategoriesTest.java +++ b/src/test/java/net/fortuna/ical4j/model/property/CategoriesTest.java @@ -113,7 +113,7 @@ public void testCommaEscaping() throws ValidationException, IOException, calendar = builder.build(new StringReader(tempOut.getBuffer() .toString())); - List categories = calendar.getComponent(Component.VEVENT) + List categories = calendar.getComponent(Component.VEVENT).get() .getProperties(Property.CATEGORIES); assertEquals(cat1, categories.get(0)); @@ -146,7 +146,7 @@ public static TestSuite suite() throws IOException, ValidationException, // Test escaping of categories string representation.. Calendar calendar = Calendars.load(CategoriesTest.class.getResource("/samples/valid/categories.ics")); - Categories orig = (Categories) calendar.getComponent(Component.VEVENT) + Categories orig = (Categories) calendar.getComponent(Component.VEVENT).get() .getProperty(Property.CATEGORIES); StringWriter tempOut = new StringWriter(); @@ -157,7 +157,7 @@ public static TestSuite suite() throws IOException, ValidationException, calendar = builder.build(new StringReader(tempOut.getBuffer() .toString())); - Categories copy = (Categories) calendar.getComponent(Component.VEVENT) + Categories copy = (Categories) calendar.getComponent(Component.VEVENT).get() .getProperty(Property.CATEGORIES); assertEquals(orig, copy); suite.addTest(new CategoriesTest(copy, orig.getValue())); diff --git a/src/test/java/net/fortuna/ical4j/model/property/DescriptionTest.java b/src/test/java/net/fortuna/ical4j/model/property/DescriptionTest.java index d4e266b40..69a1cca1d 100755 --- a/src/test/java/net/fortuna/ical4j/model/property/DescriptionTest.java +++ b/src/test/java/net/fortuna/ical4j/model/property/DescriptionTest.java @@ -31,16 +31,18 @@ */ package net.fortuna.ical4j.model.property; -import java.io.IOException; - import junit.framework.TestSuite; import net.fortuna.ical4j.data.ParserException; import net.fortuna.ical4j.model.Calendar; import net.fortuna.ical4j.model.Component; import net.fortuna.ical4j.model.Property; import net.fortuna.ical4j.model.PropertyTest; +import net.fortuna.ical4j.model.component.VEvent; import net.fortuna.ical4j.util.Calendars; +import java.io.IOException; +import java.util.Optional; + /** * Created on 21/08/2007 * @@ -65,8 +67,8 @@ public static TestSuite suite() throws IOException, ParserException { TestSuite suite = new TestSuite(); // Test correct parsing of text with tabs. Calendar calendar = Calendars.load(DescriptionTest.class.getResource("/samples/valid/mansour.ics")); - Component event = calendar.getComponent(Component.VEVENT); - suite.addTest(new DescriptionTest(event + Optional event = calendar.getComponent(Component.VEVENT); + suite.addTest(new DescriptionTest(event.get() .getProperty(Property.DESCRIPTION), "Test\t\ttabs")); return suite; } diff --git a/src/test/java/net/fortuna/ical4j/model/property/ExDateTest.java b/src/test/java/net/fortuna/ical4j/model/property/ExDateTest.java index c0ca28289..df0379bcc 100644 --- a/src/test/java/net/fortuna/ical4j/model/property/ExDateTest.java +++ b/src/test/java/net/fortuna/ical4j/model/property/ExDateTest.java @@ -81,9 +81,9 @@ protected void tearDown() throws Exception { public void testTimeZones() throws Exception { CalendarBuilder builder = new CalendarBuilder(); Calendar calendar = builder.build(getClass().getResourceAsStream("/samples/valid/EXDATE.ics")); - - Component event = calendar.getComponent(Component.VEVENT); - List exdates = event.getProperties(Property.EXDATE); + + Optional event = calendar.getComponent(Component.VEVENT); + List exdates = event.get().getProperties(Property.EXDATE); for (Property exDate : exdates) { assertTrue("This EXDATE should have a timezone", exDate.getParameter(Parameter.TZID).isPresent()); } @@ -93,15 +93,15 @@ public void testDstOnlyVTimeZones() throws Exception { CalendarBuilder builder = new CalendarBuilder(); Calendar ical = builder.build(getClass().getResourceAsStream("/samples/valid/dst-only-vtimezone.ics")); - VTimeZone vTZ = (VTimeZone) ical.getComponent(VTimeZone.VTIMEZONE); + Optional vTZ = ical.getComponent(VTimeZone.VTIMEZONE); - String id = vTZ.getTimeZoneId().getValue(); + String id = vTZ.get().getTimeZoneId().getValue(); assertEquals("Europe/Berlin", id); - assertEquals(vTZ.getObservances().get(0), vTZ.getApplicableObservance(TemporalAdapter.parse("20180403").getTemporal())); + assertEquals(vTZ.get().getObservances().get(0), vTZ.get().getApplicableObservance(TemporalAdapter.parse("20180403").getTemporal())); - VEvent vEvent = (VEvent) ical.getComponent(VEvent.VEVENT); - DtStart start = vEvent.getStartDate(); - assertTrue(start.getParameter(Parameter.TZID).equals(Optional.of(vTZ.getTimeZoneId()))); + Optional vEvent = ical.getComponent(VEvent.VEVENT); + DtStart start = vEvent.get().getStartDate(); + assertTrue(start.getParameter(Parameter.TZID).equals(Optional.of(vTZ.get().getTimeZoneId()))); assertEquals(1522738800000L, Instant.from(start.getDate()).toEpochMilli()); } @@ -109,8 +109,8 @@ public void testShouldPreserveUtcTimezoneForExDate() throws Exception { CalendarBuilder builder = new CalendarBuilder(); Calendar calendar = builder.build(getClass().getResourceAsStream("/samples/valid/EXDATE-IN-UTC.ics")); - Component event = calendar.getComponent(Component.VEVENT); - List exdates = event.getProperties(Property.EXDATE); + Optional event = calendar.getComponent(Component.VEVENT); + List exdates = event.get().getProperties(Property.EXDATE); for (Property exDate : exdates) { for (Instant dateEx : ((ExDate) exDate).getDates().getDates()) { assertNotNull(dateEx); diff --git a/src/test/java/net/fortuna/ical4j/model/property/LocationTest.java b/src/test/java/net/fortuna/ical4j/model/property/LocationTest.java index e369fc51e..af5fc99bb 100644 --- a/src/test/java/net/fortuna/ical4j/model/property/LocationTest.java +++ b/src/test/java/net/fortuna/ical4j/model/property/LocationTest.java @@ -31,16 +31,18 @@ */ package net.fortuna.ical4j.model.property; -import java.io.IOException; - import junit.framework.TestSuite; import net.fortuna.ical4j.data.ParserException; import net.fortuna.ical4j.model.Calendar; import net.fortuna.ical4j.model.Component; import net.fortuna.ical4j.model.Property; import net.fortuna.ical4j.model.PropertyTest; +import net.fortuna.ical4j.model.component.VEvent; import net.fortuna.ical4j.util.Calendars; +import java.io.IOException; +import java.util.Optional; + /** * $Id$ * @@ -74,8 +76,8 @@ public LocationTest(String testMethod, Location property) { */ public void testQuotedText() throws IOException, ParserException { Calendar calendar = Calendars.load(getClass().getResource("/samples/valid/mansour.ics")); - Component event = calendar.getComponent(Component.VEVENT); - assertEquals("At \"The Terrace\" Complex > Melbourne \"\\,", event.getProperty(Property.LOCATION).getValue()); + Optional event = calendar.getComponent(Component.VEVENT); + assertEquals("At \"The Terrace\" Complex > Melbourne \"\\,", event.get().getProperty(Property.LOCATION).getValue()); } /** @@ -87,8 +89,8 @@ public static TestSuite suite() throws IOException, ParserException { TestSuite suite = new TestSuite(); //testQuotedText.. Calendar calendar = Calendars.load(LocationTest.class.getResource("/samples/valid/mansour.ics")); - Component event = calendar.getComponent(Component.VEVENT); - Location location = (Location) event.getProperty(Property.LOCATION); + Optional event = calendar.getComponent(Component.VEVENT); + Location location = (Location) event.get().getProperty(Property.LOCATION); suite.addTest(new LocationTest(location, "At \"The Terrace\" Complex > Melbourne \"\\,")); return suite; } diff --git a/src/test/java/net/fortuna/ical4j/model/property/SummaryTest.java b/src/test/java/net/fortuna/ical4j/model/property/SummaryTest.java index f9b9b76fd..92424d989 100644 --- a/src/test/java/net/fortuna/ical4j/model/property/SummaryTest.java +++ b/src/test/java/net/fortuna/ical4j/model/property/SummaryTest.java @@ -31,16 +31,18 @@ */ package net.fortuna.ical4j.model.property; -import java.io.IOException; - import junit.framework.TestSuite; import net.fortuna.ical4j.data.ParserException; import net.fortuna.ical4j.model.Calendar; import net.fortuna.ical4j.model.Component; import net.fortuna.ical4j.model.Property; import net.fortuna.ical4j.model.PropertyTest; +import net.fortuna.ical4j.model.component.VEvent; import net.fortuna.ical4j.util.Calendars; +import java.io.IOException; +import java.util.Optional; + /** * $Id$ * @@ -76,8 +78,8 @@ public static TestSuite suite() throws IOException, ParserException { TestSuite suite = new TestSuite(); // Test correct parsing of quoted text.. Calendar calendar = Calendars.load(SummaryTest.class.getResource("/samples/valid/mansour.ics")); - Component event = calendar.getComponent(Component.VEVENT); - Summary summary = (Summary) event.getProperty(Property.SUMMARY); + Optional event = calendar.getComponent(Component.VEVENT); + Summary summary = (Summary) event.get().getProperty(Property.SUMMARY); suite.addTest(new SummaryTest(summary, "A colon with spaces on either side : like that")); suite.addTest(new SummaryTest("testValidation", summary));