Skip to content

Commit 0ab0d3c

Browse files
committed
Add SequenceProcessor
1 parent 60a1d86 commit 0ab0d3c

4 files changed

Lines changed: 74 additions & 21 deletions

File tree

lib/src/androidTest/kotlin/at/bitfire/synctools/mapping/calendar/LegacyAndroidEventProcessorTest.kt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,6 @@ class LegacyAndroidEventProcessorTest {
141141
}
142142

143143

144-
@Test
145-
fun testPopulateEvent_Sequence_Int() {
146-
populateEvent(true, asSyncAdapter = true) {
147-
put(AndroidEvent2.COLUMN_SEQUENCE, 5)
148-
}.let { result ->
149-
assertEquals(5, result.sequence)
150-
}
151-
}
152-
153-
@Test
154-
fun testPopulateEvent_Sequence_Null() {
155-
populateEvent(true, asSyncAdapter = true) {
156-
putNull(AndroidEvent2.COLUMN_SEQUENCE)
157-
}.let { result ->
158-
assertNull(result.sequence)
159-
}
160-
}
161-
162144
@Test
163145
fun testPopulateEvent_NonAllDay_NonRecurring() {
164146
populateEvent(false) {

lib/src/main/kotlin/at/bitfire/synctools/mapping/calendar/LegacyAndroidEventProcessor.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ import at.bitfire.synctools.mapping.calendar.processor.LocationProcessor
2727
import at.bitfire.synctools.mapping.calendar.processor.MutatorsProcessor
2828
import at.bitfire.synctools.mapping.calendar.processor.OrganizerProcessor
2929
import at.bitfire.synctools.mapping.calendar.processor.RemindersProcessor
30+
import at.bitfire.synctools.mapping.calendar.processor.SequenceProcessor
3031
import at.bitfire.synctools.mapping.calendar.processor.StatusProcessor
3132
import at.bitfire.synctools.mapping.calendar.processor.TitleProcessor
3233
import at.bitfire.synctools.mapping.calendar.processor.UidProcessor
3334
import at.bitfire.synctools.mapping.calendar.processor.UnknownPropertiesProcessor
3435
import at.bitfire.synctools.mapping.calendar.processor.UrlProcessor
35-
import at.bitfire.synctools.storage.calendar.AndroidEvent2
3636
import at.bitfire.synctools.storage.calendar.EventAndExceptions
3737
import net.fortuna.ical4j.model.Date
3838
import net.fortuna.ical4j.model.DateList
@@ -86,6 +86,7 @@ class LegacyAndroidEventProcessor(
8686
AvailabilityProcessor(),
8787
StatusProcessor(),
8888
// scheduling
89+
SequenceProcessor(),
8990
OrganizerProcessor(),
9091
AttendeesProcessor(),
9192
// extended properties
@@ -245,8 +246,6 @@ class LegacyAndroidEventProcessor(
245246
logger.log(Level.WARNING, "Couldn't parse recurrence rules, ignoring", e)
246247
}
247248

248-
to.sequence = row.getAsInteger(AndroidEvent2.COLUMN_SEQUENCE)
249-
250249
// exceptions from recurring events
251250
row.getAsLong(Events.ORIGINAL_INSTANCE_TIME)?.let { originalInstanceTime ->
252251
val originalAllDay = (row.getAsInteger(Events.ORIGINAL_ALL_DAY) ?: 0) != 0
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* This file is part of bitfireAT/synctools which is released under GPLv3.
3+
* Copyright © All Contributors. See the LICENSE and AUTHOR files in the root directory for details.
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*/
6+
7+
package at.bitfire.synctools.mapping.calendar.processor
8+
9+
import android.content.Entity
10+
import at.bitfire.ical4android.Event
11+
import at.bitfire.synctools.storage.calendar.AndroidEvent2
12+
13+
class SequenceProcessor: AndroidEventFieldProcessor {
14+
15+
override fun process(from: Entity, main: Entity, to: Event) {
16+
to.sequence = from.entityValues.getAsInteger(AndroidEvent2.COLUMN_SEQUENCE)
17+
}
18+
19+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* This file is part of bitfireAT/synctools which is released under GPLv3.
3+
* Copyright © All Contributors. See the LICENSE and AUTHOR files in the root directory for details.
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*/
6+
7+
package at.bitfire.synctools.mapping.calendar.processor
8+
9+
import android.content.ContentValues
10+
import android.content.Entity
11+
import androidx.core.content.contentValuesOf
12+
import at.bitfire.ical4android.Event
13+
import at.bitfire.synctools.storage.calendar.AndroidEvent2
14+
import org.junit.Assert.assertEquals
15+
import org.junit.Assert.assertNull
16+
import org.junit.Test
17+
import org.junit.runner.RunWith
18+
import org.robolectric.RobolectricTestRunner
19+
20+
@RunWith(RobolectricTestRunner::class)
21+
class SequenceProcessorTest {
22+
23+
private val processor = SequenceProcessor()
24+
25+
@Test
26+
fun `No sequence`() {
27+
val result = Event()
28+
val entity = Entity(ContentValues())
29+
processor.process(entity, entity, result)
30+
assertNull(result.sequence)
31+
}
32+
33+
@Test
34+
fun `Sequence is 0`() {
35+
val entity = Entity(contentValuesOf(
36+
AndroidEvent2.COLUMN_SEQUENCE to 0
37+
))
38+
val result = Event()
39+
processor.process(entity, entity, result)
40+
assertEquals(0, result.sequence)
41+
}
42+
43+
@Test
44+
fun `Sequence is 1`() {
45+
val entity = Entity(contentValuesOf(
46+
AndroidEvent2.COLUMN_SEQUENCE to 1
47+
))
48+
val result = Event()
49+
processor.process(entity, entity, result)
50+
assertEquals(1, result.sequence)
51+
}
52+
53+
}

0 commit comments

Comments
 (0)