From 084e9b95f5bcb35f7d02a84e8da480abdb74862d Mon Sep 17 00:00:00 2001 From: Janis Eccarius Date: Sat, 6 Jun 2026 20:24:44 +0200 Subject: [PATCH] fix(test): mock IoGrpcClientWrapper in GameCreationServiceTest, disable stream listener in core tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GameCreationServiceTest called createGame which routes through RedisGameRegistry.store → IoGrpcClientWrapper.exportCombined, hitting a real gRPC stub that fails with UNIMPLEMENTED in tests. MockRedisDataSourceProducer's RETURNS_DEEP_STUBS mock caused a classloader mismatch when GameCreationStreamListener called .stream() on it (PubSubCommands mock returned instead of StreamCommands). - Add @InjectMock IoGrpcClientWrapper + @BeforeEach stub in GameCreationServiceTest - Add nowchess.game-creation-stream.enabled: false to core test application.yml Co-Authored-By: Claude Sonnet 4.6 --- modules/core/src/test/resources/application.yml | 2 ++ .../chess/service/GameCreationServiceTest.scala | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/core/src/test/resources/application.yml b/modules/core/src/test/resources/application.yml index af2dd01..e182fce 100644 --- a/modules/core/src/test/resources/application.yml +++ b/modules/core/src/test/resources/application.yml @@ -18,6 +18,8 @@ nowchess: enabled: false coordinator: enabled: false + game-creation-stream: + enabled: false redis: host: localhost port: 6379 diff --git a/modules/core/src/test/scala/de/nowchess/chess/service/GameCreationServiceTest.scala b/modules/core/src/test/scala/de/nowchess/chess/service/GameCreationServiceTest.scala index e1b0778..2fbd6e2 100644 --- a/modules/core/src/test/scala/de/nowchess/chess/service/GameCreationServiceTest.scala +++ b/modules/core/src/test/scala/de/nowchess/chess/service/GameCreationServiceTest.scala @@ -3,13 +3,16 @@ package de.nowchess.chess.service import de.nowchess.api.dto.{GameCreationRequestDto, PlayerInfoDto, TimeControlDto} import de.nowchess.api.game.{GameMode, TimeControl} import de.nowchess.api.player.PlayerType +import de.nowchess.chess.client.CombinedExportResponse +import de.nowchess.chess.grpc.IoGrpcClientWrapper import de.nowchess.chess.redis.GameRedisSubscriberManager import io.quarkus.test.InjectMock import io.quarkus.test.junit.QuarkusTest import jakarta.inject.Inject import org.junit.jupiter.api.Assertions.* -import org.junit.jupiter.api.{DisplayName, Test} -import org.mockito.Mockito.verify +import org.junit.jupiter.api.{BeforeEach, DisplayName, Test} +import org.mockito.ArgumentMatchers.any +import org.mockito.Mockito.{verify, when} import scala.compiletime.uninitialized // scalafix:off @@ -23,6 +26,14 @@ class GameCreationServiceTest: @InjectMock var subscriberManager: GameRedisSubscriberManager = uninitialized + @InjectMock + var ioWrapper: IoGrpcClientWrapper = uninitialized + + @BeforeEach + def setup(): Unit = + when(ioWrapper.exportCombined(any())) + .thenReturn(CombinedExportResponse("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", "")) + private def player(id: String, name: String): PlayerInfoDto = PlayerInfoDto(id, name, PlayerType.Human)