Commit 7c05911 1 parent 31ca6e3 commit 7c05911 Copy full SHA for 7c05911
File tree 1 file changed +25
-0
lines changed
chat-android/src/test/java/com/ably/chat
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com.ably.chat
2
+
3
+ import java.util.concurrent.Executors
4
+ import kotlinx.coroutines.CoroutineScope
5
+ import kotlinx.coroutines.asCoroutineDispatcher
6
+ import kotlinx.coroutines.delay
7
+ import kotlinx.coroutines.test.runTest
8
+ import org.junit.Assert.assertEquals
9
+ import org.junit.Test
10
+
11
+ class AtomicExecutorTest {
12
+
13
+ @Test
14
+ fun `should perform given operation` () = runTest {
15
+ val singleThreadedDispatcher = Executors .newSingleThreadExecutor().asCoroutineDispatcher()
16
+ val atomicExecutor = AtomicExecutor (CoroutineScope (singleThreadedDispatcher))
17
+ val deferred = atomicExecutor.execute {
18
+ delay(5000 )
19
+ return @execute " Hello"
20
+ }
21
+ val result = deferred.receive()
22
+ assert (result.isSuccess)
23
+ assertEquals(" Hello" , result.getOrNull())
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments