Skip to content

Commit 9c40bbd

Browse files
committed
Use runTest for coroutine testing
1 parent 2fcf46f commit 9c40bbd

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

lib/src/androidTest/java/at/bitfire/cert4android/UserDecisionRegistryTest.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,16 @@ class UserDecisionRegistryTest {
6666
}
6767

6868
@Test
69-
fun testCheck_FirstDecision_Positive() {
69+
fun testCheck_FirstDecision_Positive() = runTest {
7070
every { registry.requestDecision(testCert, any(), any()) } answers {
7171
registry.onUserDecision(testCert, true)
7272
}
73-
assertTrue(runBlocking {
74-
registry.check(testCert, true)
75-
})
73+
assertTrue(registry.check(testCert, true))
7674
}
7775

7876
@Test
7977
fun testCheck_MultipleDecisionsForSameCert_Negative() {
78+
// Keep runBlocking for complex concurrency test with Semaphore and threads
8079
val canSendFeedback = Semaphore(0)
8180
every { registry.requestDecision(testCert, any(), any()) } answers {
8281
thread {
@@ -103,6 +102,7 @@ class UserDecisionRegistryTest {
103102

104103
@Test
105104
fun testCheck_MultipleDecisionsForSameCert_Positive() {
105+
// Keep runBlocking for complex concurrency test with Semaphore and threads
106106
val canSendFeedback = Semaphore(0)
107107
every { registry.requestDecision(testCert, any(), any()) } answers {
108108
thread {
@@ -129,6 +129,7 @@ class UserDecisionRegistryTest {
129129

130130
@Test
131131
fun testCheck_MultipleDecisionsForSameCert_cancel() {
132+
// Keep runBlocking for complex concurrency test with Semaphore, threads, and job cancellation
132133
val canSendFeedback = Semaphore(0)
133134
val nm = mockk<NotificationManagerCompat>()
134135
every { nm.cancel(any(), any()) } just runs
@@ -159,12 +160,10 @@ class UserDecisionRegistryTest {
159160
}
160161

161162
@Test
162-
fun testCheck_UserDecisionImpossible() {
163+
fun testCheck_UserDecisionImpossible() = runTest {
163164
every { NotificationUtils.notificationsPermitted(any()) } returns false
164-
assertFalse(runBlocking {
165-
// should return instantly
166-
registry.check(testCert, false)
167-
})
165+
// should return instantly
166+
assertFalse(registry.check(testCert, false))
168167
verify(inverse = true) {
169168
registry.requestDecision(any(), any(), any())
170169
}

0 commit comments

Comments
 (0)