ICalBean extends AbstractEntity { public void write(Writer w, String charset) { BEANS.get(ICalVCardHelper.class).write(this, w, charset); }  static ICalBean parse(Reader r, String characterSet); void write(Writer w, String charset); byte[] toBytes(String charset);  }
@Test public void testWrite() { ICalBean cal = BEANS.get(ICalBean.class); ICalVCardHelper helper = BEANS.get(ICalVCardHelper.class); Date prodDate = BEANS.get(IDateProvider.class).currentMillis(); Date startDate = DateUtility.addDays(BEANS.get(IDateProvider.class).currentMillis(), 1); Date endDate = DateUtility.addHours(startDate, 2); String uid = "e11d9aac-890f-409b-a016-3acef4685dc6"; cal.addProperty(ICalProperties.PROP_BEGIN_ICALENDAR); cal.addProperty(ICalProperties.PROP_VERSION_2_1); cal.addProperty(new Property(ICalProperties.PROP_NAME_PRODID, "prodid doe corporation")); cal.addProperty(ICalProperties.PROP_BEGIN_VEVENT); cal.addProperty(new Property(ICalProperties.PROP_NAME_DTSTAMP, helper.createDateTime(prodDate))); cal.addProperty(new Property(ICalProperties.PROP_NAME_UID, uid)); cal.addProperty(new Property(ICalProperties.PROP_NAME_DTSTART, helper.createDateTime(startDate))); cal.addProperty(new Property(ICalProperties.PROP_NAME_DTEND, helper.createDateTime(endDate))); cal.addProperty(new Property(ICalProperties.PROP_NAME_ORGANIZER, Arrays.asList(new PropertyParameter(ICalProperties.PARAM_NAME_CN, "\"John Doe\"")), "mailto:john@doe.mail.com")); cal.addProperty(ICalProperties.PROP_END_VEVENT); cal.addProperty(ICalProperties.PROP_END_ICALENDAR); StringWriter bw = new StringWriter(); cal.write(bw, "utf-8"); String writtenIcal = bw.toString(); assertEquals("BEGIN:VCALENDAR\r\n" + "VERSION:2.1\r\n" + "PRODID;CHARSET=utf-8:prodid doe corporation\r\n" + "BEGIN:VEVENT\r\n" + "DTSTAMP;CHARSET=utf-8:" + helper.createDateTime(prodDate) + "\r\n" + "UID;CHARSET=utf-8:" + uid + "\r\n" + "DTSTART;CHARSET=utf-8:" + helper.createDateTime(startDate) + "\r\n" + "DTEND;CHARSET=utf-8:" + helper.createDateTime(endDate) + "\r\n" + "ORGANIZER;CHARSET=utf-8;CN=\"John Doe\":mailto:john@doe.mail.com\r\n" + "END:VEVENT\r\n" + "END:VCALENDAR\r\n", writtenIcal); }