-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from BME-MIT-IET/szentesi_UITests
Szentesi UI tests
- Loading branch information
Showing
3 changed files
with
229 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -449,4 +449,8 @@ public void drawInterface() { | |
frame.add(layeredPane); | ||
} | ||
|
||
public JFrame getFrame(){ | ||
return frame; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
package virologist.view; | ||
|
||
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; | ||
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; | ||
|
||
private static final int ROBOT_DELAY = 200; | ||
|
||
@BeforeAll | ||
public static void createEnvironment(){ | ||
try{ | ||
loader = new Loader(); | ||
controller = new Controller(loader.loadGame("maps/map3.txt")); | ||
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 @Order (1) | ||
public void moveTest(){ | ||
robot.delay(ROBOT_DELAY); | ||
clickAt(20, 40); | ||
robot.mouseMove(20, 90); | ||
robot.delay(ROBOT_DELAY); | ||
clickAt(200, 90); | ||
robot.delay(ROBOT_DELAY); | ||
assertEquals("Field2", Game.Create().GetCurrentPlayer().getField().getName()); | ||
} | ||
|
||
@Test @Order (2) | ||
public void endTurnTest(){ | ||
Virologist player1 = Game.Create().GetCurrentPlayer(); | ||
robot.delay(ROBOT_DELAY); | ||
clickAt(20, 40); | ||
robot.delay(ROBOT_DELAY); | ||
clickAt(20, 270); | ||
robot.delay(ROBOT_DELAY); | ||
assertNotEquals(player1, Game.Create().GetCurrentPlayer()); | ||
robot.delay(ROBOT_DELAY); | ||
} | ||
|
||
@Test @Order (3) | ||
public void dropTest(){ | ||
clickAt(20, 40); | ||
robot.delay(ROBOT_DELAY); | ||
clickAt(20, 100); | ||
robot.delay(ROBOT_DELAY); | ||
assertEquals(0, Game.Create().GetCurrentPlayer().GetEquipments().size()); | ||
robot.delay(ROBOT_DELAY); | ||
clickAt(20, 40); | ||
robot.delay(ROBOT_DELAY); | ||
clickAt(20, 270); | ||
robot.delay(ROBOT_DELAY); | ||
} | ||
|
||
@Test @Order (4) | ||
public void equipTest(){ | ||
int numEquipment = Game.Create().GetCurrentPlayer().GetEquipments().size(); | ||
clickAt(20, 40); | ||
robot.delay(ROBOT_DELAY); | ||
clickAt(20, 230); | ||
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(ROBOT_DELAY); | ||
clickAt(20, 40); | ||
robot.delay(ROBOT_DELAY); | ||
clickAt(20, 60); | ||
robot.delay(ROBOT_DELAY); | ||
clickAt(170, 60); | ||
robot.delay(ROBOT_DELAY); | ||
assertTrue(Game.Create().getVirologists().size() < numPlayers); | ||
} | ||
|
||
@Test @Order (6) | ||
public void endTurnTestBigButton(){ | ||
Virologist player1 = Game.Create().GetCurrentPlayer(); | ||
clickAt(530, 530); | ||
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) | ||
public void collectTest(){ | ||
Field warehouse = Game.Create().GetFields().get(0); | ||
for (Field field : Game.Create().GetFields()) { | ||
if(field instanceof Warehouse){ | ||
warehouse = field; | ||
break; | ||
} | ||
} | ||
|
||
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(ROBOT_DELAY); | ||
clickAt(20, 200); | ||
robot.delay(ROBOT_DELAY); | ||
assertTrue(Game.Create().GetCurrentPlayer().GetAminoAcid() > amino || Game.Create().GetCurrentPlayer().GetNucleotide() > nucleo); | ||
} | ||
|
||
@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(ROBOT_DELAY); | ||
clickAt(20, 210); | ||
robot.delay(ROBOT_DELAY); | ||
assertTrue(Game.Create().GetCurrentPlayer().getGeneticCodes().size() > codes); | ||
} | ||
|
||
@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(ROBOT_DELAY); | ||
clickAt(20, 250); | ||
robot.delay(ROBOT_DELAY); | ||
clickAt(170, 250); | ||
robot.delay(ROBOT_DELAY); | ||
clickAt(200, 250); | ||
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(ROBOT_DELAY); | ||
robot.mousePress(leftClick); | ||
robot.mouseRelease(leftClick); | ||
} | ||
} |