Commit 4a97277
refactor: Current time millis cleanup (#222)
* feat: add TestTimeConstants for deterministic test times
Creates TestTimeConstants object with STANDARD_TEST_TIME (June 15, 2026 noon UTC)
to replace System.currentTimeMillis() in tests. This prevents flaky tests caused
by midnight/boundary crossing issues.
Part of System.currentTimeMillis() removal effort - see docs/dev_todo/system_current_time_millis_removal.md
Co-authored-by: wharris <wharris@upscalews.com>
* refactor: update test fixtures to use TestTimeConstants
- MockTimeProvider: use STANDARD_TEST_TIME as default
- UITestFixture/UITestFixtureRobolectric: use constant in event creation
- BaseCalendarTestFixture/CalendarProviderTestFixture: use constant for clock reset
- MockContextProvider: use timeProvider instead of System.currentTimeMillis()
- MockDismissedEventsStorage: use constant for timestamp defaults
Co-authored-by: wharris <wharris@upscalews.com>
* refactor: remove System.currentTimeMillis() from Robolectric tests
Updated test files to use TestTimeConstants.STANDARD_TEST_TIME:
- DateTimeUtilsTest.kt
- FilterStateTest.kt
- MonitorEventAlertEntryPreMutedTest.kt
- CalendarIntentsRobolectricTest.kt
- ViewEventActivityStateTest.kt
- UpcomingEventsLookaheadTest.kt
- TagsManagerRobolectricTest.kt
Co-authored-by: wharris <wharris@upscalews.com>
* refactor: remove System.currentTimeMillis() from instrumentation tests
Updated test files to use TestTimeConstants.STANDARD_TEST_TIME:
- EventDismissTest.kt
- PreDismissIntegrationTest.kt
- PreSnoozeIntegrationTest.kt
- PreMuteIntegrationTest.kt
- ApplicationControllerCoreTest.kt
- TagsManagerTest.kt
- CalendarMonitorServiceTest.kt
- CalendarMonitorServiceTestFirstScanEver.kt
- CalendarMonitorServiceEventReminderTest.kt
- RoomCrSqlitePocTest.kt
Co-authored-by: wharris <wharris@upscalews.com>
* refactor: remove System.currentTimeMillis() from production code
- SettingsBackupManager: inject CNPlusClockInterface with CNPlusSystemClock default
- TestActivity: use existing clock property for unique title generation
Co-authored-by: wharris <wharris@upscalews.com>
* docs: mark System.currentTimeMillis() removal as complete
- Update plan doc status to COMPLETED
- Add repo rule: Never use System.currentTimeMillis() directly
- Document verification results
Co-authored-by: wharris <wharris@upscalews.com>
* fix: use clock provider pattern in UpcomingEventsFragment
- Change hardcoded CNPlusSystemClock to use getClock() like ActiveEventsFragment
- Add testClock to UITestFixtureRobolectric
- Inject testClock into both ActiveEventsFragment and UpcomingEventsFragment
This ensures tests using TestTimeConstants.STANDARD_TEST_TIME have consistent
time across fixture event creation and fragment filtering logic.
Co-authored-by: wharris <wharris@upscalews.com>
* fix: inject testClock into ApplicationController for instrumented tests
Integration tests were failing because:
1. ApplicationController.clock was hardcoded to use CNPlusSystemClock() (real time)
2. Tests created events with times based on TestTimeConstants.STANDARD_TEST_TIME (June 2026)
3. Time-dependent operations like dismissAllButRecentAndSnoozed compared event times against real system time
Changes:
- Add clockProvider pattern to ApplicationController (similar to UI fragments)
- Add resetClockProvider() method for test cleanup
- Inject testClock into ApplicationController in:
- ApplicationControllerCoreTest
- CalendarMonitorServiceTest
- CalendarMonitorServiceTestFirstScanEver
- CalendarMonitorServiceEventReminderTest
- UITestFixture (for UpcomingEventsFragmentTest)
- Update UITestFixture.mockCalendarProvider to use testClock
Co-authored-by: wharris <wharris@upscalews.com>
* fix: pass testClock to CalendarMonitorManual in testFirstScanEver
CalendarMonitorManual was created without testClock, causing it to use
real system time for scan range calculations while test events used
TestTimeConstants.STANDARD_TEST_TIME. This caused alerts not to be
found in the second scan because the scan range was based on real time.
Co-authored-by: wharris <wharris@upscalews.com>
* feat: change STANDARD_TEST_TIME to December 23, 2023 and fix DismissedEventsFragment clock injection
Address PR review comments:
- Change test time from June 15, 2026 to December 23, 2023 (day before Christmas Eve)
- Add missing DismissedEventsFragment.clockProvider injection in UITestFixture
- Add missing DismissedEventsFragment.clockProvider injection in UITestFixtureRobolectric
- Update docs/dev_todo/system_current_time_millis_removal.md to reflect new date
Co-authored-by: wharris <wharris@upscalews.com>
* fix: correct date to December 25, 2023 (Christmas Day)
Co-authored-by: wharris <wharris@upscalews.com>
* fix: add missing ApplicationController.clockProvider injections
- Add ApplicationController.clockProvider to UITestFixtureRobolectric (bugbot finding)
- Add ApplicationController.resetClockProvider() to UITestFixtureRobolectric cleanup
- Add clock injection to PreMuteIntegrationTest which uses ApplicationController.registerNewEvents()
Thorough audit confirms all test fixtures now have proper clock injection:
- UITestFixture (androidTest): fragments + ApplicationController
- UITestFixtureRobolectric (test): fragments + ApplicationController
- MockApplicationComponents: mocks ApplicationController.clock
- Individual integration tests: inject via clockProvider or MockK
Co-authored-by: wharris <wharris@upscalews.com>
---------
Co-authored-by: Cursor Agent <cursoragent@cursor.com>1 parent e4561b6 commit 4a97277
33 files changed
Lines changed: 436 additions & 93 deletions
File tree
- .cursor/rules
- android/app/src
- androidTest/java/com/github/quarck/calnotify
- app
- database/poc
- deprecated_raw_calendarmonitor
- dismissedeventsstorage
- testutils
- main/java/com/github/quarck/calnotify
- app
- backup
- ui
- test/java/com/github/quarck/calnotify
- app
- calendar
- testutils
- ui
- upcoming
- utils
- docs/dev_todo
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
Lines changed: 14 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | | - | |
| 35 | + | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
40 | 47 | | |
41 | 48 | | |
42 | 49 | | |
| |||
48 | 55 | | |
49 | 56 | | |
50 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
51 | 61 | | |
52 | 62 | | |
53 | 63 | | |
| |||
235 | 245 | | |
236 | 246 | | |
237 | 247 | | |
238 | | - | |
| 248 | + | |
239 | 249 | | |
240 | 250 | | |
241 | 251 | | |
| |||
258 | 268 | | |
259 | 269 | | |
260 | 270 | | |
261 | | - | |
| 271 | + | |
262 | 272 | | |
263 | 273 | | |
264 | 274 | | |
| |||
299 | 309 | | |
300 | 310 | | |
301 | 311 | | |
302 | | - | |
| 312 | + | |
303 | 313 | | |
304 | 314 | | |
305 | 315 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | | - | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
Lines changed: 13 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
| |||
51 | 54 | | |
52 | 55 | | |
53 | 56 | | |
54 | | - | |
| 57 | + | |
55 | 58 | | |
| 59 | + | |
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
59 | 63 | | |
60 | 64 | | |
61 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
62 | 70 | | |
63 | 71 | | |
64 | 72 | | |
65 | 73 | | |
66 | 74 | | |
67 | 75 | | |
68 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
69 | 81 | | |
70 | 82 | | |
71 | 83 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
56 | | - | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
Lines changed: 9 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | | - | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
52 | 54 | | |
53 | | - | |
| 55 | + | |
54 | 56 | | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
58 | | - | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| |||
Lines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
144 | | - | |
| 145 | + | |
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
| |||
231 | 232 | | |
232 | 233 | | |
233 | 234 | | |
234 | | - | |
| 235 | + | |
235 | 236 | | |
236 | 237 | | |
237 | 238 | | |
| |||
278 | 279 | | |
279 | 280 | | |
280 | 281 | | |
281 | | - | |
| 282 | + | |
282 | 283 | | |
283 | 284 | | |
284 | 285 | | |
| |||
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
137 | 142 | | |
138 | 143 | | |
139 | 144 | | |
| |||
622 | 627 | | |
623 | 628 | | |
624 | 629 | | |
625 | | - | |
| 630 | + | |
626 | 631 | | |
627 | 632 | | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
628 | 636 | | |
629 | 637 | | |
630 | 638 | | |
| |||
Lines changed: 10 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
339 | 340 | | |
340 | 341 | | |
341 | 342 | | |
342 | | - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
343 | 347 | | |
344 | 348 | | |
345 | 349 | | |
| |||
775 | 779 | | |
776 | 780 | | |
777 | 781 | | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
778 | 786 | | |
779 | 787 | | |
780 | 788 | | |
| |||
819 | 827 | | |
820 | 828 | | |
821 | 829 | | |
822 | | - | |
| 830 | + | |
823 | 831 | | |
824 | 832 | | |
825 | 833 | | |
| |||
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
341 | 342 | | |
342 | 343 | | |
343 | 344 | | |
344 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
345 | 349 | | |
346 | 350 | | |
347 | 351 | | |
| |||
350 | 354 | | |
351 | 355 | | |
352 | 356 | | |
353 | | - | |
| 357 | + | |
| 358 | + | |
354 | 359 | | |
355 | 360 | | |
356 | 361 | | |
| |||
969 | 974 | | |
970 | 975 | | |
971 | 976 | | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
972 | 981 | | |
973 | 982 | | |
974 | 983 | | |
| |||
0 commit comments