diff --git a/src/main/kotlin/eventDemo/adapter/interfaceLayer/query/GameCommandRouteWebSocket.kt b/src/main/kotlin/eventDemo/adapter/interfaceLayer/query/GameCommandRouteWebSocket.kt index a4aff7d..f90cdd2 100644 --- a/src/main/kotlin/eventDemo/adapter/interfaceLayer/query/GameCommandRouteWebSocket.kt +++ b/src/main/kotlin/eventDemo/adapter/interfaceLayer/query/GameCommandRouteWebSocket.kt @@ -59,10 +59,9 @@ private fun DefaultWebSocketServerSession.runWebSocket( } playerNotificationListener.startListening( - { outgoingFrameChannel.trySendBlocking(it) }, currentPlayer, gameId, - ) + ) { outgoingFrameChannel.trySendBlocking(it) } } } diff --git a/src/main/kotlin/eventDemo/business/event/projection/projectionListener/PlayerNotificationListener.kt b/src/main/kotlin/eventDemo/business/event/projection/projectionListener/PlayerNotificationListener.kt index b4e4725..0beb6e2 100644 --- a/src/main/kotlin/eventDemo/business/event/projection/projectionListener/PlayerNotificationListener.kt +++ b/src/main/kotlin/eventDemo/business/event/projection/projectionListener/PlayerNotificationListener.kt @@ -32,9 +32,9 @@ class PlayerNotificationListener( private val logger = KotlinLogging.logger {} fun startListening( - outgoingNotification: (Notification) -> Unit, currentPlayer: Player, gameId: GameId, + outgoingNotification: (Notification) -> Unit, ) { projectionBus.subscribe { currentState -> if (currentState !is GameState) return@subscribe diff --git a/src/test/kotlin/eventDemo/adapter/interfaceLayer/query/GameSimulationTest.kt b/src/test/kotlin/eventDemo/adapter/interfaceLayer/query/GameSimulationTest.kt index 42f90a0..c7b1a56 100644 --- a/src/test/kotlin/eventDemo/adapter/interfaceLayer/query/GameSimulationTest.kt +++ b/src/test/kotlin/eventDemo/adapter/interfaceLayer/query/GameSimulationTest.kt @@ -175,8 +175,8 @@ class GameSimulationTest : val eventStore by inject() val playerNotificationListener by inject() ReactionListener(get(), get()).init() - playerNotificationListener.startListening({ channelNotification1.trySendBlocking(it) }, player1, gameId) - playerNotificationListener.startListening({ channelNotification2.trySendBlocking(it) }, player2, gameId) + playerNotificationListener.startListening(player1, gameId) { channelNotification1.trySendBlocking(it) } + playerNotificationListener.startListening(player2, gameId) { channelNotification2.trySendBlocking(it) } GlobalScope.launch(Dispatchers.IO) { commandHandler.handle(player1, gameId, channelCommand1, channelNotification1) diff --git a/src/test/kotlin/eventDemo/business/command/GameCommandHandlerTest.kt b/src/test/kotlin/eventDemo/business/command/GameCommandHandlerTest.kt index 0810acb..714ca27 100644 --- a/src/test/kotlin/eventDemo/business/command/GameCommandHandlerTest.kt +++ b/src/test/kotlin/eventDemo/business/command/GameCommandHandlerTest.kt @@ -34,10 +34,9 @@ class GameCommandHandlerTest : val channelNotification = Channel(Channel.BUFFERED) ReactionListener(get(), get()).init() notificationListener.startListening( - { channelNotification.trySendBlocking(it) }, player, gameId, - ) + ) { channelNotification.trySendBlocking(it) } GlobalScope.launch { commandHandler.handle( diff --git a/src/test/kotlin/eventDemo/business/event/projection/projectionListener/PlayerNotificationListenerTest.kt b/src/test/kotlin/eventDemo/business/event/projection/projectionListener/PlayerNotificationListenerTest.kt new file mode 100644 index 0000000..d6e6c19 --- /dev/null +++ b/src/test/kotlin/eventDemo/business/event/projection/projectionListener/PlayerNotificationListenerTest.kt @@ -0,0 +1,36 @@ +package eventDemo.business.event.projection.projectionListener + +import eventDemo.adapter.infrastructureLayer.event.projection.GameProjectionBusInMemory +import eventDemo.business.entity.GameId +import eventDemo.business.entity.Player +import eventDemo.business.event.event.NewPlayerEvent +import eventDemo.business.event.projection.gameState.GameState +import eventDemo.business.notification.WelcomeToTheGameNotification +import io.kotest.core.spec.style.FunSpec +import io.mockk.mockk +import io.mockk.verify +import kotlin.test.assertIs + +class PlayerNotificationListenerTest : + FunSpec({ + + test("startListening should react when a projection is sent to the bus") { + val player = Player("Tesla") + val gameId = GameId() + val bus = GameProjectionBusInMemory() + val state = + GameState( + aggregateId = gameId, + lastEvent = NewPlayerEvent(gameId, player, 1), + players = setOf(player), + ) + val spyCall: () -> Unit = mockk(relaxed = true) + PlayerNotificationListener(bus).startListening(player, gameId) { + assertIs(it) + spyCall() + } + bus.publish(state) + + verify(exactly = 1) { spyCall() } + } + })