Gate APK releases on worker factory and Matrix regression tests
Build and Release APK / Build APK (push) Failing after 2m46s

This commit is contained in:
2026-10-21 23:00:00 +02:00
parent af4e7899e3
commit d27edde5e8
6 changed files with 258 additions and 3 deletions
+3 -1
View File
@@ -193,7 +193,9 @@ dependencies {
androidTestImplementation "org.mockito:mockito-android:$mockito_version"
testImplementation "androidx.test:runner:$androidx_testrunner_version"
testImplementation "junit:junit:$junit_version"
testImplementation "org.mockito:mockito-core:$mockito_version"
testImplementation "org.mockito:mockito-inline:4.11.0"
testImplementation "org.robolectric:robolectric:4.11.1"
testImplementation "androidx.work:work-testing:$androidx_work_version"
// moshi
implementation "com.squareup.moshi:moshi:$moshi_version"
@@ -0,0 +1,111 @@
package dev.octoshrimpy.quik.worker
import android.app.Application
import android.content.ComponentName
import androidx.work.ListenableWorker
import androidx.work.testing.TestListenableWorkerBuilder
import ch.skew.remotrix.background.CommandService
import ch.skew.remotrix.background.ServiceWatcher
import dev.octoshrimpy.quik.blocking.BlockingClient
import dev.octoshrimpy.quik.interactor.UpdateBadge
import dev.octoshrimpy.quik.manager.ActiveConversationManager
import dev.octoshrimpy.quik.manager.NotificationManager
import dev.octoshrimpy.quik.manager.ShortcutManager
import dev.octoshrimpy.quik.repository.ContactRepository
import dev.octoshrimpy.quik.repository.ConversationRepository
import dev.octoshrimpy.quik.repository.MessageContentFilterRepository
import dev.octoshrimpy.quik.repository.MessageRepository
import dev.octoshrimpy.quik.repository.ScheduledMessageRepository
import dev.octoshrimpy.quik.repository.SyncRepository
import dev.octoshrimpy.quik.util.Preferences
import kotlinx.coroutines.runBlocking
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.mock
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
/** Real WorkManager construction and Android service intents; no SMS or Matrix network calls. */
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE, application = Application::class)
class InjectionWorkerFactoryTest {
private val conversationRepo = mock(ConversationRepository::class.java)
private val blockingClient = mock(BlockingClient::class.java)
private val prefs = mock(Preferences::class.java)
private val messageRepo = mock(MessageRepository::class.java)
private val updateBadge = mock(UpdateBadge::class.java)
private val shortcutManager = mock(ShortcutManager::class.java)
private val scheduledMessages = mock(ScheduledMessageRepository::class.java)
private val notifications = mock(NotificationManager::class.java)
private val activeConversation = mock(ActiveConversationManager::class.java)
private val syncRepo = mock(SyncRepository::class.java)
private val filters = mock(MessageContentFilterRepository::class.java)
private val contacts = mock(ContactRepository::class.java)
private val factory = InjectionWorkerFactory(
conversationRepo, blockingClient, prefs, messageRepo, updateBadge, shortcutManager,
scheduledMessages, notifications, activeConversation, syncRepo, filters, contacts
)
private val application: Application get() = RuntimeEnvironment.getApplication()
private inline fun <reified W : ListenableWorker> build(): W =
TestListenableWorkerBuilder<W>(application).setWorkerFactory(factory).build()
@Test
fun matrixCoroutineWorkerIsCreatedByTheApplicationFactory() {
assertEquals(ServiceWatcher::class.java, build<ServiceWatcher>().javaClass)
}
@Test
fun matrixWatcherStartsTheExpectedService() = runBlocking {
val worker = build<ServiceWatcher>()
assertEquals(ListenableWorker.Result.success(), worker.doWork())
val intent = shadowOf(application).nextStartedService
assertNotNull(intent)
assertEquals(CommandService.START_ALL, intent.action)
assertEquals(ComponentName(application, CommandService::class.java), intent.component)
}
@Test
fun housekeepingReceivesItsRepository() {
assertSame(scheduledMessages, build<HousekeepingWorker>().scheduledMessageRepository)
}
@Test
fun smsWorkerReceivesEveryRequiredDependency() {
val worker = build<ReceiveSmsWorker>()
assertSame(conversationRepo, worker.conversationRepo)
assertSame(blockingClient, worker.blockingClient)
assertSame(prefs, worker.prefs)
assertSame(messageRepo, worker.messageRepo)
assertSame(notifications, worker.notificationManager)
assertSame(updateBadge, worker.updateBadge)
assertSame(shortcutManager, worker.shortcutManager)
assertSame(filters, worker.filterRepo)
assertSame(contacts, worker.contactsRepo)
}
@Test
fun mmsWorkerReceivesEveryRequiredDependency() {
val worker = build<ReceiveMmsWorker>()
assertSame(activeConversation, worker.activeConversationManager)
assertSame(conversationRepo, worker.conversationRepo)
assertSame(blockingClient, worker.blockingClient)
assertSame(prefs, worker.prefs)
assertSame(syncRepo, worker.syncRepo)
assertSame(messageRepo, worker.messageRepo)
assertSame(notifications, worker.notificationManager)
assertSame(updateBadge, worker.updateBadge)
assertSame(shortcutManager, worker.shortcutManager)
assertSame(filters, worker.filterRepo)
assertSame(contacts, worker.contactsRepo)
}
@Test
fun eachRequestCreatesANewWorkerInstance() {
assertNotSame(build<ServiceWatcher>(), build<ServiceWatcher>())
assertNotSame(build<ReceiveSmsWorker>(), build<ReceiveSmsWorker>())
}
}