Skip to content

Commit

Permalink
Merge pull request #759 from NWuensche/master
Browse files Browse the repository at this point in the history
Add andThenJust
  • Loading branch information
Raibaz committed Dec 1, 2021
2 parents 2b43b25 + 366eb7e commit 8c66b96
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -1277,6 +1277,7 @@ So this is similar to the `returnsMany` semantics.
|`coAndThen { code }`|specify that the matched call answers with a coroutine code block with `answer scope`|
|`andThenAnswer answerObj`|specify that the matched call answers with an Answer object|
|`andThen { nothing }`|specify that the matched call answers null|
|`andThenJust Runs`|specify that the matched call is returning Unit (available since v1.12.2)|

### Answer scope

Expand Down
7 changes: 7 additions & 0 deletions dsl/common/src/main/kotlin/io/mockk/API.kt
Expand Up @@ -6,6 +6,7 @@ import io.mockk.InternalPlatformDsl.toStr
import io.mockk.MockKGateway.*
import kotlin.coroutines.Continuation
import kotlin.reflect.KClass
import io.mockk.*

/**
* Exception thrown by library
Expand Down Expand Up @@ -2160,6 +2161,12 @@ class MockKAdditionalAnswerScope<T, B>(
andThenAnswer(CoFunctionAnswer { MockKAnswerScope<T, B>(lambda, it).answer(it) })
}

/**
* Part of DSL. Answer placeholder for Unit returning functions.
*/
@Suppress("UNUSED_PARAMETER")
infix fun MockKAdditionalAnswerScope<Unit, Unit>.andThenJust(runs: Runs) = andThenAnswer(ConstantAnswer(Unit))


internal fun <T> List<T>.allConst() = this.map { ConstantAnswer(it) }

Expand Down

0 comments on commit 8c66b96

Please sign in to comment.