|
| 1 | +package com.fsck.k9.activity |
| 2 | + |
| 3 | +import assertk.assertThat |
| 4 | +import assertk.assertions.isSameInstanceAs |
| 5 | +import kotlinx.coroutines.flow.Flow |
| 6 | +import net.thunderbird.core.android.account.AccountRemovedListener |
| 7 | +import net.thunderbird.core.android.account.AccountsChangeListener |
| 8 | +import net.thunderbird.core.android.account.LegacyAccountDto |
| 9 | +import net.thunderbird.core.android.account.LegacyAccountDtoManager |
| 10 | +import net.thunderbird.feature.search.legacy.LocalMessageSearch |
| 11 | +import org.junit.Test |
| 12 | + |
| 13 | +class MessageHomeAccountSelectorTest { |
| 14 | + private val firstAccount = LegacyAccountDto("11111111-1111-1111-1111-111111111111") |
| 15 | + private val secondAccount = LegacyAccountDto("22222222-2222-2222-2222-222222222222") |
| 16 | + private val accountManager = FakeLegacyAccountDtoManager(firstAccount, secondAccount) |
| 17 | + |
| 18 | + @Test |
| 19 | + fun `single-account search should replace current account`() { |
| 20 | + val search = LocalMessageSearch().apply { |
| 21 | + addAccountUuid(secondAccount.uuid) |
| 22 | + } |
| 23 | + |
| 24 | + val account = search.resolveAccount( |
| 25 | + currentAccount = firstAccount, |
| 26 | + accountManager = accountManager, |
| 27 | + ) |
| 28 | + |
| 29 | + assertThat(account).isSameInstanceAs(secondAccount) |
| 30 | + } |
| 31 | + |
| 32 | + private class FakeLegacyAccountDtoManager( |
| 33 | + vararg accounts: LegacyAccountDto, |
| 34 | + ) : LegacyAccountDtoManager { |
| 35 | + private val accounts = accounts.associateBy { it.uuid } |
| 36 | + |
| 37 | + override fun getAccounts(): List<LegacyAccountDto> = accounts.values.toList() |
| 38 | + |
| 39 | + override fun getAccountsFlow(): Flow<List<LegacyAccountDto>> = error("Not implemented") |
| 40 | + |
| 41 | + override fun getAccount(accountUuid: String): LegacyAccountDto? = accounts[accountUuid] |
| 42 | + |
| 43 | + override fun getAccountFlow(accountUuid: String): Flow<LegacyAccountDto?> = error("Not implemented") |
| 44 | + |
| 45 | + override fun addAccountRemovedListener(listener: AccountRemovedListener) = error("Not implemented") |
| 46 | + |
| 47 | + override fun moveAccount(account: LegacyAccountDto, newPosition: Int) = error("Not implemented") |
| 48 | + |
| 49 | + override fun addOnAccountsChangeListener(accountsChangeListener: AccountsChangeListener) = |
| 50 | + error("Not implemented") |
| 51 | + |
| 52 | + override fun removeOnAccountsChangeListener(accountsChangeListener: AccountsChangeListener) = |
| 53 | + error("Not implemented") |
| 54 | + |
| 55 | + override fun saveAccount(account: LegacyAccountDto) = error("Not implemented") |
| 56 | + } |
| 57 | +} |
0 commit comments