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 #951 from m-burst/issue-774
Fix verifier logic for slots and different matchers
- Loading branch information
Showing
3 changed files
with
106 additions
and
6 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
80 changes: 80 additions & 0 deletions
80
modules/mockk/src/commonTest/kotlin/io/mockk/it/CaptureSubclassVerificationTest.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,80 @@ | ||
package io.mockk.it | ||
|
||
import io.mockk.Runs | ||
import io.mockk.every | ||
import io.mockk.just | ||
import io.mockk.mockk | ||
import io.mockk.slot | ||
import io.mockk.verify | ||
import io.mockk.verifyOrder | ||
import io.mockk.verifySequence | ||
import kotlin.test.Test | ||
import kotlin.test.assertIs | ||
import kotlin.test.assertTrue | ||
|
||
/** | ||
* See issue #774. | ||
*/ | ||
class CaptureSubclassVerificationTest { | ||
|
||
interface Interface | ||
|
||
class Subclass1 : Interface | ||
|
||
class Subclass2 : Interface | ||
|
||
interface Service { | ||
fun method(obj: Interface) | ||
} | ||
|
||
@Test | ||
fun `test unordered`() { | ||
val service = mockk<Service> { | ||
every { method(any()) } just Runs | ||
} | ||
|
||
service.method(Subclass1()) | ||
service.method(Subclass2()) | ||
|
||
val slot = slot<Subclass2>() | ||
verify(exactly = 1) { service.method(capture(slot)) } | ||
assertTrue(slot.isCaptured) | ||
assertIs<Subclass2>(slot.captured) | ||
} | ||
|
||
@Test | ||
fun `test ordered`() { | ||
val service = mockk<Service> { | ||
every { method(any()) } just Runs | ||
} | ||
|
||
service.method(Subclass1()) | ||
service.method(Subclass2()) | ||
|
||
val slot = slot<Subclass2>() | ||
verifyOrder { | ||
service.method(any()) | ||
service.method(capture(slot)) | ||
} | ||
assertTrue(slot.isCaptured) | ||
assertIs<Subclass2>(slot.captured) | ||
} | ||
|
||
@Test | ||
fun `test sequence`() { | ||
val service = mockk<Service> { | ||
every { method(any()) } just Runs | ||
} | ||
|
||
service.method(Subclass1()) | ||
service.method(Subclass2()) | ||
|
||
val slot = slot<Subclass2>() | ||
verifySequence { | ||
service.method(any()) | ||
service.method(capture(slot)) | ||
} | ||
assertTrue(slot.isCaptured) | ||
assertIs<Subclass2>(slot.captured) | ||
} | ||
} |
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