Commit 2576dc6e authored by Ricki Hirner's avatar Ricki Hirner

Rewrite tests to Kotlin

parent acd0fa98
......@@ -24,11 +24,14 @@ Generated KDoc: https://bitfireAT.gitlab.io/ical4android/dokka/ical4android/
```
bitfire web engineering – Stockmann, Hirner GesnbR
Liniengasse 6/3/28
Florastraße 27
2540 Bad Vöslau, AUSTRIA
```
Email: [play@bitfire.at](mailto:play@bitfire.at)
Email: [play@bitfire.at](mailto:play@bitfire.at) (do not use this)
For questions, suggestions etc. please use the DAVdroid forum:
https://www.davdroid.com/forums/
## License
......
......@@ -5,9 +5,7 @@ buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
google()
}
dependencies {
......@@ -19,9 +17,7 @@ buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
google()
}
apply plugin: 'com.android.library'
......@@ -68,28 +64,4 @@ dependencies {
androidTestCompile 'com.android.support.test:rules:1.0.1'
testCompile 'junit:junit:4.12'
testCompileOnly 'org.projectlombok:lombok:1.16.20'
}
// grant permissions for unit tests
task grantPermissions(dependsOn: 'installDebugAndroidTest') {
doFirst {
def adb = android.getAdbExe().toString()
// grant permissions
[
'android.permission.READ_CALENDAR',
'android.permission.WRITE_CALENDAR',
'org.dmfs.permission.READ_TASKS',
'org.dmfs.permission.WRITE_TASKS'
].each {
"${adb} shell pm grant at.bitfire.ical4android.test ${it}".execute()
}
}
}
tasks.whenTaskAdded { task ->
if (task.name.startsWith('connectedDebugAndroidTest')) {
task.dependsOn grantPermissions
}
}
......@@ -247,7 +247,7 @@ abstract class AndroidEvent(
if (idNS != null || id != null) {
// attendee identified by namespace and ID
attendee = Attendee(URI(idNS, id, null))
email?.let { attendee.parameters.add(iCalendar.Email(it)) }
email?.let { attendee.parameters.add(ICalendar.Email(it)) }
} else
// attendee identified by email address
attendee = Attendee(URI("mailto", email, null))
......@@ -560,7 +560,7 @@ abstract class AndroidEvent(
if (uri.scheme.equals("mailto", true))
email = uri.schemeSpecificPart
else {
val emailParam = organizer.getParameter(iCalendar.Email.PARAMETER_NAME) as iCalendar.Email?
val emailParam = organizer.getParameter(ICalendar.Email.PARAMETER_NAME) as ICalendar.Email?
email = emailParam?.value
}
if (email != null)
......@@ -599,7 +599,7 @@ abstract class AndroidEvent(
else -> Reminders.METHOD_DEFAULT
}
val minutes = iCalendar.alarmMinBefore(alarm)
val minutes = ICalendar.alarmMinBefore(alarm)
builder .withValue(Reminders.METHOD, method)
.withValue(Reminders.MINUTES, minutes)
......@@ -618,7 +618,7 @@ abstract class AndroidEvent(
// attendee identified by other URI
builder .withValue(Attendees.ATTENDEE_ID_NAMESPACE, member.scheme)
.withValue(Attendees.ATTENDEE_IDENTITY, member.schemeSpecificPart)
(attendee.getParameter(iCalendar.Email.PARAMETER_NAME) as iCalendar.Email?)?.let { email ->
(attendee.getParameter(ICalendar.Email.PARAMETER_NAME) as ICalendar.Email?)?.let { email ->
builder.withValue(Attendees.ATTENDEE_EMAIL, email.value)
}
}
......
......@@ -8,7 +8,7 @@
package at.bitfire.ical4android
@Deprecated("Do not wrap calendar IPC exceptions if you don't need to.")
@Deprecated("Unnecessary generic wrapper around RemoteException")
class CalendarStorageException: Exception {
constructor(message: String): super(message)
......
......@@ -22,7 +22,7 @@ import java.io.OutputStream
import java.io.Reader
import java.util.*
class Event: iCalendar() {
class Event: ICalendar() {
// uid and sequence are inherited from iCalendar
var recurrenceId: RecurrenceId? = null
......@@ -153,7 +153,7 @@ class Event: iCalendar() {
@Throws(InvalidCalendarException::class)
fun fromVEvent(event: VEvent): Event {
private fun fromVEvent(event: VEvent): Event {
val e = Event()
// sequence must only be null for locally created, not-yet-synchronized events
......
......@@ -23,7 +23,7 @@ import java.util.*
import java.util.logging.Level
import java.util.logging.Logger
open class iCalendar {
open class ICalendar {
var uid: String? = null
var sequence: Int? = null
......
......@@ -22,7 +22,7 @@ object MiscUtils {
*/
@JvmStatic
fun androidifyTimeZone(date: DateProperty?) {
if (iCalendar.isDateTime(date)) {
if (ICalendar.isDateTime(date)) {
val tz = date!!.timeZone ?: return
val tzID = tz.id ?: return
val deviceTzID = DateUtils.findAndroidTimezoneID(tzID)
......@@ -40,7 +40,7 @@ object MiscUtils {
*/
@JvmStatic
fun getTzId(date: DateProperty?) =
if (iCalendar.isDateTime(date!!) && !date.isUtc && date.timeZone != null)
if (ICalendar.isDateTime(date!!) && !date.isUtc && date.timeZone != null)
date.timeZone.id!!
else
TimeZones.UTC_ID
......
......@@ -24,7 +24,7 @@ import java.net.URISyntaxException
import java.util.*
import java.util.logging.Level
class Task: iCalendar() {
class Task: ICalendar() {
var createdAt: Long? = null
var lastModified: Long? = null
......
/*
* Copyright © Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.ical4android;
import net.fortuna.ical4j.model.DateList;
import net.fortuna.ical4j.model.TimeZone;
import net.fortuna.ical4j.model.parameter.Value;
import net.fortuna.ical4j.model.property.ExDate;
import net.fortuna.ical4j.model.property.RDate;
import org.junit.Test;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class DateUtilsTest {
private static final String tzIdToronto = "America/Toronto";
static final TimeZone tzToronto = DateUtils.tzRegistry.getTimeZone(tzIdToronto);
static {
assertNotNull(tzToronto);
}
@Test
public void testRecurrenceSetsToAndroidString() throws ParseException {
// one entry with implicitly set UTC
final List<RDate> list = new ArrayList<>(2);
list.add(new RDate(new DateList("20150101T103010Z,20150102T103020Z", Value.DATE_TIME)));
assertEquals("20150101T103010Z,20150102T103020Z", DateUtils.recurrenceSetsToAndroidString(list, false));
// two separate entries, both with time zone Toronto
// 2015/01/03 11:30:30 Toronto = 2015/01/03 16:30:30 UTC = 1420302630 UNIX
// 2015/07/04 11:30:40 Toronto = 2015/07/04 15:30:40 UTC = 1436023840 UNIX
list.clear();
list.add(new RDate(new DateList("20150103T113030", Value.DATE_TIME, tzToronto)));
list.add(new RDate(new DateList("20150704T113040", Value.DATE_TIME, tzToronto)));
assertEquals("20150103T163030Z,20150704T153040Z", DateUtils.recurrenceSetsToAndroidString(list, false));
// DATEs (without time) have to be converted to <date>T000000Z for Android
list.clear();
list.add(new RDate(new DateList("20150101,20150702", Value.DATE)));
assertEquals("20150101T000000Z,20150702T000000Z", DateUtils.recurrenceSetsToAndroidString(list, true));
// DATE-TIME (floating time or UTC) recurrences for all-day events have to converted to <date>T000000Z for Android
list.clear();
list.add(new RDate(new DateList("20150101T000000,20150702T000000Z", Value.DATE_TIME)));
assertEquals("20150101T000000Z,20150702T000000Z", DateUtils.recurrenceSetsToAndroidString(list, true));
}
@Test
public void testAndroidStringToRecurrenceSets() throws ParseException {
// list of UTC times
ExDate exDate = (ExDate)DateUtils.androidStringToRecurrenceSet("20150101T103010Z,20150702T103020Z", ExDate.class, false);
DateList exDates = exDate.getDates();
assertEquals(Value.DATE_TIME, exDates.getType());
assertTrue(exDates.isUtc());
assertEquals(2, exDates.size());
assertEquals(1420108210000L, exDates.get(0).getTime());
assertEquals(1435833020000L, exDates.get(1).getTime());
// list of time zone times
exDate = (ExDate)DateUtils.androidStringToRecurrenceSet(tzIdToronto + ";20150103T113030,20150704T113040", ExDate.class, false);
exDates = exDate.getDates();
assertEquals(Value.DATE_TIME, exDates.getType());
assertEquals(DateUtils.tzRegistry.getTimeZone(tzIdToronto), exDates.getTimeZone());
assertEquals(2, exDates.size());
assertEquals(1420302630000L, exDates.get(0).getTime());
assertEquals(1436023840000L, exDates.get(1).getTime());
// list of dates
exDate = (ExDate)DateUtils.androidStringToRecurrenceSet("20150101T103010Z,20150702T103020Z", ExDate.class, true);
exDates = exDate.getDates();
assertEquals(Value.DATE, exDates.getType());
assertEquals(2, exDates.size());
assertEquals("20150101", exDates.get(0).toString());
assertEquals("20150702", exDates.get(1).toString());
}
}
/*
* Copyright © Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.ical4android
import net.fortuna.ical4j.model.DateList
import net.fortuna.ical4j.model.parameter.Value
import net.fortuna.ical4j.model.property.DateListProperty
import net.fortuna.ical4j.model.property.ExDate
import net.fortuna.ical4j.model.property.RDate
import org.junit.Assert
import org.junit.Assert.*
import org.junit.Test
import java.util.*
class DateUtilsTest {
private val tzIdToronto = "America/Toronto"
private val tzToronto = DateUtils.tzRegistry.getTimeZone(tzIdToronto)
init {
assertNotNull(tzToronto)
}
@Test
fun testTimeZoneRegistry() {
Assert.assertNotNull(DateUtils.tzRegistry.getTimeZone("Europe/Vienna"))
// https://github.com/ical4j/ical4j/issues/207
// assertNotNull(DateUtils.tzRegistry.getTimeZone("EST"))
}
@Test
fun testRecurrenceSetsToAndroidString() {
// one entry with implicitly set UTC
val list = ArrayList<DateListProperty>(2)
list.add(RDate(DateList("20150101T103010Z,20150102T103020Z", Value.DATE_TIME)))
assertEquals("20150101T103010Z,20150102T103020Z", DateUtils.recurrenceSetsToAndroidString(list, false))
// two separate entries, both with time zone Toronto
// 2015/01/03 11:30:30 Toronto = 2015/01/03 16:30:30 UTC = 1420302630 UNIX
// 2015/07/04 11:30:40 Toronto = 2015/07/04 15:30:40 UTC = 1436023840 UNIX
list.clear()
list.add(RDate(DateList("20150103T113030", Value.DATE_TIME, tzToronto)))
list.add(RDate(DateList("20150704T113040", Value.DATE_TIME, tzToronto)))
assertEquals("20150103T163030Z,20150704T153040Z", DateUtils.recurrenceSetsToAndroidString(list, false))
// DATEs (without time) have to be converted to <date>T000000Z for Android
list.clear()
list.add(RDate(DateList("20150101,20150702", Value.DATE)))
assertEquals("20150101T000000Z,20150702T000000Z", DateUtils.recurrenceSetsToAndroidString(list, true))
// DATE-TIME (floating time or UTC) recurrences for all-day events have to converted to <date>T000000Z for Android
list.clear()
list.add(RDate(DateList("20150101T000000,20150702T000000Z", Value.DATE_TIME)))
assertEquals("20150101T000000Z,20150702T000000Z", DateUtils.recurrenceSetsToAndroidString(list, true))
}
@Test
fun testAndroidStringToRecurrenceSets() {
// list of UTC times
var exDate = DateUtils.androidStringToRecurrenceSet("20150101T103010Z,20150702T103020Z", ExDate::class.java, false)
var exDates = exDate.dates
assertEquals(Value.DATE_TIME, exDates.type)
assertTrue(exDates.isUtc)
assertEquals(2, exDates.size)
assertEquals(1420108210000L, exDates.get(0).time)
assertEquals(1435833020000L, exDates.get(1).time)
// list of time zone times
exDate = DateUtils.androidStringToRecurrenceSet(tzIdToronto + ";20150103T113030,20150704T113040", ExDate::class.java, false)
exDates = exDate.dates
assertEquals(Value.DATE_TIME, exDates.type)
assertEquals(DateUtils.tzRegistry.getTimeZone(tzIdToronto), exDates.timeZone)
assertEquals(2, exDates.size)
assertEquals(1420302630000L, exDates.get(0).time)
assertEquals(1436023840000L, exDates.get(1).time)
// list of dates
exDate = DateUtils.androidStringToRecurrenceSet("20150101T103010Z,20150702T103020Z", ExDate::class.java, true)
exDates = exDate.dates
assertEquals(Value.DATE, exDates.type)
assertEquals(2, exDates.size)
assertEquals("20150101", exDates.get(0).toString())
assertEquals("20150702", exDates.get(1).toString())
}
}
/*
* Copyright © Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.ical4android;
import org.junit.Test;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import kotlin.text.Charsets;
import lombok.Cleanup;
import lombok.NonNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class EventTest {
private static final String TAG = "ical4android.EventTest";
/* public interface tests */
@Test
public void testCalendarProperties() throws IOException, InvalidCalendarException {
@Cleanup InputStream is = getClass().getClassLoader().getResourceAsStream("events/multiple.ics");
assertNotNull(is);
Map<String, String> properties = new HashMap<>();
Event.fromReader(new InputStreamReader(is, Charsets.UTF_8), properties);
assertEquals(1, properties.size());
assertEquals("Test-Kalender", properties.get(Event.CALENDAR_NAME));
}
@Test
public void testCharsets() throws IOException, InvalidCalendarException {
Event e = parseCalendar("latin1.ics", Charset.forName("ISO-8859-1"))[0];
assertEquals("äöüß", e.getSummary());
e = parseCalendar("utf8.ics", null)[0];
assertEquals("© äö — üß", e.getSummary());
assertEquals("中华人民共和国", e.getLocation());
}
public void testParsingCustomTimezone() throws IOException, InvalidCalendarException {
Event[] events = parseCalendar("custom-timezone.ics", null);
assertEquals(1, events.length);
Event e = events[0];
assertEquals("XXX", e.getDtStart().getTimeZone().getID());
}
@Test
public void testGrouping() throws IOException, InvalidCalendarException {
Event[] events = parseCalendar("multiple.ics", null);
assertEquals(3, events.length);
Event e = findEvent(events, "multiple-0@ical4android.EventTest");
assertEquals("Event 0", e.getSummary());
assertEquals(0, e.getExceptions().size());
e = findEvent(events, "multiple-1@ical4android.EventTest");
assertEquals("Event 1", e.getSummary());
assertEquals(1, e.getExceptions().size());
assertEquals("Event 1 Exception", e.getExceptions().get(0).getSummary());
e = findEvent(events, "multiple-2@ical4android.EventTest");
assertEquals("Event 2", e.getSummary());
assertEquals(2, e.getExceptions().size());
assertTrue("Event 2 Updated Exception 1".equals(e.getExceptions().get(0).getSummary()) || "Event 2 Updated Exception 1".equals(e.getExceptions().get(1).getSummary()));
assertTrue("Event 2 Exception 2".equals(e.getExceptions().get(0).getSummary()) || "Event 2 Exception 2".equals(e.getExceptions().get(1).getSummary()));
}
@Test
public void testParseAndWrite() throws IOException, InvalidCalendarException {
Event event = parseCalendar("utf8.ics", null)[0];
assertEquals("utf8@ical4android.EventTest", event.getUid());
assertEquals("© äö — üß", event.getSummary());
assertEquals("Test Description", event.getDescription());
assertEquals("中华人民共和国", event.getLocation());
assertEquals(EventColor.aliceblue, event.getColor());
}
@Test
public void testRecurringWithException() throws IOException, InvalidCalendarException {
Event event = parseCalendar("recurring-with-exception1.ics", null)[0];
assertTrue(event.isAllDay());
assertEquals(1, event.getExceptions().size());
Event exception = event.getExceptions().get(0);
assertEquals("20150503", exception.getRecurrenceId().getValue());
assertEquals("Another summary for the third day", exception.getSummary());
}
@Test
public void testStartEndTimes() throws IOException, InvalidCalendarException {
// event with start+end date-time
Event eViennaEvolution = parseCalendar("vienna-evolution.ics", null)[0];
assertEquals(1381330800000L, eViennaEvolution.getDtStart().getDate().getTime());
assertEquals("/freeassociation.sourceforge.net/Tzfile/Europe/Vienna", eViennaEvolution.getDtStart().getTimeZone().getID());
assertEquals(1381334400000L, eViennaEvolution.getDtEnd().getDate().getTime());
assertEquals("/freeassociation.sourceforge.net/Tzfile/Europe/Vienna", eViennaEvolution.getDtEnd().getTimeZone().getID());
}
@Test
public void testStartEndTimesAllDay() throws IOException, InvalidCalendarException {
// event with start date only
Event eOnThatDay = parseCalendar("event-on-that-day.ics", null)[0];
assertEquals(868838400000L, eOnThatDay.getDtStart().getDate().getTime());
assertNull(eOnThatDay.getDtStart().getTimeZone());
// event with start+end date for all-day event (one day)
Event eAllDay1Day = parseCalendar("all-day-1day.ics", null)[0];
assertEquals(868838400000L, eAllDay1Day.getDtStart().getDate().getTime());
assertNull(eAllDay1Day.getDtStart().getTimeZone());
assertEquals(868838400000L + 86400000, eAllDay1Day.getDtEnd().getDate().getTime());
assertNull(eAllDay1Day.getDtEnd().getTimeZone());
// event with start+end date for all-day event (ten days)
Event eAllDay10Days = parseCalendar("all-day-10days.ics", null)[0];
assertEquals(868838400000L, eAllDay10Days.getDtStart().getDate().getTime());
assertNull(eAllDay10Days.getDtStart().getTimeZone());
assertEquals(868838400000L + 10 * 86400000, eAllDay10Days.getDtEnd().getDate().getTime());
assertNull(eAllDay10Days.getDtEnd().getTimeZone());
// event with start+end date on some day (0 sec-event)
Event eAllDay0Sec = parseCalendar("all-day-0sec.ics", null)[0];
assertEquals(868838400000L, eAllDay0Sec.getDtStart().getDate().getTime());
assertNull(eAllDay0Sec.getDtStart().getTimeZone());
// DTEND is same as DTSTART which is not valid for Android – but this will be handled by AndroidEvent, not Event
assertEquals(868838400000L, eAllDay0Sec.getDtEnd().getDate().getTime());
assertNull(eAllDay0Sec.getDtEnd().getTimeZone());
}
@Test
public void testUnfolding() throws IOException, InvalidCalendarException {
Event e = parseCalendar("two-line-description-without-crlf.ics", null)[0];
assertEquals("http://www.tgbornheim.de/index.php?sessionid=&page=&id=&sportcentergroup=&day=6", e.getDescription());
}
@Test
public void testToString() {
Event e = new Event();
e.setUid("SAMPLEUID");
String s = e.toString();
assertTrue(s.contains(Event.class.getSimpleName()));
assertTrue(s.contains("uid=SAMPLEUID"));
}
/* internal tests */
@Test
public void testFindMasterEventsAndExceptions() throws ParseException, IOException, InvalidCalendarException {
Event[] events;
// two single events
events = parseCalendar("two-events-without-exceptions.ics", null);
assertEquals(2, events.length);
for (Event event : events)
assertTrue(event.getExceptions().isEmpty());
// one event with exception, another single event
events = parseCalendar("one-event-with-exception-one-without.ics", null);
assertEquals(2, events.length);
for (Event event : events) {
String uid = event.getUid();
if ("event1".equals(uid))
assertEquals(1, event.getExceptions().size());
else
assertTrue(event.getExceptions().isEmpty());
}
// one event two exceptions (thereof one updated two times) and updated exception, another single event
events = parseCalendar("one-event-with-multiple-exceptions-one-without.ics", null);
assertEquals(2, events.length);
for (Event event : events) {
String uid = event.getUid();
if ("event1".equals(uid)) {
assertEquals(2, event.getExceptions().size());
for (Event exception : event.getExceptions())
if ("20150503".equals(exception.getRecurrenceId().getValue())) {
assertEquals(2, (int)exception.getSequence());
assertEquals("Final summary", exception.getSummary());
}
} else
assertTrue(event.getExceptions().isEmpty());
}
}
// helpers
private Event findEvent(@NonNull Event[] events, @NonNull String uid) throws FileNotFoundException {
for (Event event : events)
if (uid.equals(event.getUid()))
return event;
throw new FileNotFoundException();
}
private Event[] parseCalendar(String fname, Charset charset) throws IOException, InvalidCalendarException {
fname = "events/" + fname;
System.err.println("Loading event file " + fname);
@Cleanup InputStream is = getClass().getClassLoader().getResourceAsStream(fname);
assertNotNull(is);
List<Event> events = Event.fromReader(new InputStreamReader(is, charset == null ? Charsets.UTF_8 : charset));
return events.toArray(new Event[events.size()]);
}
}
/*
* Copyright © Ricki Hirner (bitfire web engineering).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*/
package at.bitfire.ical4android
import org.junit.Assert.*
import org.junit.Test
import java.io.FileNotFoundException
import java.io.InputStreamReader
import java.nio.charset.Charset
class EventTest {
/* public interface tests */
@Test
fun testCalendarProperties() {
javaClass.classLoader.getResourceAsStream("events/multiple.ics").use { stream ->
val properties = mutableMapOf<String, String>()
Event.fromReader(InputStreamReader(stream, Charsets.UTF_8), properties)
assertEquals(1, properties.size)
assertEquals("Test-Kalender", properties[Event.CALENDAR_NAME])
}
}
@Test
fun testCharsets() {
var e = parseCalendar("latin1.ics", Charset.forName("ISO-8859-1"))[0]
assertEquals("äöüß", e.summary)
e = parseCalendar("utf8.ics").first()
assertEquals("© äö — üß", e.summary)
assertEquals("中华人民共和国", e.location)
}
fun testParsingCustomTimezone() {
val events = parseCalendar("custom-timezone.ics")
assertEquals(1, events.size)
val e = events.first()
assertEquals("XXX", e.dtStart!!.timeZone.id)
}
@Test
fun testGrouping() {
val events = parseCalendar("multiple.ics")
assertEquals(3, events.size)
var e = findEvent(events, "multiple-0@ical4android.EventTest")
assertEquals("Event 0", e.summary)
assertEquals(0, e.exceptions.size)
e = findEvent(events, "multiple-1@ical4android.EventTest")
assertEquals("Event 1", e.summary)
assertEquals(1, e.exceptions.size)
assertEquals("Event 1 Exception", e.exceptions.first.summary)
e = findEvent(events, "multiple-2@ical4android.EventTest")
assertEquals("Event 2", e.summary)
assertEquals(2, e.exceptions.size)
assertTrue("Event 2 Updated Exception 1" == e.exceptions.first.summary || "Event 2 Updated Exception 1" == e.exceptions[1].summary)
assertTrue("Event 2 Exception 2" == e.exceptions.first.summary || "Event 2 Exception 2" == e.exceptions[1].summary)
}
@Test
fun testParseAndWrite() {
val event = parseCalendar("utf8.ics").first()
assertEquals("utf8@ical4android.EventTest", event.uid)
assertEquals("© äö — üß", event.summary)
assertEquals("Test Description", event.description)
assertEquals("中华人民共和国", event.location)
assertEquals(EventColor.aliceblue, event.color)
}
@Test
fun testRecurringWithException() {
val event = parseCalendar("recurring-with-exception1.ics").first()
assertTrue(event.isAllDay())
assertEquals(1, event.exceptions.size)
val exception = event.exceptions.first
assertEquals("20150503", exception.recurrenceId!!.value)
assertEquals("Another summary for the third day", exception.summary)
}
@Test
fun testStartEndTimes() {
// event with start+end date-time
val eViennaEvolution = parseCalendar("vienna-evolution.ics").first()
assertEquals(1381330800000L, eViennaEvolution.dtStart!!.date.time)
assertEquals("/freeassociation.sourceforge.net/Tzfile/Europe/Vienna", eViennaEvolution.dtStart!!.timeZone.id)
assertEquals(1381334400000L, eViennaEvolution.dtEnd!!.date.time)
assertEquals("/freeassociation.sourceforge.net/Tzfile/Europe/Vienna", eViennaEvolution.dtEnd!!.timeZone.id)
}
@Test
fun testStartEndTimesAllDay() {
// event with start date only
val eOnThatDay = parseCalendar("event-on-that-day.ics").first()
assertEquals(868838400000L, eOnThatDay.dtStart!!.date.time)
assertNull(eOnThatDay.dtStart!!.timeZone)
// event with start+end date for all-day event (one day)
val eAllDay1Day = parseCalendar("all-day-1day.ics").first()
assertEquals(868838400000L, eAllDay1Day.dtStart!!.date.time)
assertNull(eAllDay1Day.dtStart!!.timeZone)
assertEquals(868838400000L + 86400000, eAllDay1Day.dtEnd!!.date.time)
assertNull(eAllDay1Day.dtEnd!!.timeZone)
// event with start+end date for all-day event (ten days)
val eAllDay10Days = parseCalendar("all-day-10days.ics").first()
assertEquals(868838400000L, eAllDay10Days.dtStart!!.date.time)