|
|
|
|
@ -275,6 +275,26 @@ class CoroutinesUtilsTests {
@@ -275,6 +275,26 @@ class CoroutinesUtilsTests {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
fun invokeSuspendingFunctionWithContextParameter() { |
|
|
|
|
val method = CoroutinesUtilsTests::class.java.getDeclaredMethod("suspendingFunctionWithContextParameter", |
|
|
|
|
CustomException::class.java, Continuation::class.java) |
|
|
|
|
val mono = CoroutinesUtils.invokeSuspendingFunction(method, this, CustomException("foo")) as Mono |
|
|
|
|
runBlocking { |
|
|
|
|
Assertions.assertThat(mono.awaitSingleOrNull()).isEqualTo("foo") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
fun invokeSuspendingFunctionWithContextParameterAndParameter() { |
|
|
|
|
val method = CoroutinesUtilsTests::class.java.getDeclaredMethod("suspendingFunctionWithContextParameterAndParameter", |
|
|
|
|
CustomException::class.java, Int::class.java, Continuation::class.java) |
|
|
|
|
val mono = CoroutinesUtils.invokeSuspendingFunction(method, this, CustomException("foo"), 20) as Mono |
|
|
|
|
runBlocking { |
|
|
|
|
Assertions.assertThat(mono.awaitSingleOrNull()).isEqualTo("foo-20") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
fun invokeSuspendingFunctionWithGenericParameter() { |
|
|
|
|
val method = GenericController::class.java.declaredMethods.first { it.name.startsWith("handle") } |
|
|
|
|
@ -377,6 +397,18 @@ class CoroutinesUtilsTests {
@@ -377,6 +397,18 @@ class CoroutinesUtilsTests {
|
|
|
|
|
return "${this.message}-$limit" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
context(value: CustomException) |
|
|
|
|
suspend fun suspendingFunctionWithContextParameter(): String { |
|
|
|
|
delay(1) |
|
|
|
|
return "${value.message}" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
context(value: CustomException) |
|
|
|
|
suspend fun suspendingFunctionWithContextParameterAndParameter(limit: Int): String { |
|
|
|
|
delay(1) |
|
|
|
|
return "${value.message}-$limit" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface Named { |
|
|
|
|
val name: String |
|
|
|
|
} |
|
|
|
|
|