diff --git a/integration-tests/src/test/kotlin/org/springframework/aop/framework/autoproxy/AspectJAutoProxyInterceptorKotlinIntegrationTests.kt b/integration-tests/src/test/kotlin/org/springframework/aop/framework/autoproxy/AspectJAutoProxyInterceptorKotlinIntegrationTests.kt index e22c155daa7..ee20417a9a0 100644 --- a/integration-tests/src/test/kotlin/org/springframework/aop/framework/autoproxy/AspectJAutoProxyInterceptorKotlinIntegrationTests.kt +++ b/integration-tests/src/test/kotlin/org/springframework/aop/framework/autoproxy/AspectJAutoProxyInterceptorKotlinIntegrationTests.kt @@ -17,7 +17,6 @@ package org.springframework.aop.framework.autoproxy import kotlinx.coroutines.delay -import kotlinx.coroutines.runBlocking import org.aopalliance.intercept.MethodInterceptor import org.aopalliance.intercept.MethodInvocation import org.aspectj.lang.ProceedingJoinPoint @@ -73,43 +72,37 @@ class AspectJAutoProxyInterceptorKotlinIntegrationTests( } @Test - fun `Multiple interceptors with suspending function`() { + suspend fun `Multiple interceptors with suspending function`() { assertThat(firstAdvisor.interceptor.invocations).isEmpty() assertThat(secondAdvisor.interceptor.invocations).isEmpty() val value = "Hello!" - runBlocking { - assertThat(echo.suspendingEcho(value)).isEqualTo(value) - } + assertThat(echo.suspendingEcho(value)).isEqualTo(value) assertThat(firstAdvisor.interceptor.invocations).singleElement().matches { Mono::class.java.isAssignableFrom(it) } assertThat(secondAdvisor.interceptor.invocations).singleElement().matches { Mono::class.java.isAssignableFrom(it) } } @Test // gh-33095 - fun `Aspect and reactive transactional with suspending function`() { + suspend fun `Aspect and reactive transactional with suspending function`() { assertThat(countingAspect.counter).isZero() assertThat(reactiveTransactionManager.commits).isZero() val value = "Hello!" - runBlocking { - assertThat(echo.suspendingTransactionalEcho(value)).isEqualTo(value) - } + assertThat(echo.suspendingTransactionalEcho(value)).isEqualTo(value) assertThat(countingAspect.counter).`as`("aspect applied").isOne() assertThat(reactiveTransactionManager.begun).isOne() assertThat(reactiveTransactionManager.commits).`as`("transactional applied").isOne() } @Test // gh-33210 - fun `Aspect and cacheable with suspending function`() { + suspend fun `Aspect and cacheable with suspending function`() { assertThat(countingAspect.counter).isZero() val value = "Hello!" - runBlocking { - assertThat(echo.suspendingCacheableEcho(value)).isEqualTo("$value 0") - assertThat(echo.suspendingCacheableEcho(value)).isEqualTo("$value 0") - assertThat(echo.suspendingCacheableEcho(value)).isEqualTo("$value 0") - assertThat(countingAspect.counter).`as`("aspect applied once").isOne() - - assertThat(echo.suspendingCacheableEcho("$value bis")).isEqualTo("$value bis 1") - assertThat(echo.suspendingCacheableEcho("$value bis")).isEqualTo("$value bis 1") - } + assertThat(echo.suspendingCacheableEcho(value)).isEqualTo("$value 0") + assertThat(echo.suspendingCacheableEcho(value)).isEqualTo("$value 0") + assertThat(echo.suspendingCacheableEcho(value)).isEqualTo("$value 0") + assertThat(countingAspect.counter).`as`("aspect applied once").isOne() + + assertThat(echo.suspendingCacheableEcho("$value bis")).isEqualTo("$value bis 1") + assertThat(echo.suspendingCacheableEcho("$value bis")).isEqualTo("$value bis 1") assertThat(countingAspect.counter).`as`("aspect applied once per key").isEqualTo(2) } diff --git a/spring-aop/src/test/kotlin/org/springframework/aop/framework/CoroutinesUtilsTests.kt b/spring-aop/src/test/kotlin/org/springframework/aop/framework/CoroutinesUtilsTests.kt index 188b72f8b1e..81bae7b5844 100644 --- a/spring-aop/src/test/kotlin/org/springframework/aop/framework/CoroutinesUtilsTests.kt +++ b/spring-aop/src/test/kotlin/org/springframework/aop/framework/CoroutinesUtilsTests.kt @@ -19,7 +19,6 @@ package org.springframework.aop.framework import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.toList -import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import reactor.core.publisher.Flux @@ -37,39 +36,31 @@ class CoroutinesUtilsTests { fun awaitSingleNonNullValue() { val value = "foo" val continuation = Continuation(CoroutineName("test")) { } - runBlocking { - assertThat(CoroutinesUtils.awaitSingleOrNull(value, continuation)).isEqualTo(value) - } + assertThat(CoroutinesUtils.awaitSingleOrNull(value, continuation)).isEqualTo(value) } @Test fun awaitSingleNullValue() { val value = null val continuation = Continuation(CoroutineName("test")) { } - runBlocking { - assertThat(CoroutinesUtils.awaitSingleOrNull(value, continuation)).isNull() - } + assertThat(CoroutinesUtils.awaitSingleOrNull(value, continuation)).isNull() } @Test fun awaitSingleMonoValue() { val value = "foo" val continuation = Continuation(CoroutineName("test")) { } - runBlocking { - assertThat(CoroutinesUtils.awaitSingleOrNull(Mono.just(value), continuation)).isEqualTo(value) - } + assertThat(CoroutinesUtils.awaitSingleOrNull(Mono.just(value), continuation)).isEqualTo(value) } @Test @Suppress("UNCHECKED_CAST") - fun flow() { + suspend fun flow() { val value1 = "foo" val value2 = "bar" val values = Flux.just(value1, value2) val flow = CoroutinesUtils.asFlow(values) as Flow - runBlocking { - assertThat(flow.toList()).containsExactly(value1, value2) - } + assertThat(flow.toList()).containsExactly(value1, value2) } } diff --git a/spring-context/src/test/kotlin/org/springframework/cache/KotlinCacheReproTests.kt b/spring-context/src/test/kotlin/org/springframework/cache/KotlinCacheReproTests.kt index 465940061ff..ff45b40e0b7 100644 --- a/spring-context/src/test/kotlin/org/springframework/cache/KotlinCacheReproTests.kt +++ b/spring-context/src/test/kotlin/org/springframework/cache/KotlinCacheReproTests.kt @@ -16,7 +16,6 @@ package org.springframework.cache -import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.springframework.beans.testfixture.beans.TestBean @@ -33,51 +32,47 @@ import org.springframework.context.annotation.Configuration class KotlinCacheReproTests { @Test - fun spr14235AdaptsToSuspendingFunction() { - runBlocking { - val context = AnnotationConfigApplicationContext( - Spr14235Config::class.java, - Spr14235SuspendingService::class.java - ) - val bean = context.getBean(Spr14235SuspendingService::class.java) - val cache = context.getBean(CacheManager::class.java).getCache("itemCache")!! - val tb: TestBean = bean.findById("tb1") - assertThat(bean.findById("tb1")).isSameAs(tb) - assertThat(cache["tb1"]!!.get()).isSameAs(tb) - bean.clear() - val tb2: TestBean = bean.findById("tb1") - assertThat(tb2).isNotSameAs(tb) - assertThat(cache["tb1"]!!.get()).isSameAs(tb2) - bean.clear() - bean.insertItem(tb) - assertThat(bean.findById("tb1")).isSameAs(tb) - assertThat(cache["tb1"]!!.get()).isSameAs(tb) - context.close() - } + suspend fun spr14235AdaptsToSuspendingFunction() { + val context = AnnotationConfigApplicationContext( + Spr14235Config::class.java, + Spr14235SuspendingService::class.java + ) + val bean = context.getBean(Spr14235SuspendingService::class.java) + val cache = context.getBean(CacheManager::class.java).getCache("itemCache")!! + val tb: TestBean = bean.findById("tb1") + assertThat(bean.findById("tb1")).isSameAs(tb) + assertThat(cache["tb1"]!!.get()).isSameAs(tb) + bean.clear() + val tb2: TestBean = bean.findById("tb1") + assertThat(tb2).isNotSameAs(tb) + assertThat(cache["tb1"]!!.get()).isSameAs(tb2) + bean.clear() + bean.insertItem(tb) + assertThat(bean.findById("tb1")).isSameAs(tb) + assertThat(cache["tb1"]!!.get()).isSameAs(tb) + context.close() } @Test - fun spr14235AdaptsToSuspendingFunctionWithSync() { - runBlocking { - val context = AnnotationConfigApplicationContext( - Spr14235Config::class.java, - Spr14235SuspendingServiceSync::class.java - ) - val bean = context.getBean(Spr14235SuspendingServiceSync::class.java) - val cache = context.getBean(CacheManager::class.java).getCache("itemCache")!! - val tb = bean.findById("tb1") - assertThat(bean.findById("tb1")).isSameAs(tb) - assertThat(cache["tb1"]!!.get()).isSameAs(tb) - cache.clear() - val tb2 = bean.findById("tb1") - assertThat(tb2).isNotSameAs(tb) - assertThat(cache["tb1"]!!.get()).isSameAs(tb2) - cache.clear() - bean.insertItem(tb) - assertThat(bean.findById("tb1")).isSameAs(tb) - assertThat(cache["tb1"]!!.get()).isSameAs(tb) - context.close() - } + suspend fun spr14235AdaptsToSuspendingFunctionWithSync() { + val context = AnnotationConfigApplicationContext( + Spr14235Config::class.java, + Spr14235SuspendingServiceSync::class.java + ) + val bean = context.getBean(Spr14235SuspendingServiceSync::class.java) + val cache = context.getBean(CacheManager::class.java).getCache("itemCache")!! + val tb = bean.findById("tb1") + assertThat(bean.findById("tb1")).isSameAs(tb) + assertThat(cache["tb1"]!!.get()).isSameAs(tb) + cache.clear() + val tb2 = bean.findById("tb1") + assertThat(tb2).isNotSameAs(tb) + assertThat(cache["tb1"]!!.get()).isSameAs(tb2) + cache.clear() + bean.insertItem(tb) + assertThat(bean.findById("tb1")).isSameAs(tb) + assertThat(cache["tb1"]!!.get()).isSameAs(tb) + context.close() } @Test diff --git a/spring-context/src/test/kotlin/org/springframework/validation/beanvalidation/MethodValidationKotlinTests.kt b/spring-context/src/test/kotlin/org/springframework/validation/beanvalidation/MethodValidationKotlinTests.kt index d23681a97fb..38e00a39620 100644 --- a/spring-context/src/test/kotlin/org/springframework/validation/beanvalidation/MethodValidationKotlinTests.kt +++ b/spring-context/src/test/kotlin/org/springframework/validation/beanvalidation/MethodValidationKotlinTests.kt @@ -49,7 +49,7 @@ class MethodValidationKotlinTests { } @Test - fun coroutinesParameterValidation() = runBlocking { + suspend fun coroutinesParameterValidation() { val bean = MyValidCoroutinesBean() val proxyFactory = ProxyFactory(bean) val validator = LocalValidatorFactoryBean() diff --git a/spring-core/src/test/kotlin/org/springframework/core/CoroutinesUtilsTests.kt b/spring-core/src/test/kotlin/org/springframework/core/CoroutinesUtilsTests.kt index dccb13d0e83..c03a2039d30 100644 --- a/spring-core/src/test/kotlin/org/springframework/core/CoroutinesUtilsTests.kt +++ b/spring-core/src/test/kotlin/org/springframework/core/CoroutinesUtilsTests.kt @@ -18,11 +18,17 @@ package org.springframework.core import io.micrometer.observation.Observation import io.micrometer.observation.tck.TestObservationRegistry -import kotlinx.coroutines.* +import kotlinx.coroutines.CoroutineName +import kotlinx.coroutines.Deferred +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.reactor.awaitSingle import kotlinx.coroutines.reactor.awaitSingleOrNull +import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -33,8 +39,6 @@ import reactor.core.publisher.Mono import reactor.test.StepVerifier import kotlin.coroutines.Continuation import kotlin.coroutines.coroutineContext -import kotlin.reflect.full.primaryConstructor -import kotlin.reflect.jvm.isAccessible import kotlin.reflect.jvm.javaMethod /** @@ -47,8 +51,8 @@ class CoroutinesUtilsTests { private val observationRegistry = TestObservationRegistry.create() @Test - fun deferredToMono() { - runBlocking { + suspend fun deferredToMono() { + coroutineScope { val deferred: Deferred = async(Dispatchers.IO) { delay(1) "foo" @@ -62,12 +66,10 @@ class CoroutinesUtilsTests { } @Test - fun monoToDeferred() { - runBlocking { - val mono = Mono.just("foo") - val deferred = CoroutinesUtils.monoToDeferred(mono) - Assertions.assertThat(deferred.await()).isEqualTo("foo") - } + suspend fun monoToDeferred() { + val mono = Mono.just("foo") + val deferred = CoroutinesUtils.monoToDeferred(mono) + Assertions.assertThat(deferred.await()).isEqualTo("foo") } @Test @@ -93,12 +95,10 @@ class CoroutinesUtilsTests { } @Test - fun invokeSuspendingFunctionWithNullableParameter() { + suspend fun invokeSuspendingFunctionWithNullableParameter() { val method = CoroutinesUtilsTests::class.java.getDeclaredMethod("suspendingFunctionWithNullable", String::class.java, Continuation::class.java) val mono = CoroutinesUtils.invokeSuspendingFunction(method, this, null, null) as Mono - runBlocking { - Assertions.assertThat(mono.awaitSingleOrNull()).isNull() - } + Assertions.assertThat(mono.awaitSingleOrNull()).isNull() } @Test @@ -154,23 +154,19 @@ class CoroutinesUtilsTests { } @Test - fun invokeSuspendingFunctionWithNullContinuationParameterAndContext() { + suspend fun invokeSuspendingFunctionWithNullContinuationParameterAndContext() { val method = CoroutinesUtilsTests::class.java.getDeclaredMethod("suspendingFunctionWithContext", String::class.java, Continuation::class.java) val context = CoroutineName("name") val mono = CoroutinesUtils.invokeSuspendingFunction(context, method, this, "foo", null) as Mono - runBlocking { - Assertions.assertThat(mono.awaitSingle()).isEqualTo("foo") - } + Assertions.assertThat(mono.awaitSingle()).isEqualTo("foo") } @Test - fun invokeSuspendingFunctionWithoutContinuationParameterAndContext() { + suspend fun invokeSuspendingFunctionWithoutContinuationParameterAndContext() { val method = CoroutinesUtilsTests::class.java.getDeclaredMethod("suspendingFunctionWithContext", String::class.java, Continuation::class.java) val context = CoroutineName("name") val mono = CoroutinesUtils.invokeSuspendingFunction(context, method, this, "foo") as Mono - runBlocking { - Assertions.assertThat(mono.awaitSingle()).isEqualTo("foo") - } + Assertions.assertThat(mono.awaitSingle()).isEqualTo("foo") } @Test @@ -181,57 +177,45 @@ class CoroutinesUtilsTests { } @Test - fun invokeSuspendingFunctionReturningUnit() { + suspend fun invokeSuspendingFunctionReturningUnit() { val method = CoroutinesUtilsTests::class.java.getDeclaredMethod("suspendingUnit", Continuation::class.java) val mono = CoroutinesUtils.invokeSuspendingFunction(method, this) as Mono - runBlocking { - Assertions.assertThat(mono.awaitSingleOrNull()).isNull() - } + Assertions.assertThat(mono.awaitSingleOrNull()).isNull() } @Test - fun invokeSuspendingFunctionReturningNull() { + suspend fun invokeSuspendingFunctionReturningNull() { val method = CoroutinesUtilsTests::class.java.getDeclaredMethod("suspendingNullable", Continuation::class.java) val mono = CoroutinesUtils.invokeSuspendingFunction(method, this) as Mono - runBlocking { - Assertions.assertThat(mono.awaitSingleOrNull()).isNull() - } + Assertions.assertThat(mono.awaitSingleOrNull()).isNull() } @Test - fun invokeSuspendingFunctionWithValueClassParameter() { + suspend fun invokeSuspendingFunctionWithValueClassParameter() { val method = CoroutinesUtilsTests::class.java.declaredMethods.first { it.name.startsWith("suspendingFunctionWithValueClassParameter") } val mono = CoroutinesUtils.invokeSuspendingFunction(method, this, "foo", null) as Mono - runBlocking { - Assertions.assertThat(mono.awaitSingle()).isEqualTo("foo") - } + Assertions.assertThat(mono.awaitSingle()).isEqualTo("foo") } @Test - fun invokeSuspendingFunctionWithNestedValueClassParameter() { + suspend fun invokeSuspendingFunctionWithNestedValueClassParameter() { val method = CoroutinesUtilsTests::class.java.declaredMethods.first { it.name.startsWith("suspendingFunctionWithNestedValueClassParameter") } val mono = CoroutinesUtils.invokeSuspendingFunction(method, this, "foo", null) as Mono - runBlocking { - Assertions.assertThat(mono.awaitSingle()).isEqualTo("foo") - } + Assertions.assertThat(mono.awaitSingle()).isEqualTo("foo") } @Test - fun invokeSuspendingFunctionWithValueClassReturnValue() { + suspend fun invokeSuspendingFunctionWithValueClassReturnValue() { val method = CoroutinesUtilsTests::class.java.declaredMethods.first { it.name.startsWith("suspendingFunctionWithValueClassReturnValue") } val mono = CoroutinesUtils.invokeSuspendingFunction(method, this, null) as Mono - runBlocking { - Assertions.assertThat(mono.awaitSingle()).isEqualTo(ValueClass("foo")) - } + Assertions.assertThat(mono.awaitSingle()).isEqualTo(ValueClass("foo")) } @Test - fun invokeSuspendingFunctionWithResultOfUnitReturnValue() { + suspend fun invokeSuspendingFunctionWithResultOfUnitReturnValue() { val method = CoroutinesUtilsTests::class.java.declaredMethods.first { it.name.startsWith("suspendingFunctionWithResultOfUnitReturnValue") } val mono = CoroutinesUtils.invokeSuspendingFunction(method, this, null) as Mono - runBlocking { - Assertions.assertThat(mono.awaitSingle()).isEqualTo(Result.success(Unit)) - } + Assertions.assertThat(mono.awaitSingle()).isEqualTo(Result.success(Unit)) } @Test @@ -246,51 +230,41 @@ class CoroutinesUtilsTests { } @Test - fun invokeSuspendingFunctionWithNullableValueClassParameter() { + suspend fun invokeSuspendingFunctionWithNullableValueClassParameter() { val method = CoroutinesUtilsTests::class.java.declaredMethods.first { it.name.startsWith("suspendingFunctionWithNullableValueClass") } val mono = CoroutinesUtils.invokeSuspendingFunction(method, this, null, null) as Mono - runBlocking { - Assertions.assertThat(mono.awaitSingleOrNull()).isNull() - } + Assertions.assertThat(mono.awaitSingleOrNull()).isNull() } @Test - fun invokeSuspendingFunctionWithValueClassWithPrivateConstructorParameter() { + suspend fun invokeSuspendingFunctionWithValueClassWithPrivateConstructorParameter() { val method = CoroutinesUtilsTests::class.java.declaredMethods.first { it.name.startsWith("suspendingFunctionWithValueClassWithPrivateConstructor") } val mono = CoroutinesUtils.invokeSuspendingFunction(method, this, "foo", null) as Mono - runBlocking { - Assertions.assertThat(mono.awaitSingleOrNull()).isEqualTo("foo") - } + Assertions.assertThat(mono.awaitSingleOrNull()).isEqualTo("foo") } @Test - fun invokeSuspendingFunctionWithExtension() { + suspend fun invokeSuspendingFunctionWithExtension() { val method = CoroutinesUtilsTests::class.java.getDeclaredMethod("suspendingFunctionWithExtension", CustomException::class.java, Continuation::class.java) val mono = CoroutinesUtils.invokeSuspendingFunction(method, this, CustomException("foo")) as Mono - runBlocking { - Assertions.assertThat(mono.awaitSingleOrNull()).isEqualTo("foo") - } + Assertions.assertThat(mono.awaitSingleOrNull()).isEqualTo("foo") } @Test - fun invokeSuspendingFunctionWithExtensionAndParameter() { + suspend fun invokeSuspendingFunctionWithExtensionAndParameter() { val method = CoroutinesUtilsTests::class.java.getDeclaredMethod("suspendingFunctionWithExtensionAndParameter", 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") - } + Assertions.assertThat(mono.awaitSingleOrNull()).isEqualTo("foo-20") } @Test - fun invokeSuspendingFunctionWithGenericParameter() { + suspend fun invokeSuspendingFunctionWithGenericParameter() { val method = GenericController::class.java.declaredMethods.first { it.name.startsWith("handle") } val horse = Animal("horse") val mono = CoroutinesUtils.invokeSuspendingFunction(method, AnimalController(), horse, null) as Mono - runBlocking { - Assertions.assertThat(mono.awaitSingle()).isEqualTo(horse.name) - } + Assertions.assertThat(mono.awaitSingle()).isEqualTo(horse.name) } @Test diff --git a/spring-core/src/test/kotlin/org/springframework/core/ReactiveAdapterRegistryKotlinTests.kt b/spring-core/src/test/kotlin/org/springframework/core/ReactiveAdapterRegistryKotlinTests.kt index c1fbbb21c65..817fecbed5b 100644 --- a/spring-core/src/test/kotlin/org/springframework/core/ReactiveAdapterRegistryKotlinTests.kt +++ b/spring-core/src/test/kotlin/org/springframework/core/ReactiveAdapterRegistryKotlinTests.kt @@ -23,7 +23,6 @@ import kotlinx.coroutines.async import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.toList -import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.reactivestreams.Publisher @@ -52,11 +51,11 @@ class ReactiveAdapterRegistryKotlinTests { } @Test - fun publisherToDeferred() { + suspend fun publisherToDeferred() { val source = Mono.just(1) val target = getAdapter(Deferred::class).fromPublisher(source) assertThat(target).isInstanceOf(Deferred::class.java) - assertThat(runBlocking { (target as Deferred<*>).await() }).isEqualTo(1) + assertThat((target as Deferred<*>).await()).isEqualTo(1) } @Test @@ -76,11 +75,11 @@ class ReactiveAdapterRegistryKotlinTests { } @Test - fun publisherToFlow() { + suspend fun publisherToFlow() { val source = Flux.just(1, 2, 3) val target = getAdapter(Flow::class).fromPublisher(source) assertThat(target).isInstanceOf(Flow::class.java) - assertThat(runBlocking { (target as Flow<*>).toList() }).contains(1, 2, 3) + assertThat((target as Flow<*>).toList()).contains(1, 2, 3) } private fun getAdapter(reactiveType: KClass<*>): ReactiveAdapter { diff --git a/spring-messaging/src/test/kotlin/org/springframework/messaging/rsocket/RSocketRequesterExtensionsTests.kt b/spring-messaging/src/test/kotlin/org/springframework/messaging/rsocket/RSocketRequesterExtensionsTests.kt index 98988805b98..49940f57044 100644 --- a/spring-messaging/src/test/kotlin/org/springframework/messaging/rsocket/RSocketRequesterExtensionsTests.kt +++ b/spring-messaging/src/test/kotlin/org/springframework/messaging/rsocket/RSocketRequesterExtensionsTests.kt @@ -20,7 +20,6 @@ import io.mockk.every import io.mockk.mockk import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.toList -import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.reactivestreams.Publisher @@ -40,36 +39,30 @@ class RSocketRequesterExtensionsTests { @Test @Suppress("DEPRECATION") - fun connectAndAwait() { + suspend fun connectAndAwait() { val requester = mockk() val builder = mockk() every { builder.connect(any()) } returns Mono.just(requester) - runBlocking { - assertThat(builder.connectAndAwait(mockk())).isEqualTo(requester) - } + assertThat(builder.connectAndAwait(mockk())).isEqualTo(requester) } @Test @Suppress("DEPRECATION") - fun connectTcpAndAwait() { + suspend fun connectTcpAndAwait() { val host = "127.0.0.1" val requester = mockk() val builder = mockk() every { builder.connectTcp(host, any()) } returns Mono.just(requester) - runBlocking { - assertThat(builder.connectTcpAndAwait(host, 0)).isEqualTo(requester) - } + assertThat(builder.connectTcpAndAwait(host, 0)).isEqualTo(requester) } @Test @Suppress("DEPRECATION") - fun connectWebSocketAndAwait() { + suspend fun connectWebSocketAndAwait() { val requester = mockk() val builder = mockk() every { builder.connectWebSocket(any()) } returns Mono.just(requester) - runBlocking { - assertThat(builder.connectWebSocketAndAwait(mockk())).isEqualTo(requester) - } + assertThat(builder.connectWebSocketAndAwait(mockk())).isEqualTo(requester) } @Test @@ -104,57 +97,45 @@ class RSocketRequesterExtensionsTests { } @Test - fun sendAndAwait() { + suspend fun sendAndAwait() { val retrieveSpec = mockk() every { retrieveSpec.send() } returns Mono.empty() - runBlocking { - retrieveSpec.sendAndAwait() - } + retrieveSpec.sendAndAwait() } @Test - fun retrieveAndAwait() { + suspend fun retrieveAndAwait() { val response = "foo" val retrieveSpec = mockk() every { retrieveSpec.retrieveMono(match>(stringTypeRefMatcher)) } returns Mono.just("foo") - runBlocking { - assertThat(retrieveSpec.retrieveAndAwait()).isEqualTo(response) - } + assertThat(retrieveSpec.retrieveAndAwait()).isEqualTo(response) } @Test - fun retrieveAndAwaitOrNull() { + suspend fun retrieveAndAwaitOrNull() { val retrieveSpec = mockk() every { retrieveSpec.retrieveMono(match>(stringTypeRefMatcher)) } returns Mono.empty() - runBlocking { - assertThat(retrieveSpec.retrieveAndAwaitOrNull()).isNull() - } + assertThat(retrieveSpec.retrieveAndAwaitOrNull()).isNull() } @Test - fun retrieveFlow() { + suspend fun retrieveFlow() { val retrieveSpec = mockk() every { retrieveSpec.retrieveFlux(match>(stringTypeRefMatcher)) } returns Flux.just("foo", "bar") - runBlocking { - assertThat(retrieveSpec.retrieveFlow().toList()).contains("foo", "bar") - } + assertThat(retrieveSpec.retrieveFlow().toList()).contains("foo", "bar") } @Test fun retrieveMono() { val retrieveSpec = mockk() every { retrieveSpec.retrieveMono(match>(stringTypeRefMatcher)) } returns Mono.just("foo") - runBlocking { - assertThat(retrieveSpec.retrieveMono().block()).isEqualTo("foo") - } + assertThat(retrieveSpec.retrieveMono().block()).isEqualTo("foo") } @Test fun retrieveFlux() { val retrieveSpec = mockk() every { retrieveSpec.retrieveFlux(match>(stringTypeRefMatcher)) } returns Flux.just("foo", "bar") - runBlocking { - assertThat(retrieveSpec.retrieveFlux().collectList().block()).contains("foo", "bar") - } + assertThat(retrieveSpec.retrieveFlux().collectList().block()).contains("foo", "bar") } } diff --git a/spring-messaging/src/test/kotlin/org/springframework/messaging/rsocket/service/RSocketServiceMethodKotlinTests.kt b/spring-messaging/src/test/kotlin/org/springframework/messaging/rsocket/service/RSocketServiceMethodKotlinTests.kt index 075906b3fff..11cde445c14 100644 --- a/spring-messaging/src/test/kotlin/org/springframework/messaging/rsocket/service/RSocketServiceMethodKotlinTests.kt +++ b/spring-messaging/src/test/kotlin/org/springframework/messaging/rsocket/service/RSocketServiceMethodKotlinTests.kt @@ -22,7 +22,6 @@ import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.toList import kotlinx.coroutines.reactive.asFlow -import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -53,7 +52,7 @@ class RSocketServiceMethodKotlinTests { } @Test - fun fireAndForget(): Unit = runBlocking { + suspend fun fireAndForget() { val service = proxyFactory.createClient(SuspendingFunctionsService::class.java) val requestPayload = "request" @@ -65,7 +64,7 @@ class RSocketServiceMethodKotlinTests { } @Test - fun requestResponse(): Unit = runBlocking { + suspend fun requestResponse() { val service = proxyFactory.createClient(SuspendingFunctionsService::class.java) val requestPayload = "request" @@ -80,7 +79,7 @@ class RSocketServiceMethodKotlinTests { } @Test - fun requestStream(): Unit = runBlocking { + suspend fun requestStream() { val service = proxyFactory.createClient(SuspendingFunctionsService::class.java) val requestPayload = "request" @@ -97,7 +96,7 @@ class RSocketServiceMethodKotlinTests { } @Test - fun nonSuspendingRequestStream(): Unit = runBlocking { + suspend fun nonSuspendingRequestStream() { val service = proxyFactory.createClient(NonSuspendingFunctionsService::class.java) val requestPayload = "request" @@ -114,7 +113,7 @@ class RSocketServiceMethodKotlinTests { } @Test - fun requestChannel(): Unit = runBlocking { + suspend fun requestChannel() { val service = proxyFactory.createClient(SuspendingFunctionsService::class.java) val requestPayload1 = "request1" diff --git a/spring-r2dbc/src/test/kotlin/org/springframework/r2dbc/core/DatabaseClientExtensionsTests.kt b/spring-r2dbc/src/test/kotlin/org/springframework/r2dbc/core/DatabaseClientExtensionsTests.kt index cb38307f378..62c4839fe12 100644 --- a/spring-r2dbc/src/test/kotlin/org/springframework/r2dbc/core/DatabaseClientExtensionsTests.kt +++ b/spring-r2dbc/src/test/kotlin/org/springframework/r2dbc/core/DatabaseClientExtensionsTests.kt @@ -20,7 +20,6 @@ import io.mockk.every import io.mockk.mockk import io.mockk.verify import io.r2dbc.spi.Parameters -import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Test import reactor.core.publisher.Mono @@ -37,11 +36,7 @@ class DatabaseClientExtensionsTests { fun bindByIndexShouldBindValue() { val spec = mockk() every { spec.bind(eq(0), any()) } returns spec - - runBlocking { - spec.bind(0, "foo") - } - + spec.bind(0, "foo") verify { spec.bind(0, Parameters.`in`("foo")) } @@ -51,11 +46,7 @@ class DatabaseClientExtensionsTests { fun bindByIndexShouldBindNull() { val spec = mockk() every { spec.bind(eq(0), any()) } returns spec - - runBlocking { - spec.bind(0, null) - } - + spec.bind(0, null) verify { spec.bind(0, Parameters.`in`(String::class.java)) } @@ -65,11 +56,7 @@ class DatabaseClientExtensionsTests { fun bindByNameShouldBindValue() { val spec = mockk() every { spec.bind(eq("field"), any()) } returns spec - - runBlocking { - spec.bind("field", "foo") - } - + spec.bind("field", "foo") verify { spec.bind("field", Parameters.`in`("foo")) } @@ -79,25 +66,17 @@ class DatabaseClientExtensionsTests { fun bindByNameShouldBindNull() { val spec = mockk() every { spec.bind(eq("field"), any()) } returns spec - - runBlocking { - spec.bind("field", null) - } - + spec.bind("field", null) verify { spec.bind("field", Parameters.`in`(String::class.java)) } } @Test - fun genericExecuteSpecAwait() { + suspend fun genericExecuteSpecAwait() { val spec = mockk() every { spec.then() } returns Mono.empty() - - runBlocking { - spec.await() - } - + spec.await() verify { spec.then() } diff --git a/spring-r2dbc/src/test/kotlin/org/springframework/r2dbc/core/RowsFetchSpecExtensionsTests.kt b/spring-r2dbc/src/test/kotlin/org/springframework/r2dbc/core/RowsFetchSpecExtensionsTests.kt index c18fd38ac12..100bb718b4c 100644 --- a/spring-r2dbc/src/test/kotlin/org/springframework/r2dbc/core/RowsFetchSpecExtensionsTests.kt +++ b/spring-r2dbc/src/test/kotlin/org/springframework/r2dbc/core/RowsFetchSpecExtensionsTests.kt @@ -37,14 +37,10 @@ import reactor.core.publisher.Mono class RowsFetchSpecExtensionsTests { @Test - fun awaitOneWithValue() { + suspend fun awaitOneWithValue() { val spec = mockk>() every { spec.one() } returns Mono.just("foo") - - runBlocking { - assertThat(spec.awaitOne()).isEqualTo("foo") - } - + assertThat(spec.awaitOne()).isEqualTo("foo") verify { spec.one() } @@ -54,53 +50,39 @@ class RowsFetchSpecExtensionsTests { fun awaitOneWithNull() { val spec = mockk>() every { spec.one() } returns Mono.empty() - assertThatExceptionOfType(EmptyResultDataAccessException::class.java).isThrownBy { runBlocking { spec.awaitOne() } } - verify { spec.one() } } @Test - fun awaitOneOrNullWithValue() { + suspend fun awaitOneOrNullWithValue() { val spec = mockk>() every { spec.one() } returns Mono.just("foo") - - runBlocking { - assertThat(spec.awaitOneOrNull()).isEqualTo("foo") - } - + assertThat(spec.awaitOneOrNull()).isEqualTo("foo") verify { spec.one() } } @Test - fun awaitOneOrNullWithNull() { + suspend fun awaitOneOrNullWithNull() { val spec = mockk>() every { spec.one() } returns Mono.empty() - - runBlocking { - assertThat(spec.awaitOneOrNull()).isNull() - } - + assertThat(spec.awaitOneOrNull()).isNull() verify { spec.one() } } @Test - fun awaitFirstWithValue() { + suspend fun awaitFirstWithValue() { val spec = mockk>() every { spec.first() } returns Mono.just("foo") - - runBlocking { - assertThat(spec.awaitSingle()).isEqualTo("foo") - } - + assertThat(spec.awaitSingle()).isEqualTo("foo") verify { spec.first() } @@ -110,39 +92,29 @@ class RowsFetchSpecExtensionsTests { fun awaitFirstWithNull() { val spec = mockk>() every { spec.first() } returns Mono.empty() - assertThatExceptionOfType(EmptyResultDataAccessException::class.java).isThrownBy { runBlocking { spec.awaitSingle() } } - verify { spec.first() } } @Test - fun awaitSingleOrNullWithValue() { + suspend fun awaitSingleOrNullWithValue() { val spec = mockk>() every { spec.first() } returns Mono.just("foo") - - runBlocking { - assertThat(spec.awaitSingleOrNull()).isEqualTo("foo") - } - + assertThat(spec.awaitSingleOrNull()).isEqualTo("foo") verify { spec.first() } } @Test - fun awaitSingleOrNullWithNull() { + suspend fun awaitSingleOrNullWithNull() { val spec = mockk>() every { spec.first() } returns Mono.empty() - - runBlocking { - assertThat(spec.awaitSingleOrNull()).isNull() - } - + assertThat(spec.awaitSingleOrNull()).isNull() verify { spec.first() } @@ -150,14 +122,10 @@ class RowsFetchSpecExtensionsTests { @Test @ExperimentalCoroutinesApi - fun allAsFlow() { + suspend fun allAsFlow() { val spec = mockk>() every { spec.all() } returns Flux.just("foo", "bar", "baz") - - runBlocking { - assertThat(spec.flow().toList()).contains("foo", "bar", "baz") - } - + assertThat(spec.flow().toList()).contains("foo", "bar", "baz") verify { spec.all() } diff --git a/spring-r2dbc/src/test/kotlin/org/springframework/r2dbc/core/UpdatedRowsFetchSpecExtensionsTests.kt b/spring-r2dbc/src/test/kotlin/org/springframework/r2dbc/core/UpdatedRowsFetchSpecExtensionsTests.kt index 52f0cae7f6d..e91990d19a0 100644 --- a/spring-r2dbc/src/test/kotlin/org/springframework/r2dbc/core/UpdatedRowsFetchSpecExtensionsTests.kt +++ b/spring-r2dbc/src/test/kotlin/org/springframework/r2dbc/core/UpdatedRowsFetchSpecExtensionsTests.kt @@ -19,7 +19,6 @@ package org.springframework.r2dbc.core import io.mockk.every import io.mockk.mockk import io.mockk.verify -import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import reactor.core.publisher.Mono @@ -32,14 +31,10 @@ import reactor.core.publisher.Mono class UpdatedRowsFetchSpecExtensionsTests { @Test - fun awaitRowsUpdatedWithValue() { + suspend fun awaitRowsUpdatedWithValue() { val spec = mockk() every { spec.rowsUpdated() } returns Mono.just(42) - - runBlocking { - assertThat(spec.awaitRowsUpdated()).isEqualTo(42) - } - + assertThat(spec.awaitRowsUpdated()).isEqualTo(42) verify { spec.rowsUpdated() } diff --git a/spring-tx/src/test/kotlin/org/springframework/transaction/annotation/CoroutinesAnnotationTransactionInterceptorTests.kt b/spring-tx/src/test/kotlin/org/springframework/transaction/annotation/CoroutinesAnnotationTransactionInterceptorTests.kt index 4a9b5611339..53b41b9f6a5 100644 --- a/spring-tx/src/test/kotlin/org/springframework/transaction/annotation/CoroutinesAnnotationTransactionInterceptorTests.kt +++ b/spring-tx/src/test/kotlin/org/springframework/transaction/annotation/CoroutinesAnnotationTransactionInterceptorTests.kt @@ -42,14 +42,12 @@ class CoroutinesAnnotationTransactionInterceptorTests { private val source = AnnotationTransactionAttributeSource() @Test - fun suspendingNoValueSuccess() { + suspend fun suspendingNoValueSuccess() { val proxyFactory = ProxyFactory() proxyFactory.setTarget(TestWithCoroutines()) proxyFactory.addAdvice(TransactionInterceptor(rtm, source)) val proxy = proxyFactory.proxy as TestWithCoroutines - runBlocking { - proxy.suspendingNoValueSuccess() - } + proxy.suspendingNoValueSuccess() assertReactiveGetTransactionAndCommitCount(1) } @@ -68,14 +66,12 @@ class CoroutinesAnnotationTransactionInterceptorTests { } @Test - fun suspendingValueSuccess() { + suspend fun suspendingValueSuccess() { val proxyFactory = ProxyFactory() proxyFactory.setTarget(TestWithCoroutines()) proxyFactory.addAdvice(TransactionInterceptor(rtm, source)) val proxy = proxyFactory.proxy as TestWithCoroutines - runBlocking { - assertThat(proxy.suspendingValueSuccess()).isEqualTo("foo") - } + assertThat(proxy.suspendingValueSuccess()).isEqualTo("foo") assertReactiveGetTransactionAndCommitCount(1) } @@ -94,39 +90,33 @@ class CoroutinesAnnotationTransactionInterceptorTests { } @Test - fun suspendingFlowSuccess() { + suspend fun suspendingFlowSuccess() { val proxyFactory = ProxyFactory() proxyFactory.setTarget(TestWithCoroutines()) proxyFactory.addAdvice(TransactionInterceptor(rtm, source)) val proxy = proxyFactory.proxy as TestWithCoroutines - runBlocking { - assertThat(proxy.suspendingFlowSuccess().toList()).containsExactly("foo", "foo") - } + assertThat(proxy.suspendingFlowSuccess().toList()).containsExactly("foo", "foo") assertReactiveGetTransactionAndCommitCount(1) } @Test - fun flowSuccess() { + suspend fun flowSuccess() { val proxyFactory = ProxyFactory() proxyFactory.setTarget(TestWithCoroutines()) proxyFactory.addAdvice(TransactionInterceptor(rtm, source)) val proxy = proxyFactory.proxy as TestWithCoroutines - runBlocking { - assertThat(proxy.flowSuccess().toList()).containsExactly("foo", "foo") - } + assertThat(proxy.flowSuccess().toList()).containsExactly("foo", "foo") assertReactiveGetTransactionAndCommitCount(1) } @Test - fun suspendingValueSuccessWithContext() { + suspend fun suspendingValueSuccessWithContext() { val proxyFactory = ProxyFactory() proxyFactory.setTarget(TestWithCoroutines()) proxyFactory.addAdvice(TransactionInterceptor(rtm, source)) val proxy = proxyFactory.proxy as TestWithCoroutines - assertThat(runBlocking { - withExampleContext("context") { - proxy.suspendingValueSuccessWithContext() - } + assertThat(withExampleContext("context") { + proxy.suspendingValueSuccessWithContext() }).isEqualTo("context") assertReactiveGetTransactionAndCommitCount(1) } diff --git a/spring-tx/src/test/kotlin/org/springframework/transaction/interceptor/AbstractCoroutinesTransactionAspectTests.kt b/spring-tx/src/test/kotlin/org/springframework/transaction/interceptor/AbstractCoroutinesTransactionAspectTests.kt index a418692ae8b..79986b79068 100644 --- a/spring-tx/src/test/kotlin/org/springframework/transaction/interceptor/AbstractCoroutinesTransactionAspectTests.kt +++ b/spring-tx/src/test/kotlin/org/springframework/transaction/interceptor/AbstractCoroutinesTransactionAspectTests.kt @@ -19,6 +19,7 @@ package org.springframework.transaction.interceptor import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.assertThatExceptionOfType import org.assertj.core.api.Fail import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -53,7 +54,7 @@ abstract class AbstractCoroutinesTransactionAspectTests { } @Test - fun noTransaction() { + suspend fun noTransaction() { val rtm = Mockito.mock(ReactiveTransactionManager::class.java) val tb = DefaultTestBean() val tas: TransactionAttributeSource = MapTransactionAttributeSource() @@ -63,9 +64,7 @@ abstract class AbstractCoroutinesTransactionAspectTests { // and transaction attribute source val itb = advised(tb, rtm, tas) as TestBean checkReactiveTransaction(false) - runBlocking { - itb.getName() - } + itb.getName() checkReactiveTransaction(false) // expect no calls @@ -76,7 +75,7 @@ abstract class AbstractCoroutinesTransactionAspectTests { * Check that a transaction is created and committed. */ @Test - fun transactionShouldSucceed() { + suspend fun transactionShouldSucceed() { val txatt: TransactionAttribute = DefaultTransactionAttribute() val tas = MapTransactionAttributeSource() tas.register(getNameMethod!!, txatt) @@ -87,9 +86,7 @@ abstract class AbstractCoroutinesTransactionAspectTests { given(rtm.commit(status)).willReturn(Mono.empty()) val tb = DefaultTestBean() val itb = advised(tb, rtm, tas) as TestBean - runBlocking { - itb.getName() - } + itb.getName() Mockito.verify(rtm).commit(status) } @@ -97,7 +94,7 @@ abstract class AbstractCoroutinesTransactionAspectTests { * Check that two transactions are created and committed. */ @Test - fun twoTransactionsShouldSucceed() { + suspend fun twoTransactionsShouldSucceed() { val txatt: TransactionAttribute = DefaultTransactionAttribute() val tas1 = MapTransactionAttributeSource() tas1.register(getNameMethod!!, txatt) @@ -110,10 +107,8 @@ abstract class AbstractCoroutinesTransactionAspectTests { given(rtm.commit(status)).willReturn(Mono.empty()) val tb = DefaultTestBean() val itb = advised(tb, rtm, arrayOf(tas1, tas2)) as TestBean - runBlocking { - itb.getName() - itb.setName("myName") - } + itb.getName() + itb.setName("myName") Mockito.verify(rtm, Mockito.times(2)).commit(status) } @@ -121,7 +116,7 @@ abstract class AbstractCoroutinesTransactionAspectTests { * Check that a transaction is created and committed. */ @Test - fun transactionShouldSucceedWithNotNew() { + suspend fun transactionShouldSucceedWithNotNew() { val txatt: TransactionAttribute = DefaultTransactionAttribute() val tas = MapTransactionAttributeSource() tas.register(getNameMethod!!, txatt) @@ -132,9 +127,7 @@ abstract class AbstractCoroutinesTransactionAspectTests { given(rtm.commit(status)).willReturn(Mono.empty()) val tb = DefaultTestBean() val itb = advised(tb, rtm, tas) as TestBean - runBlocking { - itb.getName() - } + itb.getName() Mockito.verify(rtm).commit(status) } @@ -254,14 +247,8 @@ abstract class AbstractCoroutinesTransactionAspectTests { } } val itb = advised(tb, rtm, tas) as TestBean - runBlocking { - try { - itb.getName() - } - catch (actual: Exception) { - assertThat(actual).isInstanceOf(CannotCreateTransactionException::class.java) - } - } + assertThatExceptionOfType(CannotCreateTransactionException::class.java) + .isThrownBy { runBlocking { itb.getName() } } } /** @@ -270,7 +257,7 @@ abstract class AbstractCoroutinesTransactionAspectTests { * infrastructure exception was thrown to the client */ @Test - fun cannotCommitTransaction() { + suspend fun cannotCommitTransaction() { val txatt: TransactionAttribute = DefaultTransactionAttribute() val m = setNameMethod val tas = MapTransactionAttributeSource() @@ -286,17 +273,15 @@ abstract class AbstractCoroutinesTransactionAspectTests { val tb = DefaultTestBean() val itb = advised(tb, rtm, tas) as TestBean val name = "new name" - runBlocking { - try { - itb.setName(name) - } - catch (actual: Exception) { - assertThat(actual).isInstanceOf(ex.javaClass) - assertThat(actual).hasMessage(ex.message) - } - // Should have invoked target and changed name - assertThat(itb.getName()).isEqualTo(name) + try { + itb.setName(name) + } + catch (actual: Exception) { + assertThat(actual).isInstanceOf(ex.javaClass) + assertThat(actual).hasMessage(ex.message) } + // Should have invoked target and changed name + assertThat(itb.getName()).isEqualTo(name) } private fun checkReactiveTransaction(expected: Boolean) { diff --git a/spring-tx/src/test/kotlin/org/springframework/transaction/reactive/TransactionalOperatorExtensionsTests.kt b/spring-tx/src/test/kotlin/org/springframework/transaction/reactive/TransactionalOperatorExtensionsTests.kt index ff0680825a6..a07d368262d 100644 --- a/spring-tx/src/test/kotlin/org/springframework/transaction/reactive/TransactionalOperatorExtensionsTests.kt +++ b/spring-tx/src/test/kotlin/org/springframework/transaction/reactive/TransactionalOperatorExtensionsTests.kt @@ -22,6 +22,7 @@ import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.toList import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.assertThatIllegalStateException import org.junit.jupiter.api.Test import org.springframework.transaction.support.DefaultTransactionDefinition import kotlin.coroutines.AbstractCoroutineContextElement @@ -33,13 +34,11 @@ class TransactionalOperatorExtensionsTests { @Test @Suppress("UNUSED_VARIABLE") - fun commitWithSuspendingFunction() { + suspend fun commitWithSuspendingFunction() { val operator = TransactionalOperator.create(tm, DefaultTransactionDefinition()) - runBlocking { - val returnValue: Boolean = operator.executeAndAwait { - delay(1) - true - } + val returnValue: Boolean = operator.executeAndAwait { + delay(1) + true } assertThat(tm.commit).isTrue() assertThat(tm.rollback).isFalse() @@ -47,13 +46,11 @@ class TransactionalOperatorExtensionsTests { @Test @Suppress("UNUSED_VARIABLE") - fun commitWithEmptySuspendingFunction() { + suspend fun commitWithEmptySuspendingFunction() { val operator = TransactionalOperator.create(tm, DefaultTransactionDefinition()) - runBlocking { - val returnValue: Boolean? = operator.executeAndAwait { - delay(1) - null - } + val returnValue: Boolean? = operator.executeAndAwait { + delay(1) + null } assertThat(tm.commit).isTrue() assertThat(tm.rollback).isFalse() @@ -62,22 +59,20 @@ class TransactionalOperatorExtensionsTests { @Test fun rollbackWithSuspendingFunction() { val operator = TransactionalOperator.create(tm, DefaultTransactionDefinition()) - runBlocking { - try { + assertThatIllegalStateException().isThrownBy { + runBlocking { operator.executeAndAwait { delay(1) throw IllegalStateException() } - } catch (ex: IllegalStateException) { - assertThat(tm.commit).isFalse() - assertThat(tm.rollback).isTrue() - return@runBlocking } } + assertThat(tm.commit).isFalse() + assertThat(tm.rollback).isTrue() } @Test - fun commitWithFlow() { + suspend fun commitWithFlow() { val operator = TransactionalOperator.create(tm, DefaultTransactionDefinition()) val flow = flow { emit(1) @@ -85,10 +80,8 @@ class TransactionalOperatorExtensionsTests { emit(3) emit(4) } - runBlocking { - val list = flow.transactional(operator).toList() - assertThat(list).hasSize(4) - } + val list = flow.transactional(operator).toList() + assertThat(list).hasSize(4) assertThat(tm.commit).isTrue() assertThat(tm.rollback).isFalse() } @@ -100,15 +93,13 @@ class TransactionalOperatorExtensionsTests { delay(1) throw IllegalStateException() } - runBlocking { - try { + assertThatIllegalStateException().isThrownBy { + runBlocking { flow.transactional(operator).toList() - } catch (ex: IllegalStateException) { - assertThat(tm.commit).isFalse() - assertThat(tm.rollback).isTrue() - return@runBlocking } } + assertThat(tm.commit).isFalse() + assertThat(tm.rollback).isTrue() } @Test diff --git a/spring-web/src/test/kotlin/org/springframework/web/server/ServerWebExchangeExtensionsTest.kt b/spring-web/src/test/kotlin/org/springframework/web/server/ServerWebExchangeExtensionsTest.kt index 575ac111a20..7a60d6c9b38 100644 --- a/spring-web/src/test/kotlin/org/springframework/web/server/ServerWebExchangeExtensionsTest.kt +++ b/spring-web/src/test/kotlin/org/springframework/web/server/ServerWebExchangeExtensionsTest.kt @@ -19,7 +19,6 @@ package org.springframework.web.server import io.mockk.every import io.mockk.mockk import io.mockk.verify -import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.springframework.http.codec.multipart.Part @@ -35,44 +34,36 @@ import java.security.Principal class ServerWebExchangeExtensionsTest { @Test - fun `awaitFormData extension`() { + suspend fun `awaitFormData extension`() { val exchange = mockk() val multiMap = mockk>() every { exchange.formData } returns Mono.just(multiMap) - runBlocking { - assertThat(exchange.awaitFormData()).isEqualTo(multiMap) - } + assertThat(exchange.awaitFormData()).isEqualTo(multiMap) } @Test - fun `awaitMultipartData extension`() { + suspend fun `awaitMultipartData extension`() { val exchange = mockk() val multiMap = mockk>() every { exchange.multipartData } returns Mono.just(multiMap) - runBlocking { - assertThat(exchange.awaitMultipartData()).isEqualTo(multiMap) - } + assertThat(exchange.awaitMultipartData()).isEqualTo(multiMap) } @Test - fun `awaitPrincipal extension`() { + suspend fun `awaitPrincipal extension`() { val exchange = mockk() val principal = mockk() every { exchange.getPrincipal() } returns Mono.just(principal) - runBlocking { - assertThat(exchange.awaitPrincipal()).isEqualTo(principal) - } + assertThat(exchange.awaitPrincipal()).isEqualTo(principal) verify { exchange.getPrincipal() } } @Test - fun `awaitSession extension`() { + suspend fun `awaitSession extension`() { val exchange = mockk() val session = mockk() every { exchange.session } returns Mono.just(session) - runBlocking { - assertThat(exchange.awaitSession()).isEqualTo(session) - } + assertThat(exchange.awaitSession()).isEqualTo(session) } @Test @@ -80,9 +71,7 @@ class ServerWebExchangeExtensionsTest { val builder = mockk() val principal = mockk() every { builder.principal(any>()) } returns builder - runBlocking { - assertThat(builder.principal { principal }).isEqualTo(builder) - } + assertThat(builder.principal { principal }).isEqualTo(builder) verify { builder.principal(any>()) } } diff --git a/spring-web/src/test/kotlin/org/springframework/web/service/invoker/HttpServiceMethodKotlinTests.kt b/spring-web/src/test/kotlin/org/springframework/web/service/invoker/HttpServiceMethodKotlinTests.kt index c5a62bd593a..67291486179 100644 --- a/spring-web/src/test/kotlin/org/springframework/web/service/invoker/HttpServiceMethodKotlinTests.kt +++ b/spring-web/src/test/kotlin/org/springframework/web/service/invoker/HttpServiceMethodKotlinTests.kt @@ -18,7 +18,6 @@ package org.springframework.web.service.invoker import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.toList -import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatIllegalStateException import org.junit.jupiter.api.Test @@ -42,7 +41,7 @@ class KotlinHttpServiceMethodTests { private val reactorProxyFactory = HttpServiceProxyFactory.builderFor(this.reactorExchangeAdapter).build() @Test - fun coroutinesService(): Unit = runBlocking { + suspend fun coroutinesService() { val service = reactorProxyFactory.createClient(FunctionsService::class.java) val stringBody = service.stringBody() diff --git a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/ClientResponseExtensionsTests.kt b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/ClientResponseExtensionsTests.kt index bf6d887e433..b43b3f5d24e 100644 --- a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/ClientResponseExtensionsTests.kt +++ b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/ClientResponseExtensionsTests.kt @@ -19,7 +19,6 @@ package org.springframework.web.reactive.function.client import io.mockk.every import io.mockk.mockk import io.mockk.verify -import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.springframework.core.ParameterizedTypeReference @@ -74,99 +73,79 @@ class ClientResponseExtensionsTests { } @Test - fun awaitBody() { + suspend fun awaitBody() { val response = mockk() every { response.bodyToMono() } returns Mono.just("foo") - runBlocking { - assertThat(response.awaitBody()).isEqualTo("foo") - } + assertThat(response.awaitBody()).isEqualTo("foo") } @Test - fun `awaitBody with KClass parameter`() { + suspend fun `awaitBody with KClass parameter`() { val response = mockk() every { response.bodyToMono(String::class.java) } returns Mono.just("foo") - runBlocking { - assertThat(response.awaitBody(String::class)).isEqualTo("foo") - } + assertThat(response.awaitBody(String::class)).isEqualTo("foo") } @Test - fun awaitBodyOrNull() { + suspend fun awaitBodyOrNull() { val response = mockk() every { response.bodyToMono() } returns Mono.empty() - runBlocking { - assertThat(response.awaitBodyOrNull()).isNull() - } + assertThat(response.awaitBodyOrNull()).isNull() } @Test - fun `awaitBodyOrNullGeneric with KClass parameter`() { + suspend fun `awaitBodyOrNullGeneric with KClass parameter`() { val response = mockk() every { response.bodyToMono(String::class.java) } returns Mono.empty() - runBlocking { - assertThat(response.awaitBodyOrNull(String::class)).isNull() - } + assertThat(response.awaitBodyOrNull(String::class)).isNull() } @Test - fun awaitEntity() { + suspend fun awaitEntity() { val response = mockk() val entity = ResponseEntity("foo", HttpStatus.OK) every { response.toEntity() } returns Mono.just(entity) - runBlocking { - assertThat(response.awaitEntity()).isEqualTo(entity) - } + assertThat(response.awaitEntity()).isEqualTo(entity) } @Test - fun `awaitEntity with KClass parameter`() { + suspend fun `awaitEntity with KClass parameter`() { val response = mockk() val entity = ResponseEntity("foo", HttpStatus.OK) every { response.toEntity(String::class.java) } returns Mono.just(entity) - runBlocking { - assertThat(response.awaitEntity(String::class)).isEqualTo(entity) - } + assertThat(response.awaitEntity(String::class)).isEqualTo(entity) } @Test - fun awaitEntityList() { + suspend fun awaitEntityList() { val response = mockk() val entity = ResponseEntity(listOf("foo"), HttpStatus.OK) every { response.toEntityList() } returns Mono.just(entity) - runBlocking { - assertThat(response.awaitEntityList()).isEqualTo(entity) - } + assertThat(response.awaitEntityList()).isEqualTo(entity) } @Test - fun `awaitEntityList with KClass parameter`() { + suspend fun `awaitEntityList with KClass parameter`() { val response = mockk() val entity = ResponseEntity(listOf("foo"), HttpStatus.OK) every { response.toEntityList(String::class.java) } returns Mono.just(entity) - runBlocking { - assertThat(response.awaitEntityList(String::class)).isEqualTo(entity) - } + assertThat(response.awaitEntityList(String::class)).isEqualTo(entity) } @Test - fun awaitBodilessEntity() { + suspend fun awaitBodilessEntity() { val response = mockk() val entity = mockk>() every { response.toBodilessEntity() } returns Mono.just(entity) - runBlocking { - assertThat(response.awaitBodilessEntity()).isEqualTo(entity) - } + assertThat(response.awaitBodilessEntity()).isEqualTo(entity) } @Test - fun createExceptionAndAwait() { + suspend fun createExceptionAndAwait() { val response = mockk() val exception = mockk() every { response.createException() } returns Mono.just(exception) - runBlocking { - assertThat(response.createExceptionAndAwait()).isEqualTo(exception) - } + assertThat(response.createExceptionAndAwait()).isEqualTo(exception) } class Foo diff --git a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/CoExchangeFilterFunctionTests.kt b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/CoExchangeFilterFunctionTests.kt index 264b5b90ca1..456a2dde13f 100644 --- a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/CoExchangeFilterFunctionTests.kt +++ b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/CoExchangeFilterFunctionTests.kt @@ -18,7 +18,6 @@ package org.springframework.web.reactive.function.client import io.mockk.mockk import kotlinx.coroutines.delay -import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -30,12 +29,10 @@ import org.junit.jupiter.api.Test class CoExchangeFilterFunctionTests { @Test - fun exchange() { + suspend fun exchange() { val response = mockk() val exchangeFunction = MyCoExchangeFunction(response) - runBlocking { - assertThat(exchangeFunction.exchange(mockk())).isEqualTo(response) - } + assertThat(exchangeFunction.exchange(mockk())).isEqualTo(response) } } diff --git a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/WebClientExtensionsTests.kt b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/WebClientExtensionsTests.kt index 368faeecf1e..514deffc602 100644 --- a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/WebClientExtensionsTests.kt +++ b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/WebClientExtensionsTests.kt @@ -102,12 +102,10 @@ class WebClientExtensionsTests { } @Test - fun `awaitExchange with function parameter`() { + suspend fun `awaitExchange with function parameter`() { val foo = mockk() every { requestBodySpec.exchangeToMono(any>>()) } returns Mono.just(foo) - runBlocking { - assertThat(requestBodySpec.awaitExchange { foo }).isEqualTo(foo) - } + assertThat(requestBodySpec.awaitExchange { foo }).isEqualTo(foo) } @Test @@ -123,21 +121,17 @@ class WebClientExtensionsTests { } @Test - fun `awaitExchangeOrNull returning null`() { + suspend fun `awaitExchangeOrNull returning null`() { val foo = mockk() every { requestBodySpec.exchangeToMono(any>>()) } returns Mono.empty() - runBlocking { - assertThat(requestBodySpec.awaitExchangeOrNull { foo }).isEqualTo(null) - } + assertThat(requestBodySpec.awaitExchangeOrNull { foo }).isEqualTo(null) } @Test - fun `awaitExchangeOrNull returning object`() { + suspend fun `awaitExchangeOrNull returning object`() { val foo = mockk() every { requestBodySpec.exchangeToMono(any>>()) } returns Mono.just(foo) - runBlocking { - assertThat(requestBodySpec.awaitExchangeOrNull { foo }).isEqualTo(foo) - } + assertThat(requestBodySpec.awaitExchangeOrNull { foo }).isEqualTo(foo) } @Test @@ -153,65 +147,53 @@ class WebClientExtensionsTests { } @Test - fun exchangeToFlow() { + suspend fun exchangeToFlow() { val foo = mockk() every { requestBodySpec.exchangeToFlux(any>>()) } returns Flux.just(foo, foo) - runBlocking { - assertThat(requestBodySpec.exchangeToFlow { - flow { - emit(foo) - emit(foo) - } - }.toList()).isEqualTo(listOf(foo, foo)) - } + assertThat(requestBodySpec.exchangeToFlow { + flow { + emit(foo) + emit(foo) + } + }.toList()).isEqualTo(listOf(foo, foo)) } @Test - fun awaitBody() { + suspend fun awaitBody() { val spec = mockk() every { spec.bodyToMono() } returns Mono.just("foo") - runBlocking { - assertThat(spec.awaitBody()).isEqualTo("foo") - } + assertThat(spec.awaitBody()).isEqualTo("foo") } @Test - fun `awaitBody of type Unit`() { + suspend fun `awaitBody of type Unit`() { val spec = mockk() val entity = mockk>() every { spec.toBodilessEntity() } returns Mono.just(entity) - runBlocking { - assertThat(spec.awaitBody()).isEqualTo(Unit) - } + assertThat(spec.awaitBody()).isEqualTo(Unit) } @Test - fun awaitBodyOrNull() { + suspend fun awaitBodyOrNull() { val spec = mockk() every { spec.bodyToMono() } returns Mono.just("foo") - runBlocking { - assertThat(spec.awaitBodyOrNull()).isEqualTo("foo") - } + assertThat(spec.awaitBodyOrNull()).isEqualTo("foo") } @Test - fun `awaitBodyOrNull of type Unit`() { + suspend fun `awaitBodyOrNull of type Unit`() { val spec = mockk() val entity = mockk>() every { spec.toBodilessEntity() } returns Mono.just(entity) - runBlocking { - assertThat(spec.awaitBodyOrNull()).isEqualTo(Unit) - } + assertThat(spec.awaitBodyOrNull()).isEqualTo(Unit) } @Test - fun awaitBodilessEntity() { + suspend fun awaitBodilessEntity() { val spec = mockk() val entity = mockk>() every { spec.toBodilessEntity() } returns Mono.just(entity) - runBlocking { - assertThat(spec.awaitBodilessEntity()).isEqualTo(entity) - } + assertThat(spec.awaitBodilessEntity()).isEqualTo(entity) } @Test diff --git a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/support/WebClientHttpServiceProxyKotlinTests.kt b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/support/WebClientHttpServiceProxyKotlinTests.kt index b8790665564..23f224501e2 100644 --- a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/support/WebClientHttpServiceProxyKotlinTests.kt +++ b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/support/WebClientHttpServiceProxyKotlinTests.kt @@ -15,7 +15,6 @@ */ package org.springframework.web.reactive.function.client.support -import kotlinx.coroutines.runBlocking import mockwebserver3.MockResponse import mockwebserver3.MockWebServer import org.assertj.core.api.Assertions.assertThat @@ -69,12 +68,10 @@ class KotlinWebClientHttpServiceGroupAdapterServiceProxyTests { } @Test - fun greetingSuspending() { + suspend fun greetingSuspending() { prepareResponse { it.setHeader("Content-Type", "text/plain").body("Hello Spring!") } - runBlocking { - val greeting = initHttpService().getGreetingSuspending() - assertThat(greeting).isEqualTo("Hello Spring!") - } + val greeting = initHttpService().getGreetingSuspending() + assertThat(greeting).isEqualTo("Hello Spring!") } @Test @@ -94,7 +91,7 @@ class KotlinWebClientHttpServiceGroupAdapterServiceProxyTests { } @Test - fun greetingSuspendingWithRequestAttribute() { + suspend fun greetingSuspendingWithRequestAttribute() { val attributes: MutableMap = HashMap() val webClient = WebClient.builder() .baseUrl(server.url("/").toString()) @@ -105,11 +102,9 @@ class KotlinWebClientHttpServiceGroupAdapterServiceProxyTests { .build() prepareResponse { it.setHeader("Content-Type", "text/plain").body("Hello Spring!") } val service = initHttpService(webClient) - runBlocking { - val greeting = service.getGreetingSuspendingWithAttribute("myAttributeValue") - assertThat(greeting).isEqualTo("Hello Spring!") - assertThat(attributes).containsEntry("myAttribute", "myAttributeValue") - } + val greeting = service.getGreetingSuspendingWithAttribute("myAttributeValue") + assertThat(greeting).isEqualTo("Hello Spring!") + assertThat(attributes).containsEntry("myAttribute", "myAttributeValue") } @Test diff --git a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/RenderingResponseExtensionsTests.kt b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/RenderingResponseExtensionsTests.kt index 081a05dd3cc..c4814ab4e86 100644 --- a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/RenderingResponseExtensionsTests.kt +++ b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/RenderingResponseExtensionsTests.kt @@ -19,20 +19,17 @@ package org.springframework.web.reactive.function.server import io.mockk.every import io.mockk.mockk import io.mockk.verify -import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Test import reactor.core.publisher.Mono class RenderingResponseExtensionsTests { @Test - fun buildAndAwait() { + suspend fun buildAndAwait() { val builder = mockk() val response = mockk() every { builder.build() } returns Mono.just(response) - runBlocking { - builder.buildAndAwait() - } + builder.buildAndAwait() verify { builder.build() } diff --git a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensionsTests.kt b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensionsTests.kt index eeeb3dafd07..12fb7931f3d 100644 --- a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensionsTests.kt +++ b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensionsTests.kt @@ -19,7 +19,6 @@ package org.springframework.web.reactive.function.server import io.mockk.every import io.mockk.mockk import io.mockk.verify -import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.springframework.core.ParameterizedTypeReference @@ -70,71 +69,55 @@ class ServerRequestExtensionsTests { } @Test - fun `awaitBody with reified type parameters`() { + suspend fun `awaitBody with reified type parameters`() { every { request.bodyToMono() } returns Mono.just("foo") - runBlocking { - assertThat(request.awaitBody()).isEqualTo("foo") - } + assertThat(request.awaitBody()).isEqualTo("foo") } @Test - fun `awaitBody with KClass parameters`() { + suspend fun `awaitBody with KClass parameters`() { every { request.bodyToMono(String::class.java) } returns Mono.just("foo") - runBlocking { - assertThat(request.awaitBody(String::class)).isEqualTo("foo") - } + assertThat(request.awaitBody(String::class)).isEqualTo("foo") } @Test - fun `awaitBodyOrNull with reified type parameters`() { + suspend fun `awaitBodyOrNull with reified type parameters`() { every { request.bodyToMono() } returns Mono.empty() - runBlocking { - assertThat(request.awaitBodyOrNull()).isNull() - } + assertThat(request.awaitBodyOrNull()).isNull() } @Test - fun `awaitBodyOrNull with KClass parameters`() { + suspend fun `awaitBodyOrNull with KClass parameters`() { every { request.bodyToMono(String::class.java) } returns Mono.empty() - runBlocking { - assertThat(request.awaitBodyOrNull(String::class)).isNull() - } + assertThat(request.awaitBodyOrNull(String::class)).isNull() } @Test - fun awaitFormData() { + suspend fun awaitFormData() { val map = mockk>() every { request.formData() } returns Mono.just(map) - runBlocking { - assertThat(request.awaitFormData()).isEqualTo(map) - } + assertThat(request.awaitFormData()).isEqualTo(map) } @Test - fun awaitMultipartData() { + suspend fun awaitMultipartData() { val map = mockk>() every { request.multipartData() } returns Mono.just(map) - runBlocking { - assertThat(request.awaitMultipartData()).isEqualTo(map) - } + assertThat(request.awaitMultipartData()).isEqualTo(map) } @Test - fun awaitPrincipal() { + suspend fun awaitPrincipal() { val principal = mockk() every { request.principal() } returns Mono.just(principal) - runBlocking { - assertThat(request.awaitPrincipal()).isEqualTo(principal) - } + assertThat(request.awaitPrincipal()).isEqualTo(principal) } @Test - fun awaitSession() { + suspend fun awaitSession() { val session = mockk() every { request.session() } returns Mono.just(session) - runBlocking { - assertThat(request.awaitSession()).isEqualTo(session) - } + assertThat(request.awaitSession()).isEqualTo(session) } @Test diff --git a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerResponseExtensionsTests.kt b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerResponseExtensionsTests.kt index 59afe71d3c9..c16f637054b 100644 --- a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerResponseExtensionsTests.kt +++ b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerResponseExtensionsTests.kt @@ -21,7 +21,6 @@ import io.mockk.mockk import io.mockk.verify import io.reactivex.rxjava3.core.Flowable import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.reactivestreams.Publisher @@ -63,39 +62,33 @@ class ServerResponseExtensionsTests { } @Test - fun `BodyBuilder#bodyAndAwait with object parameter`() { + suspend fun `BodyBuilder#bodyAndAwait with object parameter`() { val response = mockk() val body = "foo" every { bodyBuilder.bodyValue(ofType()) } returns Mono.just(response) - runBlocking { - bodyBuilder.bodyValueAndAwait(body) - } + bodyBuilder.bodyValueAndAwait(body) verify { bodyBuilder.bodyValue(ofType()) } } @Test - fun `BodyBuilder#bodyValueWithTypeAndAwait with object parameter and reified type parameters`() { + suspend fun `BodyBuilder#bodyValueWithTypeAndAwait with object parameter and reified type parameters`() { val response = mockk() val body = listOf("foo", "bar") every { bodyBuilder.bodyValue(ofType>(), object : ParameterizedTypeReference>() {}) } returns Mono.just(response) - runBlocking { - bodyBuilder.bodyValueWithTypeAndAwait>(body) - } + bodyBuilder.bodyValueWithTypeAndAwait>(body) verify { bodyBuilder.bodyValue(body, object : ParameterizedTypeReference>() {}) } } @Test - fun `BodyBuilder#bodyAndAwait with flow parameter`() { + suspend fun `BodyBuilder#bodyAndAwait with flow parameter`() { val response = mockk() val body = mockk>>() every { bodyBuilder.body(ofType>>(), object : ParameterizedTypeReference>() {}) } returns Mono.just(response) - runBlocking { - bodyBuilder.bodyAndAwait(body) - } + bodyBuilder.bodyAndAwait(body) verify { bodyBuilder.body(ofType>>(), object : ParameterizedTypeReference>() {}) } @@ -126,38 +119,32 @@ class ServerResponseExtensionsTests { } @Test - fun `BodyBuilder#renderAndAwait with a vararg parameter`() { + suspend fun `BodyBuilder#renderAndAwait with a vararg parameter`() { val response = mockk() every { bodyBuilder.render("foo", any(), any()) } returns Mono.just(response) - runBlocking { - bodyBuilder.renderAndAwait("foo", "bar", "baz") - } + bodyBuilder.renderAndAwait("foo", "bar", "baz") verify { bodyBuilder.render("foo", any(), any()) } } @Test - fun `BodyBuilder#renderAndAwait with a Map parameter`() { + suspend fun `BodyBuilder#renderAndAwait with a Map parameter`() { val response = mockk() val map = mockk>() every { bodyBuilder.render("foo", map) } returns Mono.just(response) - runBlocking { - bodyBuilder.renderAndAwait("foo", map) - } + bodyBuilder.renderAndAwait("foo", map) verify { bodyBuilder.render("foo", map) } } @Test - fun `HeadersBuilder#buildAndAwait`() { + suspend fun `HeadersBuilder#buildAndAwait`() { val response = mockk() val builder = mockk>() every { builder.build() } returns Mono.just(response) - runBlocking { - assertThat(builder.buildAndAwait()).isEqualTo(response) - } + assertThat(builder.buildAndAwait()).isEqualTo(response) } class Foo