File tree Expand file tree Collapse file tree
jvmTest/kotlin/io/mockk/it Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11public final class io/mockk/JVMMockKKt {
2+ public static final fun clearStaticMockk ([Lkotlin/reflect/KFunction;)V
3+ public static final fun clearStaticMockk ([Lkotlin/reflect/KProperty;)V
24 public static final fun getDeclaringKotlinFile (Lkotlin/reflect/KFunction;)Lkotlin/reflect/KClass;
35 public static final fun mockkStatic ([Lkotlin/reflect/KFunction;)V
46 public static final fun mockkStatic ([Lkotlin/reflect/KFunction;Lkotlin/jvm/functions/Function0;)V
Original file line number Diff line number Diff line change @@ -44,6 +44,18 @@ fun unmockkStatic(vararg functions: KFunction<*>) =
4444fun unmockkStatic (vararg functions : KProperty <* >) =
4545 unmockkStatic(* functions.map(KProperty <* >::getter).toTypedArray())
4646
47+ /* *
48+ * Clear static mocks.
49+ */
50+ fun clearStaticMockk (vararg functions : KFunction <* >) =
51+ clearStaticMockk(* functions.map { it.declaringKotlinFile }.toTypedArray())
52+
53+ /* *
54+ * Clear static mocks.
55+ */
56+ fun clearStaticMockk (vararg functions : KProperty <* >) =
57+ clearStaticMockk(* functions.map(KProperty <* >::getter).toTypedArray())
58+
4759/* *
4860 * Builds a static mock and unmocks it after the block has been executed.
4961 */
Original file line number Diff line number Diff line change 11package io.mockk.it
22
3+ import io.mockk.clearStaticMockk
34import io.mockk.every
45import io.mockk.mockkStatic
56import io.mockk.unmockkStatic
@@ -73,6 +74,19 @@ class StaticMockkTest {
7374 verify { 5 op 6 }
7475 }
7576
77+ @Test
78+ fun extensionFunctionClearStaticMock () {
79+ mockkStatic(Int ::op)
80+
81+ every { 5 op 6 } returns 2
82+
83+ assertEquals(2 , 5 op 6 )
84+
85+ clearStaticMockk(Int ::op)
86+
87+ verify(exactly = 0 ) { 5 op 6 }
88+ }
89+
7690 @Test
7791 fun extensionPropertyStaticMock () {
7892 mockkStatic(Int ::selfOp)
@@ -106,4 +120,17 @@ class StaticMockkTest {
106120
107121 verify { 5 .selfOp }
108122 }
123+
124+ @Test
125+ fun extensionPropertyClearStaticMock () {
126+ mockkStatic(Int ::selfOp)
127+
128+ every { 5 .selfOp } returns 2
129+
130+ assertEquals(2 , 5 .selfOp)
131+
132+ clearStaticMockk(Int ::selfOp)
133+
134+ verify(exactly = 0 ) { 5 .selfOp }
135+ }
109136}
You can’t perform that action at this time.
0 commit comments