@@ -690,9 +690,10 @@ open class MockKMatcherScope(
690690 val lambda : CapturingSlot <Function <* >>
691691) {
692692
693- fun <T : Any > match (matcher : Matcher <T >, kclass : KClass <T >): T {
693+ fun <T : Any > match (matcher : Matcher <T >, kclass : KClass <T >): T {
694694 return callRecorder.matcher(matcher, kclass)
695695 }
696+
696697 inline fun <reified T : Any > match (matcher : Matcher <T >): T {
697698 return callRecorder.matcher(matcher, T ::class )
698699 }
@@ -720,6 +721,7 @@ open class MockKMatcherScope(
720721 */
721722 inline fun <reified T : Any > eq (value : T , inverse : Boolean = false): T =
722723 match(EqMatcher (value, inverse = inverse))
724+
723725 /* *
724726 * Matches if the value is not equal to the provided [value] via the `deepEquals` function.
725727 */
@@ -730,6 +732,7 @@ open class MockKMatcherScope(
730732 */
731733 inline fun <reified T : Any > refEq (value : T , inverse : Boolean = false): T =
732734 match(EqMatcher (value, ref = true , inverse = inverse))
735+
733736 /* *
734737 * Matches if the value is not equal to the provided [value] via reference comparison.
735738 */
@@ -738,13 +741,15 @@ open class MockKMatcherScope(
738741 /* *
739742 * Matches any argument given a [KClass]
740743 */
741- fun <T : Any > any (classifier : KClass <T >): T = match(ConstantMatcher (true ), classifier)
744+ fun <T : Any > any (classifier : KClass <T >): T = match(ConstantMatcher (true ), classifier)
745+
742746 /* *
743747 * Matches any argument.
744748 */
745749 inline fun <reified T : Any > any (): T = match(ConstantMatcher (true ))
746750
747751 inline fun <reified T : Any > capture (lst : MutableList <T >): T = match(CaptureMatcher (lst, T ::class ))
752+
748753 /* *
749754 * Captures a non-nullable value to a [CapturingSlot].
750755 *
@@ -782,7 +787,8 @@ open class MockKMatcherScope(
782787 * network.download("testfile")
783788 * // slot.captured is now "testfile"
784789 */
785- inline fun <reified T : Any > captureNullable (lst : CapturingSlot <T ?>): T ? = match(CapturingNullableSlotMatcher (lst, T ::class ))
790+ inline fun <reified T : Any > captureNullable (lst : CapturingSlot <T ?>): T ? =
791+ match(CapturingNullableSlotMatcher (lst, T ::class ))
786792
787793 /* *
788794 * Captures a nullable value to a [MutableList].
@@ -797,12 +803,14 @@ open class MockKMatcherScope(
797803 * Matches if the value is equal to the provided [value] via the `compareTo` function.
798804 */
799805 inline fun <reified T : Comparable <T >> cmpEq (value : T ): T = match(ComparingMatcher (value, 0 , T ::class ))
806+
800807 /* *
801808 * Matches if the value is more than the provided [value] via the `compareTo` function.
802809 * @param andEquals matches more than or equal to
803810 */
804811 inline fun <reified T : Comparable <T >> more (value : T , andEquals : Boolean = false): T =
805812 match(ComparingMatcher (value, if (andEquals) 2 else 1 , T ::class ))
813+
806814 /* *
807815 * Matches if the value is less than the provided [value] via the `compareTo` function.
808816 * @param andEquals matches less than or equal to
@@ -824,10 +832,12 @@ open class MockKMatcherScope(
824832 * Combines two matchers via a logical and.
825833 */
826834 inline fun <reified T : Any > and (left : T , right : T ): T = match(AndOrMatcher <T >(true , left, right))
835+
827836 /* *
828837 * Combines two matchers via a logical or.
829838 */
830839 inline fun <reified T : Any > or (left : T , right : T ): T = match(AndOrMatcher <T >(false , left, right))
840+
831841 /* *
832842 * Negates the matcher.
833843 */
@@ -840,6 +850,7 @@ open class MockKMatcherScope(
840850 */
841851 inline fun <reified T : Any > isNull (inverse : Boolean = false): T = match(NullCheckMatcher <T >(inverse))
842852 inline fun <reified T : Any , R : T > ofType (cls : KClass <R >): T = match(OfTypeMatcher <T >(cls))
853+
843854 /* *
844855 * Checks if the value belongs to the type.
845856 */
@@ -2182,6 +2193,48 @@ class MockKVerificationScope(
21822193 }
21832194}
21842195
2196+ /* *
2197+ * Part of DSL. Additional operations for call count verification scope.
2198+ */
2199+ class MockKCallCountVerificationScope {
2200+ operator fun Int.times (verifyBlock : MockKVerificationScope .() -> Unit ) {
2201+ MockKGateway .implementation().verifier.verify(
2202+ VerificationParameters (Ordering .UNORDERED , min = this , max = this , inverse = false , timeout = 0 ),
2203+ verifyBlock,
2204+ null
2205+ )
2206+ }
2207+
2208+ operator fun IntRange.times (verifyBlock : MockKVerificationScope .() -> Unit ) {
2209+ MockKGateway .implementation().verifier.verify(
2210+ VerificationParameters (Ordering .UNORDERED , min = this .first, max = this .last, inverse = false , timeout = 0 ),
2211+ verifyBlock,
2212+ null
2213+ )
2214+ }
2215+ }
2216+
2217+ /* *
2218+ * Part of DSL. Additional operations for coroutine call count verification scope.
2219+ */
2220+ class MockKCallCountCoVerificationScope {
2221+ operator fun Int.times (verifyBlock : suspend MockKVerificationScope .() -> Unit ) {
2222+ MockKGateway .implementation().verifier.verify(
2223+ VerificationParameters (Ordering .UNORDERED , min = this , max = this , inverse = false , timeout = 0 ),
2224+ null ,
2225+ verifyBlock
2226+ )
2227+ }
2228+
2229+ operator fun IntRange.times (verifyBlock : suspend MockKVerificationScope .() -> Unit ) {
2230+ MockKGateway .implementation().verifier.verify(
2231+ VerificationParameters (Ordering .UNORDERED , min = this .first, max = this .last, inverse = false , timeout = 0 ),
2232+ null ,
2233+ verifyBlock
2234+ )
2235+ }
2236+ }
2237+
21852238/* *
21862239 * Part of DSL. Object to represent phrase "wasNot Called"
21872240 */
@@ -2675,7 +2728,7 @@ class CapturingSlot<T : Any?> {
26752728 * For init state (not yet captured) returns false.
26762729 */
26772730 val isNull
2678- get() = when (val value = capturedValue) {
2731+ get() = when (val value = capturedValue) {
26792732 is CapturedValue .Value -> value.value == null
26802733 is CapturedValue .NotYetCaptured -> false
26812734 }
0 commit comments