Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing enhancements #2 #4

Merged
merged 12 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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