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

Commit 2ba308e

Browse files
committed
Add test for COMPLETED without timezone not throwing
ClassCastException
1 parent 6873bfc commit 2ba308e

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

lib/src/test/kotlin/at/bitfire/synctools/mapping/tasks/builder/CompletedBuilderTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import org.junit.Test
1717
import org.junit.runner.RunWith
1818
import org.robolectric.RobolectricTestRunner
1919
import java.time.Instant
20+
import java.time.LocalDateTime
21+
import java.time.ZoneId
2022

2123
@RunWith(RobolectricTestRunner::class)
2224
class CompletedBuilderTest {
@@ -50,4 +52,22 @@ class CompletedBuilderTest {
5052
), result.entityValues)
5153
}
5254

55+
@Test
56+
fun `COMPLETED is floating LocalDateTime`() {
57+
// COMPLETED without timezone (floating) must not crash with ClassCastException
58+
// A floating COMPLETED is represented as a string without 'Z' (e.g. "20240601T120000")
59+
val result = Entity(ContentValues())
60+
builder.build(
61+
from = Task(completedAt = Completed("20240601T120000")),
62+
to = result
63+
)
64+
// floating date-time is interpreted in system default timezone
65+
val expectedTimestamp = LocalDateTime.of(2024, 6, 1, 12, 0, 0)
66+
.atZone(ZoneId.systemDefault()).toInstant().epochSecond * 1000
67+
assertContentValuesEqual(contentValuesOf(
68+
Tasks.COMPLETED to expectedTimestamp,
69+
Tasks.COMPLETED_IS_ALLDAY to 0
70+
), result.entityValues)
71+
}
72+
5373
}

0 commit comments

Comments
 (0)