From 77a842817045c76cfe96e3c1cea41446741f2636 Mon Sep 17 00:00:00 2001 From: Jay Ohms Date: Tue, 22 Aug 2023 10:15:15 -0400 Subject: [PATCH] Open up the component's didReceive(), didStart(), and didStop() for use with app component testing --- .../dev/hotwire/strada/BridgeComponent.kt | 45 +++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/strada/src/main/kotlin/dev/hotwire/strada/BridgeComponent.kt b/strada/src/main/kotlin/dev/hotwire/strada/BridgeComponent.kt index 6afc01e..ece92ee 100644 --- a/strada/src/main/kotlin/dev/hotwire/strada/BridgeComponent.kt +++ b/strada/src/main/kotlin/dev/hotwire/strada/BridgeComponent.kt @@ -6,19 +6,6 @@ abstract class BridgeComponent( ) { private val receivedMessages = hashMapOf() - internal fun didReceive(message: Message) { - receivedMessages[message.event] = message - onReceive(message) - } - - internal fun didStart() { - onStart() - } - - internal fun didStop() { - onStop() - } - /** * Returns the last received message for a given `event`, if available. */ @@ -32,6 +19,38 @@ abstract class BridgeComponent( */ abstract fun onReceive(message: Message) + /** + * This passes a received message to onReceive(message), caching it + * for use with replyTo(event) and receivedMessageFor(event). + * + * NOTE: This should not be called directly from within a component, + * but is available to use for testing. + */ + fun didReceive(message: Message) { + receivedMessages[message.event] = message + onReceive(message) + } + + /** + * This passes the start lifecycle event to onStart(). + * + * NOTE: This should not be called directly from within a component, + * but is available to use for testing. + */ + fun didStart() { + onStart() + } + + /** + * This passes the stop lifecycle event to onStop(). + * + * NOTE: This should not be called directly from within a component, + * but is available to use for testing. + */ + fun didStop() { + onStop() + } + /** * Called when the component's destination starts (and is active) * based on its lifecycle events. You can use this as an opportunity