Skip to content

Commit

Permalink
lint: test imports
Browse files Browse the repository at this point in the history
  • Loading branch information
mcatta committed May 21, 2024
1 parent d332700 commit bf7a452
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 64 deletions.
6 changes: 0 additions & 6 deletions .idea/artifacts/polpetta_jvm.xml

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions src/commonTest/kotlin/dev/mcatta/polpetta/ReducerFactoryTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package dev.mcatta.polpetta

import dev.mcatta.polpetta.TestAction.Decrease
import dev.mcatta.polpetta.TestAction.Increase
import dev.mcatta.polpetta.TestState.Count
import kotlinx.coroutines.test.runTest
import kotlin.test.BeforeTest
import kotlin.test.Test
Expand All @@ -20,23 +23,23 @@ internal class ReducerFactoryTest {
@Test
fun `Test getting a the Reducer for a defined Action`() = runTest {
// When
reducerFactory.on<TestAction.Decrease, TestState.Count> { _, stateModifier ->
reducerFactory.on<Decrease, Count> { _, stateModifier ->
stateModifier.mutate { copy(counter = 42) }
}

// Then
assertNotNull(reducerFactory.getReducer(TestAction.Decrease, TestState.Count(0)))
assertNotNull(reducerFactory.getReducer(Decrease, Count(0)))
}

@Test
fun `Test getting a the Reducer for a undefined Action`() = runTest {
// When
reducerFactory.on<TestAction.Decrease, TestState.Count> { _, stateModifier ->
reducerFactory.on<Decrease, Count> { _, stateModifier ->
stateModifier.mutate { copy(counter = 42) }
}

// Then
assertNull(reducerFactory.getReducer(TestAction.Increase, TestState.Count(0)))
assertNull(reducerFactory.getReducer(Increase, Count(0)))
}

}
86 changes: 44 additions & 42 deletions src/commonTest/kotlin/dev/mcatta/polpetta/StateStoreTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.mcatta.polpetta

import app.cash.turbine.test
import dev.mcatta.polpetta.TestAction.*
import dev.mcatta.polpetta.TestState.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
Expand All @@ -16,26 +18,26 @@ internal class StateStoreTest {

private class TestStore(scope: CoroutineScope) : StateStore<TestAction, TestState, Nothing>(
coroutineScope = scope,
initialState = TestState.Count(0),
initialState = Count(0),
reducerFactory = {
on<TestAction.Decrease, TestState.Count> { _, stateModifier ->
on<Decrease, Count> { _, stateModifier ->
stateModifier.mutate { copy(counter = counter - 1) }
}
on<TestAction.Increase, TestState.Count> { _, stateModifier ->
on<Increase, Count> { _, stateModifier ->
stateModifier.mutate { copy(counter = counter.delayedIncrease()) }
}
on<TestAction.Set, TestState.Count> { action, stateModifier ->
on<Set, Count> { action, stateModifier ->
stateModifier.mutate { copy(counter = action.n) }
}
on<TestAction.DoNothing, TestState.Count> { _, stateModifier ->
on<DoNothing, Count> { _, stateModifier ->
stateModifier.nothing()
}
on<TestAction.ToString, TestState.Count> { _, stateModifier ->
stateModifier.transform { TestState.Result(counter.toString()) }
on<ToString, Count> { _, stateModifier ->
stateModifier.transform { Result(counter.toString()) }
}
on<TestAction.Increase, TestState.Result> { _, stateModifier ->
on<Increase, Result> { _, stateModifier ->
stateModifier.transform {
TestState.Count(message.toInt() + 1)
Count(message.toInt() + 1)
}
}
}
Expand All @@ -50,30 +52,30 @@ internal class StateStoreTest {
fun `Test initial state`() = runTest(context = testScope.coroutineContext) {
testStore.stateFlow.test {
// Then
assertEquals(0, (awaitItem() as TestState.Count).counter)
assertEquals(0, (awaitItem() as Count).counter)
}
}

@Test
fun `Test Intents execution`() = runTest(context = testScope.coroutineContext) {
testStore.stateFlow.test {
// When
testStore.dispatchAction(TestAction.Increase)
testStore.dispatchAction(TestAction.Increase)
testStore.dispatchAction(TestAction.DoNothing)
testStore.dispatchAction(TestAction.Decrease)
testStore.dispatchAction(TestAction.Set(42))
testStore.dispatchAction(TestAction.ToString)
testStore.dispatchAction(TestAction.Increase)
testStore.dispatchAction(Increase)
testStore.dispatchAction(Increase)
testStore.dispatchAction(DoNothing)
testStore.dispatchAction(Decrease)
testStore.dispatchAction(Set(42))
testStore.dispatchAction(ToString)
testStore.dispatchAction(Increase)

// Then
assertEquals(0, (awaitItem() as TestState.Count).counter)
assertEquals(1, (awaitItem() as TestState.Count).counter)
assertEquals(2, (awaitItem() as TestState.Count).counter)
assertEquals(1, (awaitItem() as TestState.Count).counter)
assertEquals(42, (awaitItem() as TestState.Count).counter)
assertEquals("42", (awaitItem() as TestState.Result).message)
assertEquals(43, (awaitItem() as TestState.Count).counter)
assertEquals(0, (awaitItem() as Count).counter)
assertEquals(1, (awaitItem() as Count).counter)
assertEquals(2, (awaitItem() as Count).counter)
assertEquals(1, (awaitItem() as Count).counter)
assertEquals(42, (awaitItem() as Count).counter)
assertEquals("42", (awaitItem() as Result).message)
assertEquals(43, (awaitItem() as Count).counter)
}
}

Expand All @@ -82,20 +84,20 @@ internal class StateStoreTest {
// Given
val testStore = object : StateStore<TestAction, TestState, TestSideEffect>(
coroutineScope = testScope,
initialState = TestState.Count(0),
initialState = Count(0),
reducerFactory = {
on<TestAction.DoNothing, TestState.Count> { _, stateModifier ->
on<DoNothing, Count> { _, stateModifier ->
stateModifier.nothing()
}
}
) {}

testStore.stateFlow.test {
// When
testStore.dispatchAction(TestAction.Increase)
testStore.dispatchAction(Increase)

// Then
assertEquals(0, (awaitItem() as TestState.Count).counter)
assertEquals(0, (awaitItem() as Count).counter)
}
}

Expand All @@ -104,27 +106,27 @@ internal class StateStoreTest {
// Given
val testStore = object : StateStore<TestAction, TestState, Nothing>(
coroutineScope = testScope,
initialState = TestState.Count(0),
initialState = Count(0),
reducerFactory = {
on<TestAction.Increase, TestState.Count> { _, stateModifier ->
on<Increase, Count> { _, stateModifier ->
stateModifier.transform { copy(counter = counter + 1) }
}

on<TestAction.ToString, TestState> { _, stateModifier ->
stateModifier.transform { TestState.Result(this.toString()) }
on<ToString, TestState> { _, stateModifier ->
stateModifier.transform { Result(this.toString()) }
}
}
) {}

testStore.stateFlow.test {
// When
testStore.dispatchAction(TestAction.Increase)
testStore.dispatchAction(TestAction.ToString)
testStore.dispatchAction(Increase)
testStore.dispatchAction(ToString)

// Then
assertIs<TestState.Count>(awaitItem())
assertIs<TestState.Count>(awaitItem())
assertIs<TestState.Result>(awaitItem())
assertIs<Count>(awaitItem())
assertIs<Count>(awaitItem())
assertIs<Result>(awaitItem())
}
}

Expand All @@ -133,9 +135,9 @@ internal class StateStoreTest {
// Given
val testStore = object : StateStore<TestAction, TestState, TestSideEffect>(
coroutineScope = testScope,
initialState = TestState.Count(0),
initialState = Count(0),
reducerFactory = {
on<TestAction.Increase, TestState.Count> { _, stateModifier ->
on<Increase, Count> { _, stateModifier ->
sideEffect(TestSideEffect.Toast)
stateModifier.mutate { copy(counter = counter + 1) }
}
Expand All @@ -145,11 +147,11 @@ internal class StateStoreTest {
testStore.stateFlow.test {
// When
assertNull(testStore.sideEffectFlow.value)
testStore.dispatchAction(TestAction.Increase)
testStore.dispatchAction(Increase)

// Then
assertEquals(0, (awaitItem() as TestState.Count).counter)
assertEquals(1, (awaitItem() as TestState.Count).counter)
assertEquals(0, (awaitItem() as Count).counter)
assertEquals(1, (awaitItem() as Count).counter)
assertNotNull(testStore.sideEffectFlow.value)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package dev.mcatta.polpetta.core.logger

import dev.mcatta.polpetta.TestAction
import dev.mcatta.polpetta.TestAction.Increase
import dev.mcatta.polpetta.TestState
import dev.mcatta.polpetta.TestState.Count
import dev.mcatta.polpetta.TestState.Result
import kotlin.test.Test
import kotlin.test.assertEquals

Expand All @@ -18,7 +21,7 @@ internal class StoreLoggerTest {
// When
val logMessage = storeLogger.log(
logEvent = LogEvent.DEBUG_EV_DISPATCH,
action = TestAction.Increase
action = Increase
)

// Then
Expand All @@ -30,9 +33,9 @@ internal class StoreLoggerTest {
// When
val logMessage = storeLogger.log(
logEvent = LogEvent.DEBUG_EV_PROCESSED,
action = TestAction.Increase,
fromStateKlass = TestState.Count::class,
toStateKlass = TestState.Result::class
action = Increase,
fromStateKlass = Count::class,
toStateKlass = Result::class
)

// Then
Expand All @@ -44,8 +47,8 @@ internal class StoreLoggerTest {
// When
val logMessage = storeLogger.log(
logEvent = LogEvent.DEBUG_EV_IGNORED,
action = TestAction.Increase,
fromStateKlass = TestState.Count::class,
action = Increase,
fromStateKlass = Count::class,
toStateKlass = null
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.mcatta.polpetta.operators

import dev.mcatta.polpetta.TestState
import dev.mcatta.polpetta.TestState.*
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -12,7 +12,7 @@ internal class StateModifierTest {
@Test
fun `Test nothing operator`() {
// Given
val state = TestState.Count(42)
val state = Count(42)

// When
val newState = StateModifier.of(state).nothing()
Expand All @@ -24,7 +24,7 @@ internal class StateModifierTest {
@Test
fun `Test mutate operator`() = runTest {
// Given
val state = TestState.Count(42)
val state = Count(42)

// When
val newState = StateModifier.of(state).mutate { copy(counter = 24) }
Expand All @@ -37,11 +37,11 @@ internal class StateModifierTest {
@Test
fun `Test transform operator`() = runTest {
// Given
val state = TestState.Count(42)
val state = Count(42)

// When
val newState = StateModifier.of(state).transform {
TestState.Result(message = counter.toString())
Result(message = counter.toString())
}

// Then
Expand Down

0 comments on commit bf7a452

Please sign in to comment.