-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
TestWithMocks
logic into ITestsWithMocks
so that it can be u…
…sed in test classes that extend something else (fixes #50).
- Loading branch information
1 parent
2af48b3
commit f8da6ef
Showing
4 changed files
with
81 additions
and
42 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
58 changes: 58 additions & 0 deletions
58
...-helper/mockmp-test-helper/src/commonMain/kotlin/org/kodein/mock/tests/ITestsWithMocks.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,58 @@ | ||
package org.kodein.mock.tests | ||
|
||
import org.kodein.mock.ArgConstraintsBuilder | ||
import org.kodein.mock.Mocker | ||
import org.kodein.mock.VerificationBuilder | ||
import kotlin.test.BeforeTest | ||
|
||
|
||
public interface ITestsWithMocks { | ||
|
||
public class State { | ||
private val defs = ArrayList<TestsWithMocks.Deferred<*>>() | ||
public val mocker: Mocker = Mocker() | ||
|
||
public fun initDeferred() { | ||
defs.forEach { it.init() } | ||
} | ||
|
||
public fun clearDeferred() { | ||
defs.forEach { it.clear() } | ||
} | ||
|
||
public fun <T : Any> withMocks(create: () -> T): TestsWithMocks.Deferred<T> = TestsWithMocks.Deferred(create).also { defs.add(it) } | ||
} | ||
|
||
public val mocksState: State | ||
|
||
public val mocker: Mocker get() = mocksState.mocker | ||
|
||
public fun initDeferred(): Unit = mocksState.initDeferred() | ||
|
||
public fun clearDeferred(): Unit = mocksState.clearDeferred() | ||
|
||
public fun <T : Any> withMocks(create: () -> T): TestsWithMocks.Deferred<T> = mocksState.withMocks(create) | ||
|
||
public fun <T> every(block: ArgConstraintsBuilder.() -> T) : Mocker.Every<T> = | ||
mocker.every(block) | ||
public suspend fun <T> everySuspending(block: suspend ArgConstraintsBuilder.() -> T) : Mocker.EverySuspend<T> = | ||
mocker.everySuspending(block) | ||
|
||
public fun verify(exhaustive: Boolean = true, inOrder: Boolean = true, block: VerificationBuilder.() -> Unit): Unit = | ||
mocker.verify(exhaustive = exhaustive, inOrder = inOrder, block) | ||
public suspend fun verifyWithSuspend(exhaustive: Boolean = true, inOrder: Boolean = true, block: suspend VerificationBuilder.() -> Unit): Unit = | ||
mocker.verifyWithSuspend(exhaustive = exhaustive, inOrder = inOrder, block) | ||
|
||
@BeforeTest | ||
public fun injectMocksBeforeTest() { | ||
mocker.reset() | ||
setUpMocks() | ||
initDeferred() | ||
initMocksBeforeTest() | ||
} | ||
|
||
public fun setUpMocks() | ||
|
||
public fun initMocksBeforeTest() {} | ||
|
||
} |
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