Skip to content

[Test Improver] Add unit tests for ConnectDateUtils date parsingΒ #3600

@github-actions

Description

@github-actions

πŸ€– Test Improver β€” automated AI assistant

Goal and Rationale

ConnectDateUtils.kt contains date parsing logic used across ConnectID features:

  • convertIsoDate() β€” strips fractional seconds, normalises +00:00 β†’ Z, parses ISO 8601 strings, and formats output. Date parsing bugs here can cause data display issues or crashes.
  • parseIsoDateForSorting() β€” parses ISO dates for chronological ordering; returns null on failure.

Neither function had any test coverage. This PR adds targeted tests for the non-trivial parsing branches.

Approach

New test class: app/unit-tests/src/org/commcare/connect/ConnectDateUtilsTest.kt

convertIsoDate tests:

  • Valid standard ISO format parses without error
  • Fractional seconds (.123456) are stripped before parsing; result matches clean version
  • +00:00 offset is normalised to Z; result matches Z version
  • Empty string throws IllegalArgumentException (guarded by require)
  • Invalid format throws ParseException
  • outputStyle parameter is respected (SHORT ≀ MEDIUM length)
  • Same input produces identical output (no hidden state)

parseIsoDateForSorting tests:

  • Valid ISO string returns a non-null Date
  • Empty string returns null
  • Invalid string returns null (swallows ParseException)
  • Parsed epoch matches reference parse result (UTC correctness)
  • Earlier date sorts before later date

Coverage Impact

No baseline numbers available (commcare-core sibling not present in this environment; coverage runs via CI JaCoCo). Both methods were previously untested.

Trade-offs

  • Tests focus on the parsing/cleaning logic only; formatNotificationTime (which requires Context string resources) is left for a follow-up.
  • Output format assertions use relative comparisons (e.g., SHORT length ≀ MEDIUM) to avoid locale fragility.

Test Status

Build not runnable locally (requires ../commcare-core sibling directory, checked out only in CI). Tests follow existing patterns from ConnectReleaseTogglesParserTest and FileUtilTest and should compile and pass in CI.

To run:

./gradlew testCommcareDebug --tests "org.commcare.connect.ConnectDateUtilsTest"

Generated by Daily Test Improver Β· β—·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/daily-test-improver.md@346204513ecfa08b81566450d7d599556807389f

Note

This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch test-assist/connect-date-utils-tests-20a1a4ae812e4ee6.

Click here to create the pull request

To fix the permissions issue, go to Settings β†’ Actions β†’ General and enable Allow GitHub Actions to create and approve pull requests.

Show patch preview (138 of 138 lines)
From 44bbb0880c70e12be8a3a6d8a3920fe7b83cdc2c Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Wed, 11 Mar 2026 15:34:44 +0000
Subject: [PATCH] [AI] Add unit tests for ConnectDateUtils date parsing methods

Tests cover:
- convertIsoDate: fractional seconds stripping, +00:00 normalization,
  empty input rejection, invalid format handling, output style parameter
- parseIsoDateForSorting: null on empty/invalid input, correct UTC epoch,
  chronological ordering

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---
 .../commcare/connect/ConnectDateUtilsTest.kt  | 111 ++++++++++++++++++
 1 file changed, 111 insertions(+)
 create mode 100644 app/unit-tests/src/org/commcare/connect/ConnectDateUtilsTest.kt

diff --git a/app/unit-tests/src/org/commcare/connect/ConnectDateUtilsTest.kt b/app/unit-tests/src/org/commcare/connect/ConnectDateUtilsTest.kt
new file mode 100644
index 0000000..b56b6b3
--- /dev/null
+++ b/app/unit-tests/src/org/commcare/connect/ConnectDateUtilsTest.kt
@@ -0,0 +1,111 @@
+package org.commcare.connect
+
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import org.commcare.CommCareTestApplication
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNotNull
+import org.junit.Assert.assertNull
+import org.junit.Assert.assertTrue
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.annotation.Config
+import java.text.DateFormat
+import java.text.ParseException
+import java.text.SimpleDateFormat
+import java.util.Locale
+import java.util.TimeZone
+
+@Config(application = CommCareTestApplication::class)
+@RunWith(AndroidJUnit4::class)
+class ConnectDateUtilsTest {
+
+    // ── convertIsoDate ──────────────────────────────────────────────────────
+
+    @Test
+    fun convertIsoDate_validStandardFormat_returnsParsedDate() {
+        val result = ConnectDateUtils.convertIsoDate("2024-06-15T10:30:00Z")
+        assertNotNull(result)
+        assertTrue(
... (truncated)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions