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

Commit 2bac41d

Browse files
committed
Implement PercentCompleteHandler with unit test
1 parent 73c9974 commit 2bac41d

3 files changed

Lines changed: 68 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import at.bitfire.synctools.mapping.tasks.handler.ClassificationHandler
1515
import at.bitfire.synctools.mapping.tasks.handler.CompletedHandler
1616
import at.bitfire.synctools.mapping.tasks.handler.DmfsTaskFieldHandler
1717
import at.bitfire.synctools.mapping.tasks.handler.DmfsTaskPropertyHandler
18+
import at.bitfire.synctools.mapping.tasks.handler.PercentCompleteHandler
1819
import at.bitfire.synctools.mapping.tasks.handler.PriorityHandler
1920
import at.bitfire.synctools.mapping.tasks.handler.SequenceHandler
2021
import at.bitfire.synctools.mapping.tasks.handler.StatusHandler
@@ -61,6 +62,7 @@ class DmfsTaskProcessor(
6162
ClassificationHandler(),
6263
StatusHandler(),
6364
CompletedHandler(),
65+
PercentCompleteHandler(),
6466
)
6567

6668
private val propertyHandlers: Map<String, DmfsTaskPropertyHandler> = mapOf(
@@ -100,8 +102,6 @@ class DmfsTaskProcessor(
100102

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

103-
values.getAsInteger(Tasks.PERCENT_COMPLETE)?.let { to.percentComplete = it }
104-
105105
val allDay = (values.getAsInteger(Tasks.IS_ALLDAY) ?: 0) != 0
106106

107107
val tzID = values.getAsString(Tasks.TZ)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 org.dmfs.tasks.contract.TaskContract.Tasks
12+
13+
class PercentCompleteHandler : DmfsTaskFieldHandler {
14+
15+
override fun process(from: ContentValues, to: Task) {
16+
from.getAsInteger(Tasks.PERCENT_COMPLETE)?.let { percent ->
17+
to.percentComplete = percent
18+
}
19+
}
20+
21+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 org.dmfs.tasks.contract.TaskContract.Tasks
13+
import org.junit.Assert.assertEquals
14+
import org.junit.Assert.assertNull
15+
import org.junit.Test
16+
import org.junit.runner.RunWith
17+
import org.robolectric.RobolectricTestRunner
18+
19+
@RunWith(RobolectricTestRunner::class)
20+
class PercentCompleteHandlerTest {
21+
22+
private val handler = PercentCompleteHandler()
23+
24+
@Test
25+
fun `No PERCENT_COMPLETE leaves percentComplete null`() {
26+
val task = Task()
27+
handler.process(ContentValues(), task)
28+
assertNull(task.percentComplete)
29+
}
30+
31+
@Test
32+
fun `PERCENT_COMPLETE 0 is mapped correctly`() {
33+
val task = Task()
34+
handler.process(contentValuesOf(Tasks.PERCENT_COMPLETE to 0), task)
35+
assertEquals(0, task.percentComplete)
36+
}
37+
38+
@Test
39+
fun `PERCENT_COMPLETE 100 is mapped correctly`() {
40+
val task = Task()
41+
handler.process(contentValuesOf(Tasks.PERCENT_COMPLETE to 100), task)
42+
assertEquals(100, task.percentComplete)
43+
}
44+
45+
}

0 commit comments

Comments
 (0)