Skip to content

Commit

Permalink
Added basic unit test for AtomicExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Oct 18, 2024
1 parent 31ca6e3 commit 0451e23
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions chat-android/src/test/java/com/ably/chat/AtomicExecutorTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.ably.chat

import java.util.concurrent.Executors
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.delay
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Test

class AtomicExecutorTest {

@Test
fun `should perform given operation`() = runTest {
val singleThreadedDispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
val atomicExecutor = AtomicExecutor(CoroutineScope(singleThreadedDispatcher))
val deferred = atomicExecutor.execute {
delay(5000)
return@execute "Hello"
}
val result = deferred.receive()
assert(result.isSuccess)
assertEquals("Hello", result.getOrNull())
}
}

0 comments on commit 0451e23

Please sign in to comment.