From 59765e33bb242a96830ba600d990e2ae865e575c Mon Sep 17 00:00:00 2001 From: Jona Walpert <98217482+Jona-Walpert@users.noreply.github.com> Date: Thu, 12 Mar 2026 15:36:59 +0100 Subject: [PATCH] Test: Unit test for Translating Button IDs into backend Lobby IDs --- .../LobbyButtonTranslationManagerTest.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/LobbyButtonTranslationManagerTest.java diff --git a/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/LobbyButtonTranslationManagerTest.java b/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/LobbyButtonTranslationManagerTest.java new file mode 100644 index 0000000..82a35ad --- /dev/null +++ b/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/lobbyui/LobbyButtonTranslationManagerTest.java @@ -0,0 +1,57 @@ +package ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui; + +import org.junit.jupiter.api.*; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; + +class LobbyButtonTranslationManagerTest { + LobbyButtonTranslationManager manager; + + @BeforeEach + void setUp() { + manager = new LobbyButtonTranslationManager(); + manager.getButtonIdToLobbyId().clear(); + manager.saveTranslation(); + } + + @Test + void testAddLobbyButton() throws Exception { + manager.addLobbyButton(1, 100); + assertEquals(100, manager.getLobbyIdForButton(1)); + } + + @Test + void testRemoveLobbyButton() throws Exception { + manager.addLobbyButton(2, 200); + manager.removeLobbyButton(2); + assertNull(manager.getLobbyIdForButton(2)); + } + + @Test + void testIsFull() throws Exception { + for (int i = 1; i <= 8; i++) { + manager.addLobbyButton(i, 100 + i); + } + assertTrue(manager.isFull()); + Exception ex = assertThrows(Exception.class, () -> manager.addLobbyButton(9, 109)); + assertEquals("Grid is full!", ex.getMessage()); + } + + @Test + void testSaveAndLoadTranslation() throws Exception { + manager.addLobbyButton(3, 300); + manager.saveTranslation(); + manager.getButtonIdToLobbyId().clear(); + manager.loadTranslation(); + assertEquals(300, manager.getLobbyIdForButton(3)); + } + + @Test + void testGetButtonIdToLobbyId() throws Exception { + manager.addLobbyButton(4, 400); + Map map = manager.getButtonIdToLobbyId(); + assertTrue(map.containsKey(4)); + assertEquals(400, map.get(4)); + } +}