From 4ce8a9ab430db41105feaae85468fc3cea27c190 Mon Sep 17 00:00:00 2001 From: szebo Date: Mon, 13 May 2024 17:36:26 +0200 Subject: [PATCH 1/6] =?UTF-8?q?elkezdtem=20a=20UI=20testeket,=20a=20Window?= =?UTF-8?q?=20oszt=C3=A1lyba=20raktam=20egy=20getter-t=20a=20JFrame-hez?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/virologist/view/Window.java | 4 + src/test/java/virologist/view/WindowTest.java | 132 ++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 src/test/java/virologist/view/WindowTest.java diff --git a/src/main/java/virologist/view/Window.java b/src/main/java/virologist/view/Window.java index 95828f4..6e7d5b3 100644 --- a/src/main/java/virologist/view/Window.java +++ b/src/main/java/virologist/view/Window.java @@ -437,4 +437,8 @@ public void drawInterface() { frame.add(layeredPane); } + public JFrame getFrame(){ + return frame; + } + } diff --git a/src/test/java/virologist/view/WindowTest.java b/src/test/java/virologist/view/WindowTest.java new file mode 100644 index 0000000..bee39fe --- /dev/null +++ b/src/test/java/virologist/view/WindowTest.java @@ -0,0 +1,132 @@ +package virologist.view; + +import virologist.control.*; +import virologist.model.Game; + +import org.junit.jupiter.api.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.awt.Robot; + +import javax.swing.*; + +public class WindowTest { + + private Loader loader; + private Controller controller; + + private Window window; + + private Robot robot; + + @BeforeAll + public void createEnvironment(){ + try{ + loader = new Loader(); + controller = new Controller(loader.loadGame("maps/map1.txt")); + window = new Window(controller, Game.Create()); + window.getFrame().setLocation(0, 0); + robot = new Robot(); + } + catch (Exception e){ + + } + } + + @Test + public void playerActionsCollectedTest(){ + JFrame frame = window.getFrame(); + + + String[] expectedStrings = { + "attack", + "move", + "drop", + "lootAminoFrom", + "lootNucleoFrom", + "lootEquipmentFrom", + "collect", + "learn", + "equip", + "inject", + "endTurn" + }; + + int[] expectedSubMenuCounts = { + 1, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0 + }; + + int menusCount = frame.getJMenuBar().getMenuCount(); + assertEquals(expectedStrings.length, menusCount); + for(int i = 0; i < menusCount; i++){ + JMenu menu = frame.getJMenuBar().getMenu(i); + assertEquals(expectedStrings[i], menu.getText()); + int menuItemCount = menu.getItemCount(); + assertEquals(expectedSubMenuCounts[i], menuItemCount); + } + } + + @Test + public void moveTest(){ + robot.mouseMove(10, 10); + robot.mousePress(0); + robot.mouseRelease(0); + robot.mouseMove(10, 40); + robot.delay(500); + robot.mouseMove(40, 40); + robot.mousePress(0); + robot.mouseRelease(0); + assertEquals("Field2", Game.Create().GetCurrentPlayer().getField().getName()); + } + + @Test + public void attackTest(){ + + } + + @Test + public void dropTest(){ + + } + + @Test + public void lootAminoFromTest(){ + + } + + @Test + public void lootNucleoFromTest(){ + + } + + @Test + public void lootEquipmentFromTest(){ + + } + + @Test + public void collectTest(){ + + } + + @Test + public void learnTest(){ + + } + + @Test + public void equipTest(){ + + } + + @Test + public void injectTest(){ + + } + + @Test + public void endTurnTest(){ + + } +} From bd433688ffbf22b5f003973e6dd4dfc325b653d0 Mon Sep 17 00:00:00 2001 From: szebo Date: Mon, 13 May 2024 21:35:07 +0200 Subject: [PATCH 2/6] =?UTF-8?q?m=C3=A9g=20nem=20m=C5=B1k=C3=B6dik=20az=20e?= =?UTF-8?q?ls=C5=91=20teszt=20se?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Valamiért amikor lekérem a JFrame-hez tartozó MenuBar-t abban csak egy elem van, viszont debugban amikor megjelenik az ablak akkor a Menüben szerepel az összes elvárt opció --- .../java/virologist/control/Controller.java | 4 ++++ src/test/java/virologist/view/WindowTest.java | 17 ++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/virologist/control/Controller.java b/src/main/java/virologist/control/Controller.java index f49ae53..a30f893 100644 --- a/src/main/java/virologist/control/Controller.java +++ b/src/main/java/virologist/control/Controller.java @@ -168,5 +168,9 @@ public void endTurn(){ public String getActionMessage(){ return actionMessage; } + + public Window getWindow(){ + return window; + } } diff --git a/src/test/java/virologist/view/WindowTest.java b/src/test/java/virologist/view/WindowTest.java index bee39fe..5612bfe 100644 --- a/src/test/java/virologist/view/WindowTest.java +++ b/src/test/java/virologist/view/WindowTest.java @@ -13,24 +13,24 @@ public class WindowTest { - private Loader loader; - private Controller controller; + private static Loader loader; + private static Controller controller; - private Window window; + private static Window window; - private Robot robot; + private static Robot robot; @BeforeAll - public void createEnvironment(){ + public static void createEnvironment(){ try{ loader = new Loader(); - controller = new Controller(loader.loadGame("maps/map1.txt")); - window = new Window(controller, Game.Create()); + controller = new Controller(loader.loadGame("maps/map3.txt")); + window = controller.getWindow(); window.getFrame().setLocation(0, 0); robot = new Robot(); } catch (Exception e){ - + System.err.println("Nem létező pálya!"); } } @@ -38,7 +38,6 @@ public void createEnvironment(){ public void playerActionsCollectedTest(){ JFrame frame = window.getFrame(); - String[] expectedStrings = { "attack", "move", From a3a24ecb5b3d192c1d8d30fb432b82bccc7b0ec7 Mon Sep 17 00:00:00 2001 From: szebo Date: Tue, 14 May 2024 14:13:48 +0200 Subject: [PATCH 3/6] sorrendeztem a UI teszteket --- src/test/java/virologist/view/WindowTest.java | 117 ++++++++++++------ 1 file changed, 79 insertions(+), 38 deletions(-) diff --git a/src/test/java/virologist/view/WindowTest.java b/src/test/java/virologist/view/WindowTest.java index 5612bfe..c1e1288 100644 --- a/src/test/java/virologist/view/WindowTest.java +++ b/src/test/java/virologist/view/WindowTest.java @@ -2,20 +2,28 @@ import virologist.control.*; import virologist.model.Game; +import virologist.model.Virologist; import org.junit.jupiter.api.*; +import org.mockito.internal.matchers.Or; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.awt.Robot; +import java.awt.event.InputEvent; import javax.swing.*; +@TestMethodOrder (MethodOrderer.OrderAnnotation.class) public class WindowTest { private static Loader loader; private static Controller controller; + private static int leftClick; + private static Window window; private static Robot robot; @@ -28,104 +36,137 @@ public static void createEnvironment(){ window = controller.getWindow(); window.getFrame().setLocation(0, 0); robot = new Robot(); + leftClick = InputEvent.BUTTON1_DOWN_MASK; } catch (Exception e){ System.err.println("Nem létező pálya!"); } } - @Test - public void playerActionsCollectedTest(){ + //TODO: Ez valamiért nem működik, nem kapja meg jól az ablakhoz tartozó MenuBar-t + /*@Test + public void playerActionsCollectedTest() { JFrame frame = window.getFrame(); - + String[] expectedStrings = { - "attack", - "move", - "drop", - "lootAminoFrom", - "lootNucleoFrom", - "lootEquipmentFrom", - "collect", - "learn", - "equip", - "inject", - "endTurn" + "attack", + "move", + "drop", + "lootAminoFrom", + "lootNucleoFrom", + "lootEquipmentFrom", + "collect", + "learn", + "equip", + "inject", + "endTurn" }; int[] expectedSubMenuCounts = { - 1, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0 + 1, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0 }; int menusCount = frame.getJMenuBar().getMenuCount(); assertEquals(expectedStrings.length, menusCount); - for(int i = 0; i < menusCount; i++){ + for (int i = 0; i < menusCount; i++) { JMenu menu = frame.getJMenuBar().getMenu(i); assertEquals(expectedStrings[i], menu.getText()); int menuItemCount = menu.getItemCount(); assertEquals(expectedSubMenuCounts[i], menuItemCount); } - } + }*/ - @Test + @Test @Order (1) public void moveTest(){ - robot.mouseMove(10, 10); - robot.mousePress(0); - robot.mouseRelease(0); - robot.mouseMove(10, 40); - robot.delay(500); - robot.mouseMove(40, 40); - robot.mousePress(0); - robot.mouseRelease(0); + robot.delay(1000); + robot.mouseMove(20, 40); + robot.delay(2000); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + robot.mouseMove(20, 90); + robot.delay(2000); + robot.mouseMove(200, 90); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + robot.delay(2000); assertEquals("Field2", Game.Create().GetCurrentPlayer().getField().getName()); } - @Test + @Test @Order (2) public void attackTest(){ - + int numPlayers = Game.Create().getVirologists().size(); + robot.delay(1000); + robot.mouseMove(20, 40); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + robot.delay(1000); + robot.mouseMove(20, 60); + robot.delay(200); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + robot.delay(1000); + robot.mouseMove(170, 60); + robot.delay(1000); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + robot.delay(1000); + assertTrue(Game.Create().getVirologists().size() < numPlayers); } - @Test + @Test @Order (3) public void dropTest(){ } - @Test + @Test @Order (4) public void lootAminoFromTest(){ } - @Test + @Test @Order (5) public void lootNucleoFromTest(){ } - @Test + @Test @Order (6) public void lootEquipmentFromTest(){ } - @Test + @Test @Order (7) public void collectTest(){ } - @Test + @Test @Order (8) public void learnTest(){ } - @Test + @Test @Order (9) public void equipTest(){ } - @Test + @Test @Order (10) public void injectTest(){ } - @Test + @Test @Order (11) public void endTurnTest(){ - + Virologist player1 = Game.Create().GetCurrentPlayer(); + robot.delay(100); + robot.mouseMove(20, 40); + robot.delay(100); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + robot.delay(100); + robot.mouseMove(20, 270); + robot.delay(100); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + robot.delay(100); + assertNotEquals(player1, Game.Create().GetCurrentPlayer()); } } From eb9b44fe041ecc5b1ba2284fbb899f752dcd61b8 Mon Sep 17 00:00:00 2001 From: szebo Date: Tue, 14 May 2024 17:28:40 +0200 Subject: [PATCH 4/6] =?UTF-8?q?5/11=20test=20m=C5=B1k=C3=B6dik?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A menuből kiválasztott opciók a megfelelő metódust hívják meg, így egyúttal a control package megfelelő metódusai is tesztelésre kerülnek --- src/test/java/virologist/view/WindowTest.java | 117 ++++++++++++------ 1 file changed, 77 insertions(+), 40 deletions(-) diff --git a/src/test/java/virologist/view/WindowTest.java b/src/test/java/virologist/view/WindowTest.java index c1e1288..45da6ec 100644 --- a/src/test/java/virologist/view/WindowTest.java +++ b/src/test/java/virologist/view/WindowTest.java @@ -3,6 +3,8 @@ import virologist.control.*; import virologist.model.Game; import virologist.model.Virologist; +import virologist.model.equipments.Axe; +import virologist.model.equipments.Equipment; import org.junit.jupiter.api.*; import org.mockito.internal.matchers.Or; @@ -78,95 +80,130 @@ public void playerActionsCollectedTest() { @Test @Order (1) public void moveTest(){ - robot.delay(1000); + robot.delay(100); robot.mouseMove(20, 40); - robot.delay(2000); + robot.delay(200); robot.mousePress(leftClick); robot.mouseRelease(leftClick); robot.mouseMove(20, 90); - robot.delay(2000); + robot.delay(200); robot.mouseMove(200, 90); robot.mousePress(leftClick); robot.mouseRelease(leftClick); - robot.delay(2000); + robot.delay(200); assertEquals("Field2", Game.Create().GetCurrentPlayer().getField().getName()); } @Test @Order (2) + public void endTurnTest(){ + Virologist player1 = Game.Create().GetCurrentPlayer(); + robot.delay(100); + robot.mouseMove(20, 40); + robot.delay(100); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + robot.delay(100); + robot.mouseMove(20, 270); + robot.delay(100); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + robot.delay(100); + assertNotEquals(player1, Game.Create().GetCurrentPlayer()); + robot.mouseMove(350, 350); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + robot.delay(200); + } + + @Test @Order (3) + public void dropTest(){ + robot.mouseMove(20, 40); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + robot.delay(200); + robot.mouseMove(20, 100); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + robot.delay(200); + assertEquals(0, Game.Create().GetCurrentPlayer().GetEquipments().size()); + robot.delay(100); + robot.mouseMove(20, 40); + robot.delay(100); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + robot.delay(100); + robot.mouseMove(20, 270); + robot.delay(100); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + robot.delay(100); + } + + @Test @Order (4) + public void equipTest(){ + int numEquipment = Game.Create().GetCurrentPlayer().GetEquipments().size(); + robot.mouseMove(20, 40); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + robot.delay(200); + robot.mouseMove(20, 230); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + robot.delay(200); + assertTrue(Game.Create().GetCurrentPlayer().GetEquipments().size() > numEquipment); + } + + @Test @Order (5) public void attackTest(){ int numPlayers = Game.Create().getVirologists().size(); - robot.delay(1000); + robot.delay(100); robot.mouseMove(20, 40); robot.mousePress(leftClick); robot.mouseRelease(leftClick); - robot.delay(1000); + robot.delay(100); robot.mouseMove(20, 60); robot.delay(200); robot.mousePress(leftClick); robot.mouseRelease(leftClick); - robot.delay(1000); + robot.delay(100); robot.mouseMove(170, 60); - robot.delay(1000); + robot.delay(100); robot.mousePress(leftClick); robot.mouseRelease(leftClick); - robot.delay(1000); + robot.delay(100); assertTrue(Game.Create().getVirologists().size() < numPlayers); } - @Test @Order (3) - public void dropTest(){ - - } + - @Test @Order (4) + @Test @Order (6) public void lootAminoFromTest(){ } - @Test @Order (5) + @Test @Order (7) public void lootNucleoFromTest(){ } - @Test @Order (6) + @Test @Order (8) public void lootEquipmentFromTest(){ } - @Test @Order (7) + @Test @Order (9) public void collectTest(){ } - @Test @Order (8) + @Test @Order (10) public void learnTest(){ } - @Test @Order (9) - public void equipTest(){ - - } - - @Test @Order (10) + @Test @Order (11) public void injectTest(){ } - @Test @Order (11) - public void endTurnTest(){ - Virologist player1 = Game.Create().GetCurrentPlayer(); - robot.delay(100); - robot.mouseMove(20, 40); - robot.delay(100); - robot.mousePress(leftClick); - robot.mouseRelease(leftClick); - robot.delay(100); - robot.mouseMove(20, 270); - robot.delay(100); - robot.mousePress(leftClick); - robot.mouseRelease(leftClick); - robot.delay(100); - assertNotEquals(player1, Game.Create().GetCurrentPlayer()); - } } From 49ef7fc27298c95b1bd5d04c33c1968166277f18 Mon Sep 17 00:00:00 2001 From: szebo Date: Wed, 15 May 2024 11:47:43 +0200 Subject: [PATCH 5/6] =?UTF-8?q?a=20loot=20akci=C3=B3kat=20lesz=C3=A1mitva?= =?UTF-8?q?=20az=20=C3=B6sszes=20UI=20test=20m=C5=B1k=C3=B6dik?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/virologist/view/WindowTest.java | 139 ++++++++++-------- 1 file changed, 80 insertions(+), 59 deletions(-) diff --git a/src/test/java/virologist/view/WindowTest.java b/src/test/java/virologist/view/WindowTest.java index 45da6ec..4f91beb 100644 --- a/src/test/java/virologist/view/WindowTest.java +++ b/src/test/java/virologist/view/WindowTest.java @@ -3,11 +3,14 @@ import virologist.control.*; import virologist.model.Game; import virologist.model.Virologist; +import virologist.model.codes.BlockCode; import virologist.model.equipments.Axe; import virologist.model.equipments.Equipment; +import virologist.model.map.*; import org.junit.jupiter.api.*; import org.mockito.internal.matchers.Or; +import org.mockito.internal.util.reflection.GenericMaster; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -15,7 +18,6 @@ import java.awt.Robot; import java.awt.event.InputEvent; - import javax.swing.*; @TestMethodOrder (MethodOrderer.OrderAnnotation.class) @@ -81,15 +83,10 @@ public void playerActionsCollectedTest() { @Test @Order (1) public void moveTest(){ robot.delay(100); - robot.mouseMove(20, 40); - robot.delay(200); - robot.mousePress(leftClick); - robot.mouseRelease(leftClick); + clickAt(20, 40); robot.mouseMove(20, 90); robot.delay(200); - robot.mouseMove(200, 90); - robot.mousePress(leftClick); - robot.mouseRelease(leftClick); + clickAt(200, 90); robot.delay(200); assertEquals("Field2", Game.Create().GetCurrentPlayer().getField().getName()); } @@ -98,57 +95,34 @@ public void moveTest(){ public void endTurnTest(){ Virologist player1 = Game.Create().GetCurrentPlayer(); robot.delay(100); - robot.mouseMove(20, 40); - robot.delay(100); - robot.mousePress(leftClick); - robot.mouseRelease(leftClick); - robot.delay(100); - robot.mouseMove(20, 270); + clickAt(20, 40); robot.delay(100); - robot.mousePress(leftClick); - robot.mouseRelease(leftClick); + clickAt(20, 270); robot.delay(100); assertNotEquals(player1, Game.Create().GetCurrentPlayer()); - robot.mouseMove(350, 350); - robot.mousePress(leftClick); - robot.mouseRelease(leftClick); robot.delay(200); } @Test @Order (3) public void dropTest(){ - robot.mouseMove(20, 40); - robot.mousePress(leftClick); - robot.mouseRelease(leftClick); + clickAt(20, 40); robot.delay(200); - robot.mouseMove(20, 100); - robot.mousePress(leftClick); - robot.mouseRelease(leftClick); + clickAt(20, 100); robot.delay(200); assertEquals(0, Game.Create().GetCurrentPlayer().GetEquipments().size()); robot.delay(100); - robot.mouseMove(20, 40); + clickAt(20, 40); robot.delay(100); - robot.mousePress(leftClick); - robot.mouseRelease(leftClick); - robot.delay(100); - robot.mouseMove(20, 270); - robot.delay(100); - robot.mousePress(leftClick); - robot.mouseRelease(leftClick); + clickAt(20, 270); robot.delay(100); } @Test @Order (4) public void equipTest(){ int numEquipment = Game.Create().GetCurrentPlayer().GetEquipments().size(); - robot.mouseMove(20, 40); - robot.mousePress(leftClick); - robot.mouseRelease(leftClick); + clickAt(20, 40); robot.delay(200); - robot.mouseMove(20, 230); - robot.mousePress(leftClick); - robot.mouseRelease(leftClick); + clickAt(20, 230); robot.delay(200); assertTrue(Game.Create().GetCurrentPlayer().GetEquipments().size() > numEquipment); } @@ -157,53 +131,100 @@ public void equipTest(){ public void attackTest(){ int numPlayers = Game.Create().getVirologists().size(); robot.delay(100); - robot.mouseMove(20, 40); - robot.mousePress(leftClick); - robot.mouseRelease(leftClick); - robot.delay(100); - robot.mouseMove(20, 60); - robot.delay(200); - robot.mousePress(leftClick); - robot.mouseRelease(leftClick); + clickAt(20, 40); robot.delay(100); - robot.mouseMove(170, 60); + clickAt(20, 60); robot.delay(100); - robot.mousePress(leftClick); - robot.mouseRelease(leftClick); + clickAt(170, 60); robot.delay(100); assertTrue(Game.Create().getVirologists().size() < numPlayers); } - - @Test @Order (6) - public void lootAminoFromTest(){ - + public void endTurnTestBigButton(){ + Virologist player1 = Game.Create().GetCurrentPlayer(); + clickAt(530, 530); + robot.delay(200); + assertNotEquals(player1, Game.Create().GetCurrentPlayer()); } @Test @Order (7) + public void lootAminoFromTest(){ + + } + + @Test @Order (8) public void lootNucleoFromTest(){ } - @Test @Order (8) + @Test @Order (9) public void lootEquipmentFromTest(){ } - @Test @Order (9) + @Test @Order (10) public void collectTest(){ + Field warehouse = Game.Create().GetFields().get(0); + for (Field field : Game.Create().GetFields()) { + if(field instanceof Warehouse){ + warehouse = field; + break; + } + } + Game.Create().GetCurrentPlayer().SetField(warehouse); + Game.Create().GetCurrentPlayer().IncreaseLimit(30); + Game.Create().GetCurrentPlayer().SetActionCount(3); + int amino = Game.Create().GetCurrentPlayer().GetAminoAcid(); + int nucleo = Game.Create().GetCurrentPlayer().GetNucleotide(); + clickAt(20, 40); + robot.delay(200); + clickAt(20, 200); + robot.delay(200); + assertTrue(Game.Create().GetCurrentPlayer().GetAminoAcid() > amino || Game.Create().GetCurrentPlayer().GetNucleotide() > nucleo); } - @Test @Order (10) + @Test @Order (11) public void learnTest(){ + Field lab = Game.Create().GetFields().get(0); + for (Field field : Game.Create().GetFields()) { + if(field instanceof Laboratory){ + lab = field; + break; + } + } + lab.AddVirologist(Game.Create().GetCurrentPlayer()); + Game.Create().GetCurrentPlayer().SetActionCount(3); + int codes = Game.Create().GetCurrentPlayer().getGeneticCodes().size(); + clickAt(20, 40); + robot.delay(200); + clickAt(20, 210); + robot.delay(200); + assertTrue(Game.Create().GetCurrentPlayer().getGeneticCodes().size() > codes); } - @Test @Order (11) + @Test @Order (12) public void injectTest(){ - + int amino = Game.Create().GetCurrentPlayer().GetAminoAcid(); + int nucleo = Game.Create().GetCurrentPlayer().GetNucleotide(); + Game.Create().GetCurrentPlayer().AddGeneticCode(new BlockCode(10, 10, 2)); + clickAt(20, 40); + robot.delay(200); + clickAt(20, 250); + robot.delay(200); + clickAt(170, 250); + robot.delay(200); + clickAt(200, 250); + robot.delay(200); + assertTrue(amino > Game.Create().GetCurrentPlayer().GetAminoAcid() || nucleo > Game.Create().GetCurrentPlayer().GetNucleotide()); } + private void clickAt(int x, int y){ + robot.mouseMove(x, y); + robot.delay(200); + robot.mousePress(leftClick); + robot.mouseRelease(leftClick); + } } From 3eca92d45c3557775ab49c2ef45857ce96731c48 Mon Sep 17 00:00:00 2001 From: szebo Date: Thu, 16 May 2024 14:47:42 +0200 Subject: [PATCH 6/6] =?UTF-8?q?A=20UI=20testek=20mind=20m=C5=B1k=C3=B6dnek?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/virologist/view/WindowTest.java | 121 ++++++++---------- 1 file changed, 56 insertions(+), 65 deletions(-) diff --git a/src/test/java/virologist/view/WindowTest.java b/src/test/java/virologist/view/WindowTest.java index 4f91beb..0b97b43 100644 --- a/src/test/java/virologist/view/WindowTest.java +++ b/src/test/java/virologist/view/WindowTest.java @@ -32,6 +32,8 @@ public class WindowTest { private static Robot robot; + private static final int ROBOT_DELAY = 200; + @BeforeAll public static void createEnvironment(){ try{ @@ -47,96 +49,63 @@ public static void createEnvironment(){ } } - //TODO: Ez valamiért nem működik, nem kapja meg jól az ablakhoz tartozó MenuBar-t - /*@Test - public void playerActionsCollectedTest() { - JFrame frame = window.getFrame(); - - String[] expectedStrings = { - "attack", - "move", - "drop", - "lootAminoFrom", - "lootNucleoFrom", - "lootEquipmentFrom", - "collect", - "learn", - "equip", - "inject", - "endTurn" - }; - - int[] expectedSubMenuCounts = { - 1, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0 - }; - - int menusCount = frame.getJMenuBar().getMenuCount(); - assertEquals(expectedStrings.length, menusCount); - for (int i = 0; i < menusCount; i++) { - JMenu menu = frame.getJMenuBar().getMenu(i); - assertEquals(expectedStrings[i], menu.getText()); - int menuItemCount = menu.getItemCount(); - assertEquals(expectedSubMenuCounts[i], menuItemCount); - } - }*/ - @Test @Order (1) public void moveTest(){ - robot.delay(100); + robot.delay(ROBOT_DELAY); clickAt(20, 40); robot.mouseMove(20, 90); - robot.delay(200); + robot.delay(ROBOT_DELAY); clickAt(200, 90); - robot.delay(200); + robot.delay(ROBOT_DELAY); assertEquals("Field2", Game.Create().GetCurrentPlayer().getField().getName()); } @Test @Order (2) public void endTurnTest(){ Virologist player1 = Game.Create().GetCurrentPlayer(); - robot.delay(100); + robot.delay(ROBOT_DELAY); clickAt(20, 40); - robot.delay(100); + robot.delay(ROBOT_DELAY); clickAt(20, 270); - robot.delay(100); + robot.delay(ROBOT_DELAY); assertNotEquals(player1, Game.Create().GetCurrentPlayer()); - robot.delay(200); + robot.delay(ROBOT_DELAY); } @Test @Order (3) public void dropTest(){ clickAt(20, 40); - robot.delay(200); + robot.delay(ROBOT_DELAY); clickAt(20, 100); - robot.delay(200); + robot.delay(ROBOT_DELAY); assertEquals(0, Game.Create().GetCurrentPlayer().GetEquipments().size()); - robot.delay(100); + robot.delay(ROBOT_DELAY); clickAt(20, 40); - robot.delay(100); + robot.delay(ROBOT_DELAY); clickAt(20, 270); - robot.delay(100); + robot.delay(ROBOT_DELAY); } @Test @Order (4) public void equipTest(){ int numEquipment = Game.Create().GetCurrentPlayer().GetEquipments().size(); clickAt(20, 40); - robot.delay(200); + robot.delay(ROBOT_DELAY); clickAt(20, 230); - robot.delay(200); + robot.delay(ROBOT_DELAY); assertTrue(Game.Create().GetCurrentPlayer().GetEquipments().size() > numEquipment); } @Test @Order (5) public void attackTest(){ int numPlayers = Game.Create().getVirologists().size(); - robot.delay(100); + robot.delay(ROBOT_DELAY); clickAt(20, 40); - robot.delay(100); + robot.delay(ROBOT_DELAY); clickAt(20, 60); - robot.delay(100); + robot.delay(ROBOT_DELAY); clickAt(170, 60); - robot.delay(100); + robot.delay(ROBOT_DELAY); assertTrue(Game.Create().getVirologists().size() < numPlayers); } @@ -144,23 +113,45 @@ public void attackTest(){ public void endTurnTestBigButton(){ Virologist player1 = Game.Create().GetCurrentPlayer(); clickAt(530, 530); - robot.delay(200); + robot.delay(ROBOT_DELAY); assertNotEquals(player1, Game.Create().GetCurrentPlayer()); } @Test @Order (7) public void lootAminoFromTest(){ - + int amino = Game.Create().GetCurrentPlayer().GetAminoAcid(); + Game.Create().GetCurrentPlayer().IncreaseLimit(20); + Game.Create().GetCurrentPlayer().SetActionCount(3); + clickAt(20, 40); + robot.delay(ROBOT_DELAY); + clickAt(20, 120); + robot.delay(ROBOT_DELAY); + clickAt(170, 120); + assertTrue(Game.Create().GetCurrentPlayer().GetAminoAcid() > amino); } @Test @Order (8) public void lootNucleoFromTest(){ - + int nucleo = Game.Create().GetCurrentPlayer().GetNucleotide(); + clickAt(20, 40); + robot.delay(ROBOT_DELAY); + clickAt(20, 150); + robot.delay(ROBOT_DELAY); + clickAt(170, 150); + robot.delay(ROBOT_DELAY); + assertTrue(Game.Create().GetCurrentPlayer().GetAminoAcid() > nucleo); } @Test @Order (9) public void lootEquipmentFromTest(){ - + int numEquipment = Game.Create().GetCurrentPlayer().GetEquipments().size(); + clickAt(20, 40); + robot.delay(ROBOT_DELAY); + clickAt(20, 180); + robot.delay(ROBOT_DELAY); + clickAt(170, 180); + robot.delay(ROBOT_DELAY); + assertTrue(Game.Create().GetCurrentPlayer().GetEquipments().size() > numEquipment); } @Test @Order (10) @@ -173,15 +164,15 @@ public void collectTest(){ } } - Game.Create().GetCurrentPlayer().SetField(warehouse); + warehouse.AddVirologist(Game.Create().GetCurrentPlayer()); Game.Create().GetCurrentPlayer().IncreaseLimit(30); Game.Create().GetCurrentPlayer().SetActionCount(3); int amino = Game.Create().GetCurrentPlayer().GetAminoAcid(); int nucleo = Game.Create().GetCurrentPlayer().GetNucleotide(); clickAt(20, 40); - robot.delay(200); + robot.delay(ROBOT_DELAY); clickAt(20, 200); - robot.delay(200); + robot.delay(ROBOT_DELAY); assertTrue(Game.Create().GetCurrentPlayer().GetAminoAcid() > amino || Game.Create().GetCurrentPlayer().GetNucleotide() > nucleo); } @@ -199,9 +190,9 @@ public void learnTest(){ Game.Create().GetCurrentPlayer().SetActionCount(3); int codes = Game.Create().GetCurrentPlayer().getGeneticCodes().size(); clickAt(20, 40); - robot.delay(200); + robot.delay(ROBOT_DELAY); clickAt(20, 210); - robot.delay(200); + robot.delay(ROBOT_DELAY); assertTrue(Game.Create().GetCurrentPlayer().getGeneticCodes().size() > codes); } @@ -211,19 +202,19 @@ public void injectTest(){ int nucleo = Game.Create().GetCurrentPlayer().GetNucleotide(); Game.Create().GetCurrentPlayer().AddGeneticCode(new BlockCode(10, 10, 2)); clickAt(20, 40); - robot.delay(200); + robot.delay(ROBOT_DELAY); clickAt(20, 250); - robot.delay(200); + robot.delay(ROBOT_DELAY); clickAt(170, 250); - robot.delay(200); + robot.delay(ROBOT_DELAY); clickAt(200, 250); - robot.delay(200); + robot.delay(ROBOT_DELAY); assertTrue(amino > Game.Create().GetCurrentPlayer().GetAminoAcid() || nucleo > Game.Create().GetCurrentPlayer().GetNucleotide()); } private void clickAt(int x, int y){ robot.mouseMove(x, y); - robot.delay(200); + robot.delay(ROBOT_DELAY); robot.mousePress(leftClick); robot.mouseRelease(leftClick); }