From 13f6da67a7c3ffb6c3eb8fc4d28f71296293f83e Mon Sep 17 00:00:00 2001 From: Florian Schuster Date: Sat, 23 May 2020 10:17:40 +0200 Subject: [PATCH] Add TestOnly annotation to stub extension function --- .../src/main/kotlin/at/florianschuster/control/stub.kt | 2 ++ .../src/test/kotlin/at/florianschuster/control/StubTest.kt | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/control-core/src/main/kotlin/at/florianschuster/control/stub.kt b/control-core/src/main/kotlin/at/florianschuster/control/stub.kt index 41eabb20..a1ba5074 100644 --- a/control-core/src/main/kotlin/at/florianschuster/control/stub.kt +++ b/control-core/src/main/kotlin/at/florianschuster/control/stub.kt @@ -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. @@ -12,6 +13,7 @@ import kotlinx.coroutines.flow.MutableStateFlow */ @ExperimentalCoroutinesApi @FlowPreview +@TestOnly fun Controller.stub(): ControllerStub { require(this is ControllerImplementation) { "Cannot stub a custom implementation of a Controller." diff --git a/control-core/src/test/kotlin/at/florianschuster/control/StubTest.kt b/control-core/src/test/kotlin/at/florianschuster/control/StubTest.kt index eb7eafd2..51c18377 100644 --- a/control-core/src/test/kotlin/at/florianschuster/control/StubTest.kt +++ b/control-core/src/test/kotlin/at/florianschuster/control/StubTest.kt @@ -32,8 +32,8 @@ internal class StubTest { @Test fun `stub is initialized only after accessing stub()`() { - val sut = - testCoroutineScope.createStringController() as ControllerImplementation, List, List> + val sut = testCoroutineScope.createStringController() + as ControllerImplementation, List, List> assertFalse(sut.stubInitialized) assertFailsWith { sut.stub.dispatchedActions }