diff --git a/app-thunderbird/src/test/kotlin/net/thunderbird/android/unread/UnreadWidgetDataProviderTest.kt b/app-thunderbird/src/test/kotlin/net/thunderbird/android/unread/UnreadWidgetDataProviderTest.kt deleted file mode 100644 index 3206e4c43..000000000 --- a/app-thunderbird/src/test/kotlin/net/thunderbird/android/unread/UnreadWidgetDataProviderTest.kt +++ /dev/null @@ -1,150 +0,0 @@ -package net.thunderbird.android.unread - -import android.content.Context -import assertk.assertThat -import assertk.assertions.isEqualTo -import assertk.assertions.isNull -import com.fsck.k9.Account -import com.fsck.k9.Preferences -import com.fsck.k9.controller.MessageCounts -import com.fsck.k9.controller.MessageCountsProvider -import com.fsck.k9.mailstore.Folder -import com.fsck.k9.mailstore.FolderRepository -import com.fsck.k9.mailstore.FolderType -import com.fsck.k9.search.SearchAccount -import com.fsck.k9.ui.folders.FolderNameFormatter -import com.fsck.k9.ui.messagelist.DefaultFolderProvider -import com.fsck.k9.widget.unread.UnreadWidgetConfiguration -import com.fsck.k9.widget.unread.UnreadWidgetDataProvider -import org.junit.Test -import org.junit.runner.RunWith -import org.koin.test.AutoCloseKoinTest -import org.mockito.kotlin.doReturn -import org.mockito.kotlin.mock -import org.robolectric.RobolectricTestRunner -import org.robolectric.RuntimeEnvironment - -@RunWith(RobolectricTestRunner::class) -class UnreadWidgetDataProviderTest : AutoCloseKoinTest() { - private val context: Context = RuntimeEnvironment.getApplication() - private val account = createAccount() - private val preferences = createPreferences() - private val messageCountsProvider = createMessageCountsProvider() - private val defaultFolderStrategy = createDefaultFolderStrategy() - private val folderRepository = createFolderRepository() - private val folderNameFormatter = createFolderNameFormatter() - private val provider = UnreadWidgetDataProvider( - context, - preferences, - messageCountsProvider, - defaultFolderStrategy, - folderRepository, - folderNameFormatter, - ) - - @Test - fun unifiedInbox() { - val configuration = UnreadWidgetConfiguration( - appWidgetId = 1, - accountUuid = SearchAccount.UNIFIED_INBOX, - folderId = null, - ) - - val widgetData = provider.loadUnreadWidgetData(configuration) - - with(widgetData!!) { - assertThat(title).isEqualTo("Unified Inbox") - assertThat(unreadCount).isEqualTo(SEARCH_ACCOUNT_UNREAD_COUNT) - } - } - - @Test - fun regularAccount() { - val configuration = UnreadWidgetConfiguration( - appWidgetId = 3, - accountUuid = ACCOUNT_UUID, - folderId = null, - ) - - val widgetData = provider.loadUnreadWidgetData(configuration) - - with(widgetData!!) { - assertThat(title).isEqualTo(ACCOUNT_NAME) - assertThat(unreadCount).isEqualTo(ACCOUNT_UNREAD_COUNT) - } - } - - @Test - fun folder() { - val configuration = UnreadWidgetConfiguration(appWidgetId = 4, accountUuid = ACCOUNT_UUID, folderId = FOLDER_ID) - - val widgetData = provider.loadUnreadWidgetData(configuration) - - with(widgetData!!) { - assertThat(title).isEqualTo("$ACCOUNT_NAME - $LOCALIZED_FOLDER_NAME") - assertThat(unreadCount).isEqualTo(FOLDER_UNREAD_COUNT) - } - } - - @Test - fun nonExistentAccount_shouldReturnNull() { - val configuration = UnreadWidgetConfiguration(appWidgetId = 3, accountUuid = "invalid", folderId = null) - - val widgetData = provider.loadUnreadWidgetData(configuration) - - assertThat(widgetData).isNull() - } - - private fun createAccount(): Account = mock { - on { uuid } doReturn ACCOUNT_UUID - on { displayName } doReturn ACCOUNT_NAME - } - - private fun createPreferences(): Preferences = mock { - on { getAccount(ACCOUNT_UUID) } doReturn account - } - - private fun createMessageCountsProvider() = object : MessageCountsProvider { - override fun getMessageCounts(account: Account): MessageCounts { - return MessageCounts(unread = ACCOUNT_UNREAD_COUNT, starred = 0) - } - - override fun getMessageCounts(searchAccount: SearchAccount): MessageCounts { - return MessageCounts(unread = SEARCH_ACCOUNT_UNREAD_COUNT, starred = 0) - } - - override fun getUnreadMessageCount(account: Account, folderId: Long): Int { - return FOLDER_UNREAD_COUNT - } - } - - private fun createDefaultFolderStrategy(): DefaultFolderProvider = mock { - on { getDefaultFolder(account) } doReturn FOLDER_ID - } - - private fun createFolderRepository(): FolderRepository { - return mock { - on { getFolder(account, FOLDER_ID) } doReturn FOLDER - } - } - - private fun createFolderNameFormatter(): FolderNameFormatter = mock { - on { displayName(FOLDER) } doReturn LOCALIZED_FOLDER_NAME - } - - companion object { - const val ACCOUNT_UUID = "00000000-0000-0000-0000-000000000000" - const val ACCOUNT_NAME = "Test account" - const val FOLDER_ID = 23L - const val SEARCH_ACCOUNT_UNREAD_COUNT = 1 - const val ACCOUNT_UNREAD_COUNT = 2 - const val FOLDER_UNREAD_COUNT = 3 - const val LOCALIZED_FOLDER_NAME = "Posteingang" - val FOLDER = Folder( - id = FOLDER_ID, - name = "INBOX", - type = FolderType.INBOX, - isLocalOnly = false, - ) - } -} diff --git a/app/common/src/test/java/com/fsck/k9/widget/unread/FakeCoreResourceProvider.kt b/app/common/src/test/java/com/fsck/k9/widget/unread/FakeCoreResourceProvider.kt new file mode 100644 index 000000000..0a080637b --- /dev/null +++ b/app/common/src/test/java/com/fsck/k9/widget/unread/FakeCoreResourceProvider.kt @@ -0,0 +1,93 @@ +package com.fsck.k9.widget.unread + +import com.fsck.k9.CoreResourceProvider +import com.fsck.k9.notification.PushNotificationState + +class FakeCoreResourceProvider : CoreResourceProvider { + override fun searchUnifiedInboxTitle(): String = "Unified Inbox" + + override fun searchUnifiedInboxDetail(): String = "All messages in unified folders" + + override fun defaultSignature(): String { + throw UnsupportedOperationException("not implemented") + } + + override fun defaultIdentityDescription(): String { + throw UnsupportedOperationException("not implemented") + } + + override fun contactDisplayNamePrefix(): String { + throw UnsupportedOperationException("not implemented") + } + + override fun contactUnknownSender(): String { + throw UnsupportedOperationException("not implemented") + } + + override fun contactUnknownRecipient(): String { + throw UnsupportedOperationException("not implemented") + } + + override fun messageHeaderFrom(): String { + throw UnsupportedOperationException("not implemented") + } + + override fun messageHeaderTo(): String { + throw UnsupportedOperationException("not implemented") + } + + override fun messageHeaderCc(): String { + throw UnsupportedOperationException("not implemented") + } + + override fun messageHeaderDate(): String { + throw UnsupportedOperationException("not implemented") + } + + override fun messageHeaderSubject(): String { + throw UnsupportedOperationException("not implemented") + } + + override fun messageHeaderSeparator(): String { + throw UnsupportedOperationException("not implemented") + } + + override fun noSubject(): String { + throw UnsupportedOperationException("not implemented") + } + + override fun userAgent(): String { + throw UnsupportedOperationException("not implemented") + } + + override fun encryptedSubject(): String { + throw UnsupportedOperationException("not implemented") + } + + override fun replyHeader(sender: String): String { + throw UnsupportedOperationException("not implemented") + } + + override fun replyHeader(sender: String, sentDate: String): String { + throw UnsupportedOperationException("not implemented") + } + + override fun outboxFolderName(): String { + throw UnsupportedOperationException("not implemented") + } + + override val iconPushNotification: Int + get() = throw UnsupportedOperationException("not implemented") + + override fun pushNotificationText(notificationState: PushNotificationState): String { + throw UnsupportedOperationException("not implemented") + } + + override fun pushNotificationInfoText(): String { + throw UnsupportedOperationException("not implemented") + } + + override fun pushNotificationGrantAlarmPermissionText(): String { + throw UnsupportedOperationException("not implemented") + } +} diff --git a/app-k9mail/src/test/kotlin/app/k9mail/unread/UnreadWidgetDataProviderTest.kt b/app/common/src/test/java/com/fsck/k9/widget/unread/UnreadWidgetDataProviderTest.kt similarity index 92% rename from app-k9mail/src/test/kotlin/app/k9mail/unread/UnreadWidgetDataProviderTest.kt rename to app/common/src/test/java/com/fsck/k9/widget/unread/UnreadWidgetDataProviderTest.kt index 001f6717d..ba201e0a8 100644 --- a/app-k9mail/src/test/kotlin/app/k9mail/unread/UnreadWidgetDataProviderTest.kt +++ b/app/common/src/test/java/com/fsck/k9/widget/unread/UnreadWidgetDataProviderTest.kt @@ -1,10 +1,11 @@ -package app.k9mail.unread +package com.fsck.k9.widget.unread import android.content.Context import assertk.assertThat import assertk.assertions.isEqualTo import assertk.assertions.isNull import com.fsck.k9.Account +import com.fsck.k9.CoreResourceProvider import com.fsck.k9.Preferences import com.fsck.k9.controller.MessageCounts import com.fsck.k9.controller.MessageCountsProvider @@ -14,10 +15,11 @@ import com.fsck.k9.mailstore.FolderType import com.fsck.k9.search.SearchAccount import com.fsck.k9.ui.folders.FolderNameFormatter import com.fsck.k9.ui.messagelist.DefaultFolderProvider -import com.fsck.k9.widget.unread.UnreadWidgetConfiguration -import com.fsck.k9.widget.unread.UnreadWidgetDataProvider +import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import org.koin.core.context.startKoin +import org.koin.dsl.module import org.koin.test.AutoCloseKoinTest import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock @@ -42,6 +44,17 @@ class UnreadWidgetDataProviderTest : AutoCloseKoinTest() { folderNameFormatter, ) + @Before + fun setUp() { + startKoin { + modules( + module { + factory { FakeCoreResourceProvider() } + }, + ) + } + } + @Test fun unifiedInbox() { val configuration = UnreadWidgetConfiguration(