From 7807e31b22706d8afc142c03121c856f9e9086a3 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 3 Jun 2026 09:11:59 -0400 Subject: [PATCH] fix(android): testOptions isReturnDefaultValues = true MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unit tests touching Android framework statics (Bundle.EMPTY, android.os.Bundle constructor in MediaItem/SessionCommand construction) failed with NPE/ExceptionInInitializerError because JVM unit tests run against android.jar's stub classes whose methods throw "Method ... not mocked" by default. Enable isReturnDefaultValues so stub methods return defaults — Bundle.EMPTY ends up null and is fine because we just thread it through SessionCommand without inspecting it. Fixes LikeMediaCallbackTest's 5 failures on run #311. Lightweight — no Robolectric, no androidTest. The first JVM-side test file in the project to touch Android framework classes. --- android/app/build.gradle.kts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 4e72d441..628b03b1 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -80,6 +80,19 @@ android { buildConfig = true } + testOptions { + unitTests { + // JVM unit tests run against android.jar's stub methods, + // which throw `RuntimeException("Method ... not mocked")` + // when touched (including statics like Bundle.EMPTY). + // Return defaults instead so tests that pass Bundles + // through without inspecting them (e.g. SessionCommand + // construction in LikeMediaCallbackTest) just work, + // without dragging in Robolectric. + isReturnDefaultValues = true + } + } + packaging { resources.excludes += setOf(