Skip to content

Commit

Permalink
migrate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dsvag committed Nov 26, 2023
1 parent 437757c commit 9aeb51d
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 52 deletions.
4 changes: 1 addition & 3 deletions elmslie-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
plugins {
id("elmslie.kotlin-lib")
`java-test-fixtures`
id("elmslie.tests-convention")
}

dependencies {
implementation(libs.kotlinx.coroutinesCore)
testFixturesImplementation(libs.kotlinx.coroutinesTest)
testFixturesImplementation(libs.junit)
testImplementation(libs.kotlinx.coroutinesTest)
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
package vivid.money.elmslie.core.store

import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
import kotlinx.coroutines.test.setMain
import vivid.money.elmslie.core.config.ElmslieConfig
import vivid.money.elmslie.core.testutil.model.Command
import vivid.money.elmslie.core.testutil.model.Effect
import vivid.money.elmslie.core.testutil.model.Event
import vivid.money.elmslie.core.testutil.model.State
import vivid.money.elmslie.test.TestDispatcherExtension

@OptIn(ExperimentalCoroutinesApi::class)
class EffectCachingElmStoreTest {

@JvmField @RegisterExtension val testDispatcherExtension = TestDispatcherExtension()
@BeforeTest
fun beforeEach() {
val testDispatcher = StandardTestDispatcher()
ElmslieConfig.ioDispatchers { testDispatcher }
Dispatchers.setMain(testDispatcher)
}


@AfterTest
fun afterEach() {
Dispatchers.resetMain()
}

@Test
fun `Should collect effects which are emitted before collecting flow`() = runTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package vivid.money.elmslie.core.store

import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
Expand All @@ -8,22 +13,33 @@ import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
import kotlinx.coroutines.test.setMain
import vivid.money.elmslie.core.config.ElmslieConfig
import vivid.money.elmslie.core.testutil.model.Command
import vivid.money.elmslie.core.testutil.model.Effect
import vivid.money.elmslie.core.testutil.model.Event
import vivid.money.elmslie.core.testutil.model.State
import vivid.money.elmslie.test.TestDispatcherExtension

@OptIn(ExperimentalCoroutinesApi::class)
class ElmStoreTest {

@JvmField @RegisterExtension val testDispatcherExtension = TestDispatcherExtension()
@BeforeTest
fun beforeEach() {
val testDispatcher = StandardTestDispatcher()
ElmslieConfig.ioDispatchers { testDispatcher }
Dispatchers.setMain(testDispatcher)
}


@AfterTest
fun afterEach() {
Dispatchers.resetMain()
}

@Test
fun `Should stop the store properly`() = runTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package vivid.money.elmslie.core.store.dsl

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

private object BasicDslReducer : DslReducer<TestEvent, TestState, TestEffect, TestCommand>() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package vivid.money.elmslie.core.store.dsl

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

object BasicScreenDslReducer :
ScreenDslReducer<
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion samples/kotlin-calculator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ dependencies {
implementation(projects.elmslieCore)
implementation(libs.kotlinx.coroutinesCore)

testImplementation(projects.elmslieCore)
testImplementation(libs.kotlinx.coroutinesTest)
testImplementation(testFixtures(projects.elmslieCore))
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
package vivid.money.elmslie.samples.calculator

import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
import vivid.money.elmslie.test.TestDispatcherExtension
import kotlinx.coroutines.test.setMain
import vivid.money.elmslie.core.config.ElmslieConfig

@OptIn(ExperimentalCoroutinesApi::class)
internal class StoreTest {

@JvmField @RegisterExtension val testDispatcherExtension = TestDispatcherExtension()
@BeforeTest
fun beforeEach() {
val testDispatcher = StandardTestDispatcher()
ElmslieConfig.ioDispatchers { testDispatcher }
Dispatchers.setMain(testDispatcher)
}


@AfterTest
fun afterEach() {
Dispatchers.resetMain()
}

@Test
fun `1 + 1 = 2`() = runTest {
Expand Down

0 comments on commit 9aeb51d

Please sign in to comment.