Skip to content

Commit

Permalink
Implement clearStaticMockk for KFunction and KProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
krocard committed Apr 2, 2024
1 parent 143f6bb commit db48a53
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class StaticMockTest {

@Test
fun simpleStaticMock() {
mockkStatic("io.mockk.it.StaticMockTestKt")
mockkStatic(::op)

every { 5 op 6 } returns 2

Expand All @@ -24,15 +24,15 @@ class StaticMockTest {

@Test
fun clearStateStaticMock() {
mockkStatic("io.mockk.it.StaticMockTestKt")
mockkStatic(::op)

every { 5 op 6 } returns 2

assertEquals(2, 5 op 6)

verify { 5 op 6 }

mockkStatic("io.mockk.it.StaticMockTestKt")
mockkStatic(::op)

verify(exactly = 0) { 5 op 6 }

Expand Down
12 changes: 12 additions & 0 deletions modules/mockk/src/jvmMain/kotlin/io/mockk/MockK.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ fun unmockkStatic(vararg functions: KFunction<*>) =
fun unmockkStatic(vararg functions: KProperty<*>) =
unmockkStatic(*functions.map(KProperty<*>::getter).toTypedArray())

/**
* Clear static mocks.
*/
fun clearStaticMockk(vararg functions: KFunction<*>) =
clearStaticMockk(*functions.map { it.declaringKotlinFile }.toTypedArray())

/**
* Clear static mocks.
*/
fun clearStaticMockk(vararg functions: KProperty<*>) =
clearStaticMockk(*functions.map(KProperty<*>::getter).toTypedArray())

/**
* Builds a static mock and unmocks it after the block has been executed.
*/
Expand Down

0 comments on commit db48a53

Please sign in to comment.