Skip to content
This repository was archived by the owner on May 26, 2026. It is now read-only.

Commit 73c9974

Browse files
committed
Implement CompletedHandler with unit test
1 parent e363bfa commit 73c9974

3 files changed

Lines changed: 66 additions & 3 deletions

File tree

lib/src/main/kotlin/at/bitfire/synctools/mapping/tasks/DmfsTaskProcessor.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import at.bitfire.ical4android.UnknownProperty
1212
import at.bitfire.ical4android.util.TimeApiExtensions.toLocalDate
1313
import at.bitfire.synctools.mapping.tasks.handler.AlarmsHandler
1414
import at.bitfire.synctools.mapping.tasks.handler.ClassificationHandler
15+
import at.bitfire.synctools.mapping.tasks.handler.CompletedHandler
1516
import at.bitfire.synctools.mapping.tasks.handler.DmfsTaskFieldHandler
1617
import at.bitfire.synctools.mapping.tasks.handler.DmfsTaskPropertyHandler
1718
import at.bitfire.synctools.mapping.tasks.handler.PriorityHandler
@@ -24,7 +25,6 @@ import at.bitfire.synctools.storage.tasks.DmfsTaskList
2425
import at.bitfire.synctools.util.AndroidTimeUtils
2526
import net.fortuna.ical4j.model.TimeZoneRegistryFactory
2627
import net.fortuna.ical4j.model.parameter.RelType
27-
import net.fortuna.ical4j.model.property.Completed
2828
import net.fortuna.ical4j.model.property.DtStart
2929
import net.fortuna.ical4j.model.property.Due
3030
import net.fortuna.ical4j.model.property.Duration
@@ -41,7 +41,6 @@ import org.dmfs.tasks.contract.TaskContract.Property.Comment
4141
import org.dmfs.tasks.contract.TaskContract.Property.Relation
4242
import org.dmfs.tasks.contract.TaskContract.Tasks
4343
import java.net.URISyntaxException
44-
import java.time.Instant
4544
import java.time.temporal.Temporal
4645
import java.util.logging.Level
4746
import java.util.logging.Logger
@@ -61,6 +60,7 @@ class DmfsTaskProcessor(
6160
PriorityHandler(),
6261
ClassificationHandler(),
6362
StatusHandler(),
63+
CompletedHandler(),
6464
)
6565

6666
private val propertyHandlers: Map<String, DmfsTaskPropertyHandler> = mapOf(
@@ -100,7 +100,6 @@ class DmfsTaskProcessor(
100100

101101
// Note: big method – maybe split? Depends on how we want to proceed with refactoring.
102102

103-
values.getAsLong(Tasks.COMPLETED)?.let { to.completedAt = Completed(Instant.ofEpochMilli(it)) }
104103
values.getAsInteger(Tasks.PERCENT_COMPLETE)?.let { to.percentComplete = it }
105104

106105
val allDay = (values.getAsInteger(Tasks.IS_ALLDAY) ?: 0) != 0
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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.tasks.handler
8+
9+
import android.content.ContentValues
10+
import at.bitfire.ical4android.Task
11+
import net.fortuna.ical4j.model.property.Completed
12+
import org.dmfs.tasks.contract.TaskContract.Tasks
13+
import java.time.Instant
14+
15+
class CompletedHandler : DmfsTaskFieldHandler {
16+
17+
override fun process(from: ContentValues, to: Task) {
18+
from.getAsLong(Tasks.COMPLETED)?.let { epochMillis ->
19+
to.completedAt = Completed(Instant.ofEpochMilli(epochMillis))
20+
}
21+
}
22+
23+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.tasks.handler
8+
9+
import android.content.ContentValues
10+
import androidx.core.content.contentValuesOf
11+
import at.bitfire.ical4android.Task
12+
import net.fortuna.ical4j.model.property.Completed
13+
import org.dmfs.tasks.contract.TaskContract.Tasks
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+
import java.time.Instant
20+
21+
@RunWith(RobolectricTestRunner::class)
22+
class CompletedHandlerTest {
23+
24+
private val handler = CompletedHandler()
25+
26+
@Test
27+
fun `No COMPLETED leaves completedAt null`() {
28+
val task = Task()
29+
handler.process(ContentValues(), task)
30+
assertNull(task.completedAt)
31+
}
32+
33+
@Test
34+
fun `COMPLETED epoch millis is mapped correctly`() {
35+
val task = Task()
36+
val epochMillis = 1_700_000_000_000L
37+
handler.process(contentValuesOf(Tasks.COMPLETED to epochMillis), task)
38+
assertEquals(Completed(Instant.ofEpochMilli(epochMillis)), task.completedAt)
39+
}
40+
41+
}

0 commit comments

Comments
 (0)