diff --git a/.idea/artifacts/polpetta_jvm.xml b/.idea/artifacts/polpetta_jvm.xml
deleted file mode 100644
index bbb8e32..0000000
--- a/.idea/artifacts/polpetta_jvm.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
- $PROJECT_DIR$/build/libs
-
-
-
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index b589d56..fcb19bf 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/src/commonTest/kotlin/dev/mcatta/polpetta/ReducerFactoryTest.kt b/src/commonTest/kotlin/dev/mcatta/polpetta/ReducerFactoryTest.kt
index cfa7573..cdc996e 100644
--- a/src/commonTest/kotlin/dev/mcatta/polpetta/ReducerFactoryTest.kt
+++ b/src/commonTest/kotlin/dev/mcatta/polpetta/ReducerFactoryTest.kt
@@ -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
@@ -20,23 +23,23 @@ internal class ReducerFactoryTest {
@Test
fun `Test getting a the Reducer for a defined Action`() = runTest {
// When
- reducerFactory.on { _, stateModifier ->
+ reducerFactory.on { _, 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 { _, stateModifier ->
+ reducerFactory.on { _, stateModifier ->
stateModifier.mutate { copy(counter = 42) }
}
// Then
- assertNull(reducerFactory.getReducer(TestAction.Increase, TestState.Count(0)))
+ assertNull(reducerFactory.getReducer(Increase, Count(0)))
}
}
\ No newline at end of file
diff --git a/src/commonTest/kotlin/dev/mcatta/polpetta/StateStoreTest.kt b/src/commonTest/kotlin/dev/mcatta/polpetta/StateStoreTest.kt
index af7bd4e..bd2dfea 100644
--- a/src/commonTest/kotlin/dev/mcatta/polpetta/StateStoreTest.kt
+++ b/src/commonTest/kotlin/dev/mcatta/polpetta/StateStoreTest.kt
@@ -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
@@ -16,26 +18,26 @@ internal class StateStoreTest {
private class TestStore(scope: CoroutineScope) : StateStore(
coroutineScope = scope,
- initialState = TestState.Count(0),
+ initialState = Count(0),
reducerFactory = {
- on { _, stateModifier ->
+ on { _, stateModifier ->
stateModifier.mutate { copy(counter = counter - 1) }
}
- on { _, stateModifier ->
+ on { _, stateModifier ->
stateModifier.mutate { copy(counter = counter.delayedIncrease()) }
}
- on { action, stateModifier ->
+ on { action, stateModifier ->
stateModifier.mutate { copy(counter = action.n) }
}
- on { _, stateModifier ->
+ on { _, stateModifier ->
stateModifier.nothing()
}
- on { _, stateModifier ->
- stateModifier.transform { TestState.Result(counter.toString()) }
+ on { _, stateModifier ->
+ stateModifier.transform { Result(counter.toString()) }
}
- on { _, stateModifier ->
+ on { _, stateModifier ->
stateModifier.transform {
- TestState.Count(message.toInt() + 1)
+ Count(message.toInt() + 1)
}
}
}
@@ -50,7 +52,7 @@ 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)
}
}
@@ -58,22 +60,22 @@ internal class StateStoreTest {
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)
}
}
@@ -82,9 +84,9 @@ internal class StateStoreTest {
// Given
val testStore = object : StateStore(
coroutineScope = testScope,
- initialState = TestState.Count(0),
+ initialState = Count(0),
reducerFactory = {
- on { _, stateModifier ->
+ on { _, stateModifier ->
stateModifier.nothing()
}
}
@@ -92,10 +94,10 @@ internal class StateStoreTest {
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)
}
}
@@ -104,27 +106,27 @@ internal class StateStoreTest {
// Given
val testStore = object : StateStore(
coroutineScope = testScope,
- initialState = TestState.Count(0),
+ initialState = Count(0),
reducerFactory = {
- on { _, stateModifier ->
+ on { _, stateModifier ->
stateModifier.transform { copy(counter = counter + 1) }
}
- on { _, stateModifier ->
- stateModifier.transform { TestState.Result(this.toString()) }
+ on { _, 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(awaitItem())
- assertIs(awaitItem())
- assertIs(awaitItem())
+ assertIs(awaitItem())
+ assertIs(awaitItem())
+ assertIs(awaitItem())
}
}
@@ -133,9 +135,9 @@ internal class StateStoreTest {
// Given
val testStore = object : StateStore(
coroutineScope = testScope,
- initialState = TestState.Count(0),
+ initialState = Count(0),
reducerFactory = {
- on { _, stateModifier ->
+ on { _, stateModifier ->
sideEffect(TestSideEffect.Toast)
stateModifier.mutate { copy(counter = counter + 1) }
}
@@ -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)
}
}
diff --git a/src/commonTest/kotlin/dev/mcatta/polpetta/core/logger/StoreLoggerTest.kt b/src/commonTest/kotlin/dev/mcatta/polpetta/core/logger/StoreLoggerTest.kt
index 02a9ac2..0b9634f 100644
--- a/src/commonTest/kotlin/dev/mcatta/polpetta/core/logger/StoreLoggerTest.kt
+++ b/src/commonTest/kotlin/dev/mcatta/polpetta/core/logger/StoreLoggerTest.kt
@@ -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
@@ -18,7 +21,7 @@ internal class StoreLoggerTest {
// When
val logMessage = storeLogger.log(
logEvent = LogEvent.DEBUG_EV_DISPATCH,
- action = TestAction.Increase
+ action = Increase
)
// Then
@@ -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
@@ -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
)
diff --git a/src/commonTest/kotlin/dev/mcatta/polpetta/operators/StateModifierTest.kt b/src/commonTest/kotlin/dev/mcatta/polpetta/operators/StateModifierTest.kt
index 2c5e362..0b39b59 100644
--- a/src/commonTest/kotlin/dev/mcatta/polpetta/operators/StateModifierTest.kt
+++ b/src/commonTest/kotlin/dev/mcatta/polpetta/operators/StateModifierTest.kt
@@ -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
@@ -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()
@@ -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) }
@@ -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