Skip to content

Commit ba50860

Browse files
authored
test: add a unit test for missing coverage (#177)
* test: add a unit test for missing coverage * import kotlinx
1 parent 88c6eeb commit ba50860

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/test/kotlin/com/expedia/graphql/execution/FunctionDataFetcherTest.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import com.expedia.graphql.exceptions.CouldNotCastArgumentException
55
import graphql.schema.DataFetchingEnvironment
66
import io.mockk.every
77
import io.mockk.mockk
8+
import kotlinx.coroutines.coroutineScope
9+
import kotlinx.coroutines.delay
810
import org.junit.jupiter.api.Test
11+
import java.util.concurrent.CompletableFuture
912
import kotlin.test.assertEquals
1013
import kotlin.test.assertFailsWith
1114
import kotlin.test.assertNull
15+
import kotlin.test.assertTrue
1216

1317
internal class FunctionDataFetcherTest {
1418

@@ -22,6 +26,11 @@ internal class FunctionDataFetcherTest {
2226
fun context(@GraphQLContext string: String) = string
2327

2428
fun dataFetchingEnvironment(environment: DataFetchingEnvironment) = environment.field.name
29+
30+
suspend fun suspendPrint(string: String): String = coroutineScope {
31+
delay(10)
32+
string
33+
}
2534
}
2635

2736
@Test
@@ -105,4 +114,16 @@ internal class FunctionDataFetcherTest {
105114
}
106115
assertEquals(expected = "fooBarBaz", actual = dataFetcher.get(mockEnvironmet))
107116
}
117+
118+
@Test
119+
fun `suspend functions return value wrapped in CompletableFuture`() {
120+
val dataFetcher = FunctionDataFetcher(target = MyClass(), fn = MyClass::suspendPrint)
121+
val mockEnvironmet: DataFetchingEnvironment = mockk()
122+
every { mockEnvironmet.arguments } returns mapOf("string" to "hello")
123+
124+
val result = dataFetcher.get(mockEnvironmet)
125+
126+
assertTrue(result is CompletableFuture<*>)
127+
assertEquals(expected = "hello", actual = result.get())
128+
}
108129
}

0 commit comments

Comments
 (0)