From a1dafd78153721697904122793d8b012715bfd72 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Feb 2026 04:42:35 +0000 Subject: [PATCH 1/3] Initial plan From 0e02a70988df187daaad045345de1775f7057bdc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Feb 2026 04:45:43 +0000 Subject: [PATCH 2/3] Fix PR review issues in test files: mock syntax, @InjectMocks, comments, mutableMapOf Co-authored-by: RobotHanzo <36107150+RobotHanzo@users.noreply.github.com> --- .../werewolf/controller/AuthControllerTest.kt | 9 --------- .../werewolf/controller/SessionControllerTest.kt | 6 +++--- .../werewolf/controller/SpeechControllerTest.kt | 2 -- .../werewolf/security/GlobalWebSocketHandlerTest.kt | 12 ++++++------ 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/test/kotlin/dev/robothanzo/werewolf/controller/AuthControllerTest.kt b/src/test/kotlin/dev/robothanzo/werewolf/controller/AuthControllerTest.kt index d2e905f..34936a1 100644 --- a/src/test/kotlin/dev/robothanzo/werewolf/controller/AuthControllerTest.kt +++ b/src/test/kotlin/dev/robothanzo/werewolf/controller/AuthControllerTest.kt @@ -51,15 +51,6 @@ class AuthControllerTest { val memberMock = mock(Member::class.java) whenever(jda.getGuildById(123L)).thenReturn(guildMock) whenever(guildMock.getMemberById("user1")).thenReturn(memberMock) - // Assume isAdmin logic - isAdmin is an extension function, mocking it might be hard. - // It likely checks permissions. - // If it's an extension function, we cannot easily mock it unless we mock the Member interface completely - // and isAdmin calls member methods. - // dev.robothanzo.werewolf.utils.isAdmin checks member.hasPermission(Administrator) or is owner. - - // However, isAdmin is an extension function. - // Let's assume it returns false for mock unless we configure it. - // But for this test, we just check if it returns OK. val response = authController.selectGuild(guildId, session) diff --git a/src/test/kotlin/dev/robothanzo/werewolf/controller/SessionControllerTest.kt b/src/test/kotlin/dev/robothanzo/werewolf/controller/SessionControllerTest.kt index bf408e8..adb721f 100644 --- a/src/test/kotlin/dev/robothanzo/werewolf/controller/SessionControllerTest.kt +++ b/src/test/kotlin/dev/robothanzo/werewolf/controller/SessionControllerTest.kt @@ -37,7 +37,7 @@ class SessionControllerTest { MockitoAnnotations.openMocks(this) sessionController = SessionController(gameSessionService, identityUtils) - val mockJda = mock() + val mockJda = mock(JDA::class.java) WerewolfApplication.jda = mockJda } @@ -55,10 +55,10 @@ class SessionControllerTest { val user = AuthSession(userId = "user1", guildId = "123", role = UserRole.SPECTATOR) whenever(identityUtils.getCurrentUser()).thenReturn(Optional.of(user)) - val guildMock = mock() + val guildMock = mock(Guild::class.java) whenever(guildMock.name).thenReturn("Test Guild") whenever(guildMock.iconUrl).thenReturn("icon.png") - whenever(guildMock.getMemberById("user1")).thenReturn(mock()) + whenever(guildMock.getMemberById("user1")).thenReturn(mock(Member::class.java)) val session = Session(guildId = 123L) // We need to mock WerewolfApplication.jda.getGuildById(123L) to return guildMock diff --git a/src/test/kotlin/dev/robothanzo/werewolf/controller/SpeechControllerTest.kt b/src/test/kotlin/dev/robothanzo/werewolf/controller/SpeechControllerTest.kt index 928cf0b..c540dad 100644 --- a/src/test/kotlin/dev/robothanzo/werewolf/controller/SpeechControllerTest.kt +++ b/src/test/kotlin/dev/robothanzo/werewolf/controller/SpeechControllerTest.kt @@ -13,7 +13,6 @@ import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import org.mockito.InjectMocks import org.mockito.Mock import org.mockito.Mockito.mock import org.mockito.MockitoAnnotations @@ -27,7 +26,6 @@ import java.util.* class SpeechControllerTest { - @InjectMocks private lateinit var speechController: SpeechController @Mock diff --git a/src/test/kotlin/dev/robothanzo/werewolf/security/GlobalWebSocketHandlerTest.kt b/src/test/kotlin/dev/robothanzo/werewolf/security/GlobalWebSocketHandlerTest.kt index ff69244..9f26ae5 100644 --- a/src/test/kotlin/dev/robothanzo/werewolf/security/GlobalWebSocketHandlerTest.kt +++ b/src/test/kotlin/dev/robothanzo/werewolf/security/GlobalWebSocketHandlerTest.kt @@ -35,7 +35,7 @@ class GlobalWebSocketHandlerTest { @Test fun testConnectionEstablished_Success() { val user = AuthSession(userId = "user1", guildId = "123", role = UserRole.SPECTATOR) - whenever(session.attributes).thenReturn(mapOf("user" to user)) + whenever(session.attributes).thenReturn(mutableMapOf("user" to user)) whenever(session.uri).thenReturn(URI("ws://localhost:8080/ws?guildId=123")) handler.afterConnectionEstablished(session) @@ -45,7 +45,7 @@ class GlobalWebSocketHandlerTest { @Test fun testConnectionEstablished_NoUser() { - whenever(session.attributes).thenReturn(emptyMap()) + whenever(session.attributes).thenReturn(mutableMapOf()) handler.afterConnectionEstablished(session) @@ -55,7 +55,7 @@ class GlobalWebSocketHandlerTest { @Test fun testConnectionEstablished_UnauthorizedRole() { val user = AuthSession(userId = "user1", guildId = "123", role = UserRole.PENDING) - whenever(session.attributes).thenReturn(mapOf("user" to user)) + whenever(session.attributes).thenReturn(mutableMapOf("user" to user)) handler.afterConnectionEstablished(session) @@ -65,7 +65,7 @@ class GlobalWebSocketHandlerTest { @Test fun testConnectionEstablished_GuildMismatch() { val user = AuthSession(userId = "user1", guildId = "123", role = UserRole.SPECTATOR) - whenever(session.attributes).thenReturn(mapOf("user" to user)) + whenever(session.attributes).thenReturn(mutableMapOf("user" to user)) whenever(session.uri).thenReturn(URI("ws://localhost:8080/ws?guildId=456")) handler.afterConnectionEstablished(session) @@ -89,14 +89,14 @@ class GlobalWebSocketHandlerTest { fun testBroadcastToGuild() { val user1 = AuthSession(userId = "user1", guildId = "123", role = UserRole.SPECTATOR) val session1 = mock(WebSocketSession::class.java) - whenever(session1.attributes).thenReturn(mapOf("user" to user1)) + whenever(session1.attributes).thenReturn(mutableMapOf("user" to user1)) whenever(session1.uri).thenReturn(URI("ws://localhost/ws?guildId=123")) whenever(session1.isOpen).thenReturn(true) whenever(session1.id).thenReturn("s1") val user2 = AuthSession(userId = "user2", guildId = "456", role = UserRole.SPECTATOR) val session2 = mock(WebSocketSession::class.java) - whenever(session2.attributes).thenReturn(mapOf("user" to user2)) + whenever(session2.attributes).thenReturn(mutableMapOf("user" to user2)) whenever(session2.uri).thenReturn(URI("ws://localhost/ws?guildId=456")) whenever(session2.isOpen).thenReturn(true) whenever(session2.id).thenReturn("s2") From ce4ddd98d5a5e1efa74d3ccbf0c7945360e984f8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Feb 2026 06:15:52 +0000 Subject: [PATCH 3/3] Resolve merge conflicts: align test files with base branch ce996d8 Co-authored-by: RobotHanzo <36107150+RobotHanzo@users.noreply.github.com> --- .../werewolf/controller/SessionControllerTest.kt | 8 ++++---- .../security/GlobalWebSocketHandlerTest.kt | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/test/kotlin/dev/robothanzo/werewolf/controller/SessionControllerTest.kt b/src/test/kotlin/dev/robothanzo/werewolf/controller/SessionControllerTest.kt index adb721f..cd66fe1 100644 --- a/src/test/kotlin/dev/robothanzo/werewolf/controller/SessionControllerTest.kt +++ b/src/test/kotlin/dev/robothanzo/werewolf/controller/SessionControllerTest.kt @@ -15,9 +15,9 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.Mock -import org.mockito.Mockito.mock import org.mockito.MockitoAnnotations import org.mockito.kotlin.eq +import org.mockito.kotlin.mock import org.mockito.kotlin.whenever import org.springframework.http.HttpStatus import java.util.* @@ -37,7 +37,7 @@ class SessionControllerTest { MockitoAnnotations.openMocks(this) sessionController = SessionController(gameSessionService, identityUtils) - val mockJda = mock(JDA::class.java) + val mockJda = mock() WerewolfApplication.jda = mockJda } @@ -55,10 +55,10 @@ class SessionControllerTest { val user = AuthSession(userId = "user1", guildId = "123", role = UserRole.SPECTATOR) whenever(identityUtils.getCurrentUser()).thenReturn(Optional.of(user)) - val guildMock = mock(Guild::class.java) + val guildMock = mock() whenever(guildMock.name).thenReturn("Test Guild") whenever(guildMock.iconUrl).thenReturn("icon.png") - whenever(guildMock.getMemberById("user1")).thenReturn(mock(Member::class.java)) + whenever(guildMock.getMemberById("user1")).thenReturn(mock()) val session = Session(guildId = 123L) // We need to mock WerewolfApplication.jda.getGuildById(123L) to return guildMock diff --git a/src/test/kotlin/dev/robothanzo/werewolf/security/GlobalWebSocketHandlerTest.kt b/src/test/kotlin/dev/robothanzo/werewolf/security/GlobalWebSocketHandlerTest.kt index 9f26ae5..764dceb 100644 --- a/src/test/kotlin/dev/robothanzo/werewolf/security/GlobalWebSocketHandlerTest.kt +++ b/src/test/kotlin/dev/robothanzo/werewolf/security/GlobalWebSocketHandlerTest.kt @@ -35,7 +35,7 @@ class GlobalWebSocketHandlerTest { @Test fun testConnectionEstablished_Success() { val user = AuthSession(userId = "user1", guildId = "123", role = UserRole.SPECTATOR) - whenever(session.attributes).thenReturn(mutableMapOf("user" to user)) + whenever(session.attributes).thenReturn(mutableMapOf("user" to user) as Map) whenever(session.uri).thenReturn(URI("ws://localhost:8080/ws?guildId=123")) handler.afterConnectionEstablished(session) @@ -45,7 +45,7 @@ class GlobalWebSocketHandlerTest { @Test fun testConnectionEstablished_NoUser() { - whenever(session.attributes).thenReturn(mutableMapOf()) + whenever(session.attributes).thenReturn(mutableMapOf()) handler.afterConnectionEstablished(session) @@ -55,7 +55,7 @@ class GlobalWebSocketHandlerTest { @Test fun testConnectionEstablished_UnauthorizedRole() { val user = AuthSession(userId = "user1", guildId = "123", role = UserRole.PENDING) - whenever(session.attributes).thenReturn(mutableMapOf("user" to user)) + whenever(session.attributes).thenReturn(mutableMapOf("user" to user) as Map) handler.afterConnectionEstablished(session) @@ -65,7 +65,7 @@ class GlobalWebSocketHandlerTest { @Test fun testConnectionEstablished_GuildMismatch() { val user = AuthSession(userId = "user1", guildId = "123", role = UserRole.SPECTATOR) - whenever(session.attributes).thenReturn(mutableMapOf("user" to user)) + whenever(session.attributes).thenReturn(mutableMapOf("user" to user) as Map) whenever(session.uri).thenReturn(URI("ws://localhost:8080/ws?guildId=456")) handler.afterConnectionEstablished(session) @@ -76,7 +76,7 @@ class GlobalWebSocketHandlerTest { @Test fun testHandlePing() { val payload = """{"type": "PING"}""" - doNothing().whenever(session).sendMessage(any()) + whenever(session.sendMessage(any())).then { } handler.handleMessage(session, TextMessage(payload)) @@ -89,14 +89,14 @@ class GlobalWebSocketHandlerTest { fun testBroadcastToGuild() { val user1 = AuthSession(userId = "user1", guildId = "123", role = UserRole.SPECTATOR) val session1 = mock(WebSocketSession::class.java) - whenever(session1.attributes).thenReturn(mutableMapOf("user" to user1)) + whenever(session1.attributes).thenReturn(mutableMapOf("user" to user1) as Map) whenever(session1.uri).thenReturn(URI("ws://localhost/ws?guildId=123")) whenever(session1.isOpen).thenReturn(true) whenever(session1.id).thenReturn("s1") val user2 = AuthSession(userId = "user2", guildId = "456", role = UserRole.SPECTATOR) val session2 = mock(WebSocketSession::class.java) - whenever(session2.attributes).thenReturn(mutableMapOf("user" to user2)) + whenever(session2.attributes).thenReturn(mutableMapOf("user" to user2) as Map) whenever(session2.uri).thenReturn(URI("ws://localhost/ws?guildId=456")) whenever(session2.isOpen).thenReturn(true) whenever(session2.id).thenReturn("s2")