diff --git a/chat-android/src/test/java/com/ably/chat/AtomicExecutorTest.kt b/chat-android/src/test/java/com/ably/chat/AtomicExecutorTest.kt new file mode 100644 index 00000000..b4eaddfb --- /dev/null +++ b/chat-android/src/test/java/com/ably/chat/AtomicExecutorTest.kt @@ -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()) + } +}