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