Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1174 from Gosunet/master
Fix wasNotshould throw exception when called on non mocked object
- Loading branch information
Showing
4 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
modules/mockk/src/commonTest/kotlin/io/mockk/it/WasNotCalledTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.mockk.it | ||
|
||
import io.mockk.* | ||
import kotlinx.coroutines.flow.flowOf | ||
import org.junit.jupiter.api.BeforeEach | ||
import kotlin.test.Test | ||
import kotlin.test.assertFailsWith | ||
|
||
class WasNotCalledTest { | ||
|
||
val mock = mockk<MockCls>() | ||
|
||
@Test | ||
fun wasNotCalledOnNonMockedObject() { | ||
assertFailsWith<MockKException>("was not can should throw MockKException on non mock object") { | ||
verify { mock.flowOp(1, 2) wasNot Called } | ||
} | ||
} | ||
|
||
@Test | ||
fun wasNotCalledOnMockedObject() { | ||
verify { mock wasNot Called } | ||
} | ||
|
||
@Test | ||
fun wasNotCalledShouldThrowAssertionErrorIfMockHasBeenCalled() { | ||
assertFailsWith<AssertionError>("was not can should throw AssertionError if mock has been called") { | ||
every { mock.flowOp(1, 2) } returns flowOf(1, 2) | ||
|
||
mock.flowOp(1, 2) | ||
verify { mock wasNot Called } | ||
} | ||
} | ||
|
||
class MockCls { | ||
fun flowOp(a: Int = 1, b: Int = 2) = flowOf(a, b) | ||
} | ||
} |