From 634a318fdfd5f6369233fb95820e863c4e1d1029 Mon Sep 17 00:00:00 2001 From: Satoshi Qazi Muhammed Date: Fri, 10 Jul 2026 14:24:20 -0700 Subject: [PATCH] fix: unnecessary stubbing + missing assertTrue import in Tron backfill test @Before's preferences.getBoolean stub was never invoked by migrate()-only tests (only migrationNeeded() reads that preference), tripping Mockito's strict-stubs UnnecessaryStubbingException across the whole class. Moved it into a dedicated migrationNeeded() test, matched via any() rather than the production class's private preference-key constant (which isn't visible here), and added the missing assertTrue import. --- .../migration/TronAddressBackfillMigrationTest.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/feature-account-impl/src/test/java/io/novafoundation/nova/feature_account_impl/data/repository/datasource/migration/TronAddressBackfillMigrationTest.kt b/feature-account-impl/src/test/java/io/novafoundation/nova/feature_account_impl/data/repository/datasource/migration/TronAddressBackfillMigrationTest.kt index 96ccef2f..3c1f4c50 100644 --- a/feature-account-impl/src/test/java/io/novafoundation/nova/feature_account_impl/data/repository/datasource/migration/TronAddressBackfillMigrationTest.kt +++ b/feature-account-impl/src/test/java/io/novafoundation/nova/feature_account_impl/data/repository/datasource/migration/TronAddressBackfillMigrationTest.kt @@ -17,6 +17,7 @@ import io.novasama.substrate_sdk_android.encrypt.json.JsonDecoder import io.novasama.substrate_sdk_android.encrypt.mnemonic.MnemonicCreator import io.novasama.substrate_sdk_android.scale.EncodableStruct import kotlinx.coroutines.runBlocking +import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -79,10 +80,18 @@ class TronAddressBackfillMigrationTest { // Real factory, not a mock - the whole point of this test is to exercise the actual derivation. val accountSecretsFactory = AccountSecretsFactory(jsonDecoder) subject = TronAddressBackfillMigration(preferences, secretStoreV2, metaAccountDao, accountSecretsFactory) + } - // any() would try to unbox a null placeholder into the primitive Boolean parameter and crash - Mockito's - // own anyBoolean() returns a real `false` default instead, avoiding that entirely. + @Test + fun `migrationNeeded should reflect the persisted flag`(): Unit = runBlocking { + // The flag's preference key is a private implementation detail of the production class - matched via + // any() here rather than duplicating the literal key string, which would let this test pass even if + // that string silently drifted out of sync with the production code. whenever(preferences.getBoolean(any(), Mockito.anyBoolean())).thenReturn(false) + assertTrue(subject.migrationNeeded()) + + whenever(preferences.getBoolean(any(), Mockito.anyBoolean())).thenReturn(true) + assertTrue(!subject.migrationNeeded()) } @Test