Modern Apps git

← Modern-Apps.git

email: add test seams to EmailWidget and OutlookOAuth

Commit
97852912f7c5e6b5ac4c7c06aa6aa64eb218e32d
Author
Vayun Mathur <[email protected]>
When
2026-11-07 19:29 UTC (28 days ago)
Parents
63c0038
Behavior-preserving testability seams, defaults unchanged:

- EmailWidget.loadData/previewData/Content widened from protected to public so Robolectric/Glance unit tests can drive the widget data layer directly; the framework still calls them only via provideGlance/providePreview.

- OutlookOAuth.tokenEndpointOverride (internal, default null) lets tests point token POSTs at a local fake Microsoft endpoint; production always uses the real endpoint when null.

(cherry picked from commit 45b12a6675c9f67f5febc60ba4e49d87d3c806d4)

Diff

email/src/main/java/com/vayunmathur/email/data/OutlookOAuth.kt
diff --git a/email/src/main/java/com/vayunmathur/email/data/OutlookOAuth.kt b/email/src/main/java/com/vayunmathur/email/data/OutlookOAuth.ktindex 83e1ba99a2..584be0b64c 100644--- a/email/src/main/java/com/vayunmathur/email/data/OutlookOAuth.kt+++ b/email/src/main/java/com/vayunmathur/email/data/OutlookOAuth.kt@@ -71,6 +71,13 @@ object OutlookOAuth {      private val json = Json { ignoreUnknownKeys = true } +    /**+     * Test seam: when set, token POSTs go to this endpoint instead of+     * Microsoft's. Null (the default everywhere in production) keeps the+     * real endpoint; tests point it at a local fake token server.+     */+    internal var tokenEndpointOverride: String? = null+     fun isConfigured(): Boolean = BuildConfig.OUTLOOK_OAUTH_CLIENT_ID.isNotBlank()      fun start(context: Context, emailHint: String = "") {@@ -316,7 +323,7 @@ object OutlookOAuth {      private fun postTokenForm(form: Map<String, String>): Pair<Int, String> {         val body = form.entries.joinToString("&") { "${Uri.encode(it.key)}=${Uri.encode(it.value)}" }-        val conn = (URL(TOKEN_ENDPOINT).openConnection() as HttpURLConnection).apply {+        val conn = (URL(tokenEndpointOverride ?: TOKEN_ENDPOINT).openConnection() as HttpURLConnection).apply {             requestMethod = "POST"             doOutput = true             connectTimeout = TOKEN_TIMEOUT_MS
email/src/main/java/com/vayunmathur/email/widget/EmailWidget.kt
diff --git a/email/src/main/java/com/vayunmathur/email/widget/EmailWidget.kt b/email/src/main/java/com/vayunmathur/email/widget/EmailWidget.ktindex 631baf2bf7..b110036aaf 100644--- a/email/src/main/java/com/vayunmathur/email/widget/EmailWidget.kt+++ b/email/src/main/java/com/vayunmathur/email/widget/EmailWidget.kt@@ -51,7 +51,9 @@ class EmailWidget : MaWidget<List<EmailPreview>>() {         private const val WIDGET_PEEK_LEN = 50     } -    override suspend fun loadData(context: Context, id: GlanceId): List<EmailPreview> {+    // Widened from MaWidget's protected so unit tests can drive the data+    // layer directly; the framework only ever calls it via provideGlance.+    public override suspend fun loadData(context: Context, id: GlanceId): List<EmailPreview> {         // Query the database directly for recent messages.         // No read status indicators, so widget doesn't need to refresh on read changes.         return withContext(Dispatchers.IO) {@@ -64,7 +66,7 @@ class EmailWidget : MaWidget<List<EmailPreview>>() {         }     } -    override fun previewData(context: Context): List<EmailPreview> = listOf(+    public override fun previewData(context: Context): List<EmailPreview> = listOf(         EmailPreview(             accountEmail = "[email protected]", folderName = "INBOX", id = 1,             subject = "Lunch tomorrow?", from = "Alex Johnson <[email protected]>",@@ -83,7 +85,7 @@ class EmailWidget : MaWidget<List<EmailPreview>>() {     )      @Composable-    override fun Content(data: List<EmailPreview>) {+    public override fun Content(data: List<EmailPreview>) {         EmailWidgetContent(data)     }