Skip to content

Commit

Permalink
Testing enhancements #2 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
vokod committed Sep 29, 2023
1 parent 83aaca7 commit f99c4e8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ package com.bridge.ouroboros.compose
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext

abstract class ExecutableEffect<EVENT, EFFECT_STATE> : CoroutineScope {

private val job = SupervisorJob()

private var currentContext: CoroutineContext? = null

override val coroutineContext: CoroutineContext
get() {
checkNotNull(currentContext) { "coroutineContext must be attached before invoking perform" }
return job + defaultDispatcher
}
get() = currentContext?.let { it + defaultDispatcher }
?: error("coroutineContext must be attached before invoking perform")

abstract fun EFFECT_STATE.perform(emit: EventConsumer<EVENT>)

Expand All @@ -35,7 +31,7 @@ abstract class ExecutableEffect<EVENT, EFFECT_STATE> : CoroutineScope {

companion object {
@Volatile
private var defaultDispatcher: CoroutineDispatcher = Dispatchers.Main
private var defaultDispatcher: CoroutineDispatcher = Dispatchers.Default

fun setDefaultDispatcher(dispatcher: CoroutineDispatcher) {
defaultDispatcher = dispatcher
Expand Down
5 changes: 4 additions & 1 deletion example-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ dependencies {
implementation Libs.material

testImplementation Libs.junit
testImplementation Libs.Kotest.assertions
testImplementation (Libs.Kotest.assertions){
exclude group: 'org.jetbrains.kotlin'
}

testImplementation Libs.MockK.library
testImplementation project(':test')

Expand Down
4 changes: 3 additions & 1 deletion test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ android {

dependencies {
api project(':core')
implementation 'io.kotest:kotest-assertions-core:5.6.0'
implementation (Libs.Kotest.assertions){
exclude group: 'org.jetbrains.kotlin'
}
}

afterEvaluate {
Expand Down

0 comments on commit f99c4e8

Please sign in to comment.