Skip to content

Commit 70837ab

Browse files
authored
Fix tests and use Duration for time calculations in AndroidCalendarTest (#321)
1 parent 80e9902 commit 70837ab

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

lib/src/androidTest/kotlin/at/bitfire/synctools/storage/calendar/AndroidCalendarTest.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ class AndroidCalendarTest {
140140
// Add multiple events and test counting
141141
calendar.addEvent(Entity(contentValuesOf(
142142
Events.CALENDAR_ID to calendar.id,
143-
Events.DTSTART to now,
144-
Events.DTEND to now + 3600000,
143+
Events.DTSTART to testStartMillis,
144+
Events.DTEND to (testStartTime + Duration.ofHours(1)).toEpochMilli(),
145145
Events.TITLE to "Event 1"
146146
)))
147147
calendar.addEvent(Entity(contentValuesOf(
148148
Events.CALENDAR_ID to calendar.id,
149-
Events.DTSTART to now + 3600000,
150-
Events.DTEND to now + 3600000*2,
149+
Events.DTSTART to (testStartTime + Duration.ofHours(1)).toEpochMilli(),
150+
Events.DTEND to (testStartTime + Duration.ofHours(2)).toEpochMilli(),
151151
Events.TITLE to "Event 2"
152152
)))
153153

@@ -160,18 +160,19 @@ class AndroidCalendarTest {
160160
// Test counting with WHERE clause
161161
calendar.addEvent(Entity(contentValuesOf(
162162
Events.CALENDAR_ID to calendar.id,
163-
Events.DTSTART to now,
164-
Events.DTEND to now + 3600000,
163+
Events.DTSTART to testStartMillis,
164+
Events.DTEND to (testStartTime + Duration.ofHours(1)).toEpochMilli(),
165165
Events.TITLE to "Filter Test 1"
166166
)))
167167
calendar.addEvent(Entity(contentValuesOf(
168168
Events.CALENDAR_ID to calendar.id,
169-
Events.DTSTART to now + 3600000,
170-
Events.DTEND to now + 3600000*2,
169+
Events.DTSTART to (testStartTime + Duration.ofHours(1)).toEpochMilli(),
170+
Events.DTEND to (testStartTime + Duration.ofHours(2)).toEpochMilli(),
171171
Events.TITLE to "Filter Test 2"
172172
)))
173173

174-
val filteredCount = calendar.countEvents("${Events.DTSTART}=?", arrayOf(now.toString()))
174+
val filteredCount = calendar.countEvents("${Events.DTSTART}=?",
175+
arrayOf(testStartMillis.toString()))
175176
assertEquals(1, filteredCount)
176177
}
177178

@@ -180,12 +181,13 @@ class AndroidCalendarTest {
180181
// Test counting with filter that matches nothing
181182
calendar.addEvent(Entity(contentValuesOf(
182183
Events.CALENDAR_ID to calendar.id,
183-
Events.DTSTART to now,
184-
Events.DTEND to now + 3600000,
184+
Events.DTSTART to testStartMillis,
185+
Events.DTEND to (testStartTime + Duration.ofHours(1)).toEpochMilli(),
185186
Events.TITLE to "Test Event"
186187
)))
187188

188-
val noMatchCount = calendar.countEvents("${Events.DTSTART}=?", arrayOf((now + 86400000).toString()))
189+
val noMatchCount = calendar.countEvents("${Events.DTSTART}=?",
190+
arrayOf((testStartTime + Duration.ofHours(24)).toEpochMilli().toString()))
189191
assertEquals(0, noMatchCount)
190192
}
191193

0 commit comments

Comments
 (0)