From ae7c4ca25efe952f02de2a244634dce6ea925232 Mon Sep 17 00:00:00 2001 From: Yigit Ozgumus Date: Wed, 3 Jul 2024 16:59:48 +0300 Subject: [PATCH] Add extension functions for streams, add list of Transmissions to be processed before the Test transmission --- transmission-test/build.gradle.kts | 2 +- .../transmissiontesting/StreamExt.kt | 11 +++++++++++ .../transmissiontesting/TestWithExt.kt | 18 ++++++++++++++++++ transmission/build.gradle.kts | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 transmission-test/src/main/java/com/yigitozgumus/transmissiontesting/StreamExt.kt diff --git a/transmission-test/build.gradle.kts b/transmission-test/build.gradle.kts index 247f0c2..1d06eed 100644 --- a/transmission-test/build.gradle.kts +++ b/transmission-test/build.gradle.kts @@ -28,7 +28,7 @@ publishing { create("release") { groupId = "com.trendyol" artifactId = "transmission-test" - version = "1.0.0" + version = "1.0.4" afterEvaluate { from(components["java"]) } diff --git a/transmission-test/src/main/java/com/yigitozgumus/transmissiontesting/StreamExt.kt b/transmission-test/src/main/java/com/yigitozgumus/transmissiontesting/StreamExt.kt new file mode 100644 index 0000000..9343349 --- /dev/null +++ b/transmission-test/src/main/java/com/yigitozgumus/transmissiontesting/StreamExt.kt @@ -0,0 +1,11 @@ +package com.yigitozgumus.transmissiontesting + +import com.trendyol.transmission.Transmission + +inline fun List.lastInstanceOf(): T? { + return this.filterIsInstance().last() +} + +inline fun List.lastInstanceOf(): T? { + return this.filterIsInstance().last() +} diff --git a/transmission-test/src/main/java/com/yigitozgumus/transmissiontesting/TestWithExt.kt b/transmission-test/src/main/java/com/yigitozgumus/transmissiontesting/TestWithExt.kt index a431f41..cf723eb 100644 --- a/transmission-test/src/main/java/com/yigitozgumus/transmissiontesting/TestWithExt.kt +++ b/transmission-test/src/main/java/com/yigitozgumus/transmissiontesting/TestWithExt.kt @@ -13,6 +13,7 @@ import kotlinx.coroutines.test.runTest @OptIn(ExperimentalCoroutinesApi::class) fun Transformer.testWithEffect( + orderedInitialProcessing: List = emptyList(), effect: Transmission.Effect, registry: RegistryScope.() -> Unit = {}, scope: suspend TransformerTestScope.(scope: TestScope) -> Unit @@ -33,6 +34,14 @@ fun Transformer.testWithEffect( override val dataStream: List = dataStream override val effectStream: List = effectStream } + orderedInitialProcessing.forEach { + when (it) { + is Transmission.Data -> throw IllegalArgumentException("Transmission.Data should not be sent for processing") + is Transmission.Effect -> testRouter.sendEffect(it) + is Transmission.Signal -> testRouter.sendSignal(it) + } + this@testWithEffect.waitProcessingToFinish() + } testRouter.sendEffect(effect) this@testWithEffect.waitProcessingToFinish() testScope.scope(this) @@ -45,6 +54,7 @@ fun Transformer.testWithEffect( @OptIn(ExperimentalCoroutinesApi::class) fun Transformer.testWithSignal( + orderedInitialProcessing: List = emptyList(), signal: Transmission.Signal, registry: RegistryScope.() -> Unit = {}, scope: suspend TransformerTestScope.(scope: TestScope) -> Unit @@ -65,6 +75,14 @@ fun Transformer.testWithSignal( override val dataStream: List = dataStream override val effectStream: List = effectStream } + orderedInitialProcessing.forEach { + when (it) { + is Transmission.Data -> throw IllegalArgumentException("Transmission.Data should not be sent for processing") + is Transmission.Effect -> testRouter.sendEffect(it) + is Transmission.Signal -> testRouter.sendSignal(it) + } + this@testWithSignal.waitProcessingToFinish() + } testRouter.sendSignal(signal) this@testWithSignal.waitProcessingToFinish() testScope.scope(this) diff --git a/transmission/build.gradle.kts b/transmission/build.gradle.kts index e36773a..4661ee7 100644 --- a/transmission/build.gradle.kts +++ b/transmission/build.gradle.kts @@ -27,7 +27,7 @@ publishing { create("release") { groupId = "com.trendyol" artifactId = "transmission" - version = "1.0.0" + version = "1.0.4" afterEvaluate { from(components["java"]) }