Refine TransactionalOperator.executeAndAwait nullability

Before this commit, TransactionalOperator.executeAndAwait had a rigid
null-safety handling. This commit takes advantage of Kotlin capability
to allow to deal with both non-null and nullable depending on the
nullability of the lambda.

Closes gh-29919
This commit is contained in:
Sébastien Deleuze
2023-02-02 14:35:39 +01:00
parent 4beb05ddb3
commit e170c16b02
2 changed files with 22 additions and 6 deletions

View File

@@ -22,7 +22,6 @@ import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.fail
import org.springframework.transaction.support.DefaultTransactionDefinition
class TransactionalOperatorExtensionsTests {
@@ -30,10 +29,11 @@ class TransactionalOperatorExtensionsTests {
private val tm = ReactiveTestTransactionManager(false, true)
@Test
@Suppress("UNUSED_VARIABLE")
fun commitWithSuspendingFunction() {
val operator = TransactionalOperator.create(tm, DefaultTransactionDefinition())
runBlocking {
operator.executeAndAwait {
val returnValue: Boolean = operator.executeAndAwait {
delay(1)
true
}
@@ -43,10 +43,11 @@ class TransactionalOperatorExtensionsTests {
}
@Test
@Suppress("UNUSED_VARIABLE")
fun commitWithEmptySuspendingFunction() {
val operator = TransactionalOperator.create(tm, DefaultTransactionDefinition())
runBlocking {
operator.executeAndAwait {
val returnValue: Boolean? = operator.executeAndAwait {
delay(1)
null
}
@@ -69,7 +70,6 @@ class TransactionalOperatorExtensionsTests {
assertThat(tm.rollback).isTrue()
return@runBlocking
}
fail("")
}
}