Skip to content

Commit

Permalink
Add TestOnly annotation to stub extension function
Browse files Browse the repository at this point in the history
  • Loading branch information
floschu committed May 23, 2020
1 parent 6d22578 commit 13f6da6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package at.florianschuster.control
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.MutableStateFlow
import org.jetbrains.annotations.TestOnly

/**
* Retrieves a [ControllerStub] for this [Controller] used for view testing.
Expand All @@ -12,6 +13,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
*/
@ExperimentalCoroutinesApi
@FlowPreview
@TestOnly
fun <Action, State> Controller<Action, *, State>.stub(): ControllerStub<Action, State> {
require(this is ControllerImplementation<Action, *, State>) {
"Cannot stub a custom implementation of a Controller."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ internal class StubTest {

@Test
fun `stub is initialized only after accessing stub()`() {
val sut =
testCoroutineScope.createStringController() as ControllerImplementation<List<String>, List<String>, List<String>>
val sut = testCoroutineScope.createStringController()
as ControllerImplementation<List<String>, List<String>, List<String>>
assertFalse(sut.stubInitialized)

assertFailsWith<UninitializedPropertyAccessException> { sut.stub.dispatchedActions }
Expand Down

0 comments on commit 13f6da6

Please sign in to comment.