Skip to content

Commit

Permalink
Added fluent api for components and properties
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Mar 10, 2022
1 parent cd1b571 commit 3157f15
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
Expand Up @@ -41,7 +41,7 @@ public interface FluentComponent {
<C extends Component> C getFluentTarget();

default FluentComponent withProperty(Property property) {
getFluentTarget().getProperties().add(property);
getFluentTarget().add(property);
return getFluentTarget();
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/fortuna/ical4j/model/FluentProperty.java
Expand Up @@ -41,7 +41,7 @@ public interface FluentProperty {
<P extends Property> P getFluentTarget();

default FluentProperty withParameter(Parameter parameter) {
getFluentTarget().getParameters().add(parameter);
getFluentTarget().add(parameter);
return getFluentTarget();
}
}
28 changes: 12 additions & 16 deletions src/test/java/net/fortuna/ical4j/model/component/VAlarmTest.java
Expand Up @@ -33,7 +33,6 @@

import junit.framework.TestSuite;
import net.fortuna.ical4j.model.ComponentTest;
import net.fortuna.ical4j.model.ParameterList;
import net.fortuna.ical4j.model.parameter.FmtType;
import net.fortuna.ical4j.model.property.*;

Expand All @@ -42,7 +41,6 @@
import java.net.URISyntaxException;
import java.text.ParseException;
import java.time.Instant;
import java.util.Collections;

/**
* $Id$
Expand Down Expand Up @@ -70,8 +68,7 @@ public VAlarmTest(String testMethod, VAlarm component) {
public static TestSuite suite() throws URISyntaxException {
TestSuite suite = new TestSuite();

VAlarm alarm = new VAlarm();
alarm.add(new Trigger(Instant.now()));
VAlarm alarm = new VAlarm().withProperty(new Trigger(Instant.now())).getFluentTarget();

suite.addTest(new VAlarmTest("testIsCalendarComponent", alarm));
// suite.addTest(new VAlarmTest("testValidationException", alarm));
Expand All @@ -81,9 +78,10 @@ public static TestSuite suite() throws URISyntaxException {
suite.addTest(new VAlarmTest("testValidation", alarm));

// Test duration/repeat validation..
alarm = new VAlarm(java.time.Duration.ofHours(2));
alarm.add(Action.DISPLAY)
.add(new Description("Testing display"));
alarm = new VAlarm(java.time.Duration.ofHours(2))
.withProperty(Action.DISPLAY)
.withProperty(new Description("Testing display")).getFluentTarget();

Duration duration = new Duration(java.time.Duration.ofMinutes(2));
alarm.add(duration);
// suite.addTest(new VAlarmTest("testValidationException", alarm));
Expand All @@ -97,18 +95,16 @@ public static TestSuite suite() throws URISyntaxException {
// suite.addTest(new VAlarmTest("testValidationException", alarm));

//testValidationEmail..
alarm = new VAlarm(java.time.Duration.ofDays(-2));
alarm.add(Action.EMAIL)
.add(new Attendee("mailto:john_doe@example.com"))
.add(new Summary("*** REMINDER: SEND AGENDA FOR WEEKLY STAFF MEETING ***"))
.add(new Description("A draft agenda needs to be sent out to the attendees "
alarm = new VAlarm(java.time.Duration.ofDays(-2))
.withProperty(Action.EMAIL)
.withProperty(new Attendee("mailto:john_doe@example.com"))
.withProperty(new Summary("*** REMINDER: SEND AGENDA FOR WEEKLY STAFF MEETING ***"))
.withProperty(new Description("A draft agenda needs to be sent out to the attendees "
+ "to the weekly managers meeting (MGR-LIST). Attached is a "
+ "pointer the document template for the agenda file.")).getFluentTarget();

ParameterList attachParams = new ParameterList(Collections.singletonList(
new FmtType("application/msword")));
Attach attachment = new Attach(attachParams,
new URI("http://example.com/templates/agenda.doc"));
Attach attachment = new Attach(new URI("http://example.com/templates/agenda.doc"))
.withParameter(new FmtType("application/msword")).getFluentTarget();
alarm.add(attachment);
suite.addTest(new VAlarmTest("testValidation", alarm));

Expand Down

0 comments on commit 3157f15

Please sign in to comment.