From 1750906b6a3eafd1b87d2896104df699f762ecd8 Mon Sep 17 00:00:00 2001 From: Horvath Tamas Date: Wed, 27 Jan 2021 10:01:29 +0100 Subject: [PATCH 1/3] fix: error message on test store --- .../main/kotlin/composablearchitecture/test/TestStore.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composable-architecture-test/src/main/kotlin/composablearchitecture/test/TestStore.kt b/composable-architecture-test/src/main/kotlin/composablearchitecture/test/TestStore.kt index ec7aeda..3abc06f 100644 --- a/composable-architecture-test/src/main/kotlin/composablearchitecture/test/TestStore.kt +++ b/composable-architecture-test/src/main/kotlin/composablearchitecture/test/TestStore.kt @@ -112,19 +112,19 @@ private constructor( when (step) { is Step.Send -> { - require(receivedActions.isEmpty()) { "Must handle all actions" } + require(receivedActions.isEmpty()) { "Must handle all actions. Unhandled actions:\n" + receivedActions.joinToString(separator = "\n") } runReducer(fromLocalAction.reverseGet(step.action)) expectedState = step.block(expectedState) } is Step.Receive -> { - require(receivedActions.isNotEmpty()) { "Expected to receive an action, but received none" } + require(receivedActions.isNotEmpty()) { "Expected to receive" + receivedActions.joinToString(separator = "\n") + "but received none" } val receivedAction = receivedActions.removeFirst() require(step.action == receivedAction) { "Actual and expected actions do not match" } runReducer(fromLocalAction.reverseGet(step.action)) expectedState = step.block(expectedState) } is Step.Environment -> { - require(receivedActions.isEmpty()) { "Must handle all received actions before performing this work" } + require(receivedActions.isEmpty()) { "Must handle all received actions before performing this work." + receivedActions.joinToString(separator = "\n") + "are not handled" } step.block(environment) } is Step.Do -> step.block() @@ -139,6 +139,6 @@ private constructor( } } - require(receivedActions.isEmpty()) { "Must handle all actions" } + require(receivedActions.isEmpty()) { "Must handle all actions. Unhandled actions:\n" + receivedActions.joinToString(separator = "\n") } } } From 70e6c0693f51a7df15f05706d348cee831880d94 Mon Sep 17 00:00:00 2001 From: Horvath Tamas Date: Wed, 27 Jan 2021 10:04:11 +0100 Subject: [PATCH 2/3] add: experimental api notation --- .../src/main/kotlin/composablearchitecture/test/TestStore.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/composable-architecture-test/src/main/kotlin/composablearchitecture/test/TestStore.kt b/composable-architecture-test/src/main/kotlin/composablearchitecture/test/TestStore.kt index 3abc06f..9cd39f4 100644 --- a/composable-architecture-test/src/main/kotlin/composablearchitecture/test/TestStore.kt +++ b/composable-architecture-test/src/main/kotlin/composablearchitecture/test/TestStore.kt @@ -84,7 +84,9 @@ private constructor( fromLocalAction, testDispatcher ) - + + @kotlin.ExperimentalStdlibApi + @OptIn(kotlin.ExperimentalStdlibApi::class) fun assert(block: AssertionBuilder.() -> Unit) { val assertion = AssertionBuilder { toLocalState.get(state) From f669160e5895624ac56d8d7f6032b451aec38ef5 Mon Sep 17 00:00:00 2001 From: Horvath Tamas Date: Tue, 2 Feb 2021 13:52:51 +0100 Subject: [PATCH 3/3] fix: error descriptions --- .../composablearchitecture/test/TestStore.kt | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/composable-architecture-test/src/main/kotlin/composablearchitecture/test/TestStore.kt b/composable-architecture-test/src/main/kotlin/composablearchitecture/test/TestStore.kt index 9cd39f4..6feed8a 100644 --- a/composable-architecture-test/src/main/kotlin/composablearchitecture/test/TestStore.kt +++ b/composable-architecture-test/src/main/kotlin/composablearchitecture/test/TestStore.kt @@ -70,6 +70,20 @@ private constructor( Prism.id(), testDispatcher ) + fun , Environment> create ( + state: State, + reducer: Reducer, + environment: Environment, + testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher() + ) = + TestStore( + state, + reducer, + environment, + Lens.id(), + Prism.id(), + testDispatcher + ) } fun scope( @@ -119,14 +133,20 @@ private constructor( expectedState = step.block(expectedState) } is Step.Receive -> { - require(receivedActions.isNotEmpty()) { "Expected to receive" + receivedActions.joinToString(separator = "\n") + "but received none" } + require(receivedActions.isNotEmpty()) { + "Expected to receive" + receivedActions.joinToString(separator = "\n") + "but received none" + } val receivedAction = receivedActions.removeFirst() - require(step.action == receivedAction) { "Actual and expected actions do not match" } + require(step.action == receivedAction) { + "Actual and expected states do not match.\n\n${step.action}\n---vs---\n$receivedAction" + } runReducer(fromLocalAction.reverseGet(step.action)) expectedState = step.block(expectedState) } is Step.Environment -> { - require(receivedActions.isEmpty()) { "Must handle all received actions before performing this work." + receivedActions.joinToString(separator = "\n") + "are not handled" } + require(receivedActions.isEmpty()) { + "Must handle all received actions before performing this work." + receivedActions.joinToString(separator = "\n") + "are not handled" + } step.block(environment) } is Step.Do -> step.block() @@ -134,13 +154,11 @@ private constructor( val actualState = toLocalState.get(state) require(actualState == expectedState) { - println(actualState) - println("---vs---") - println(expectedState) - "Actual and expected states do not match" + "Actual and expected states do not match\n\n$actualState\n---vs---\n$expectedState" } } require(receivedActions.isEmpty()) { "Must handle all actions. Unhandled actions:\n" + receivedActions.joinToString(separator = "\n") } } } +