Skip to content

Commit

Permalink
Further unmockk after tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc2822 committed Jan 27, 2025
1 parent feccb76 commit 4f2d4e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import dagger.hilt.android.testing.HiltAndroidTest
import io.mockk.Awaits
import io.mockk.coEvery
import io.mockk.every
import io.mockk.junit4.MockKRule
import io.mockk.just
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.mockkStatic
import io.mockk.unmockkAll
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flow
Expand All @@ -55,8 +55,7 @@ class SyncAdapterServicesTest {
@Inject
lateinit var collectionRepository: DavCollectionRepository

@Inject
@ApplicationContext
@Inject @ApplicationContext
lateinit var context: Context

@Inject
Expand All @@ -74,6 +73,9 @@ class SyncAdapterServicesTest {
@get:Rule
val hiltRule = HiltAndroidRule(this)

@get:Rule
val mockkRule = MockKRule(this)

// test methods should run quickly and not wait 60 seconds for a sync timeout or something like that
@get:Rule
val timeoutRule: Timeout = Timeout.seconds(5)
Expand All @@ -90,7 +92,6 @@ class SyncAdapterServicesTest {
@After
fun tearDown() {
TestAccount.remove(account)
unmockkAll()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import at.bitfire.davdroid.sync.account.TestAccount
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import io.mockk.junit4.MockKRule
import io.mockk.mockkObject
import io.mockk.verify
import kotlinx.coroutines.runBlocking
Expand All @@ -41,6 +42,9 @@ class PeriodicSyncWorkerTest {
@get:Rule
val hiltRule = HiltAndroidRule(this)

@get:Rule
val mockkRule = MockKRule(this)

lateinit var account: Account

@Before
Expand Down Expand Up @@ -68,7 +72,7 @@ class PeriodicSyncWorkerTest {
BaseSyncWorker.INPUT_ACCOUNT_TYPE to invalidAccount.type
)

// mock WorkManager to observe cancellation call
// observe WorkManager cancellation call
val workManager = WorkManager.getInstance(context)
mockkObject(workManager)

Expand Down

0 comments on commit 4f2d4e3

Please sign in to comment.