Skip to content

Commit

Permalink
Merge pull request #247 from vivid-money/migrate-tests
Browse files Browse the repository at this point in the history
Migrate tests
  • Loading branch information
dsvag authored Nov 27, 2023
2 parents 41e4f8c + 9aeb51d commit f480e45
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ val catalog = extensions.getByType<VersionCatalogsExtension>().named("libs")

dependencies {
val testImplementation by configurations
catalog.findLibrary("junit").ifPresent { testImplementation(it) }
catalog.findLibrary("kotlin-test").ifPresent { testImplementation(it) }
}
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.

3 changes: 1 addition & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
agp = "8.0.2"
coroutines = "1.7.1"
dokka = "1.8.20"
junit = "5.9.3"
kotlin = "1.8.21"
lifecycle = "2.6.1"

Expand All @@ -19,8 +18,8 @@ detekt-gradlePlugin = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.0"
dokka-gradlePlugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
dokka-kotlinAsJavaPlugin = { module = "org.jetbrains.dokka:kotlin-as-java-plugin", version.ref = "dokka" }
google-material = "com.google.android.material:material:1.9.0"
junit = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlinx-coroutinesCore = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
kotlinx-coroutinesTest = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }

Expand Down
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 f480e45

Please sign in to comment.