UNIT TESTING IS HEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEL
This commit is contained in:
parent
292f446d10
commit
5b759f9adc
@ -11,6 +11,19 @@
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-module-junit4:2.0.6" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-module-junit4-common:2.0.6" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-reflect:2.0.6" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy:1.9.10" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.9.10" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-core:2.0.6" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.javassist:javassist:3.27.0-GA" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-api-mockito2:2.0.6" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.powermock:powermock-api-support:2.0.6" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:2.28.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.6" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.7.0-M1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.7.0-M1" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
|
||||
|
||||
@ -20,11 +20,23 @@ public class Battle {
|
||||
|
||||
private boolean playerAttack;
|
||||
|
||||
public boolean isTimerStopped() {
|
||||
return timerStopped;
|
||||
}
|
||||
|
||||
public void setTimerStopped(boolean timerStopped) {
|
||||
this.timerStopped = timerStopped;
|
||||
}
|
||||
|
||||
private boolean timerStopped;
|
||||
|
||||
public BattlePerson getTurnBelongTo() {
|
||||
return turnBelongTo;
|
||||
}
|
||||
|
||||
public void setPlayerAttack(boolean playerAttack) {
|
||||
windowOfBattle.getMenuOfActions().setVisible(false);
|
||||
windowOfBattle.getEnemyDescription().setVisible(false);
|
||||
this.playerAttack = playerAttack;
|
||||
}
|
||||
|
||||
@ -42,11 +54,11 @@ public class Battle {
|
||||
return heroes;
|
||||
}
|
||||
|
||||
private boolean checkHealthOfEnemies(){
|
||||
public boolean checkHealthOfEnemies(){
|
||||
return enemies.isEmpty();
|
||||
}
|
||||
|
||||
private boolean checkHealthOfHeroes(){
|
||||
public boolean checkHealthOfHeroes(){
|
||||
return heroes.isEmpty();
|
||||
}
|
||||
|
||||
@ -76,12 +88,14 @@ public class Battle {
|
||||
private void endBattle(boolean b) {
|
||||
//TODO Return to Map
|
||||
timer.stop();
|
||||
timerStopped = true;
|
||||
if (b) windowOfBattle.writeToOutput("Win!");
|
||||
else windowOfBattle.writeToOutput("Lose!");
|
||||
}
|
||||
|
||||
private void returnControlToPlayer(){
|
||||
timer.stop();
|
||||
timerStopped = true;
|
||||
windowOfBattle.getMenuOfActions().setVisible(true);
|
||||
for (Component e: windowOfBattle.getMenuOfActions().getComponents()) e.setEnabled(true);
|
||||
windowOfBattle.getEnemyDescription().setVisible(true);
|
||||
@ -89,8 +103,6 @@ public class Battle {
|
||||
|
||||
private void attackByHero(Enemy e) {
|
||||
turnCount++;
|
||||
windowOfBattle.getMenuOfActions().setVisible(false);
|
||||
windowOfBattle.getEnemyDescription().setVisible(false);
|
||||
windowOfBattle.repaint();
|
||||
turnBelongTo.attack(e);
|
||||
|
||||
|
||||
63
src/test/java/ruscz/game/gameOfProd/Battle/BattleTest.java
Normal file
63
src/test/java/ruscz/game/gameOfProd/Battle/BattleTest.java
Normal file
@ -0,0 +1,63 @@
|
||||
package ruscz.game.gameOfProd.Battle;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import ruscz.game.gameOfProd.Game;
|
||||
import ruscz.game.gameOfProd.Windows.WindowOfBattle;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import static ruscz.game.gameOfProd.Windows.WindowOfFreeMove.sleep;
|
||||
|
||||
public class BattleTest {
|
||||
|
||||
@Test
|
||||
public void startBattle_battleWithAMightHero_winOfHero(){
|
||||
//Arrange
|
||||
Battle battle;
|
||||
Hero h;
|
||||
Enemy e1, e2;
|
||||
LinkedList<Hero> llh;
|
||||
LinkedList<Enemy> lle;
|
||||
Game game;
|
||||
|
||||
//Act
|
||||
game = new Game();
|
||||
game.setVisible(false);
|
||||
|
||||
h = new Hero(100, 100, "123", 100, 100, 100);
|
||||
e1 = new Enemy(1, 1,"1", 1, 1);
|
||||
e2 = new Enemy(2,2,"2", 2, 2);
|
||||
|
||||
llh = new LinkedList<>(Collections.singleton(h));
|
||||
lle = new LinkedList<>(Arrays.asList(e1, e2));
|
||||
|
||||
battle = new Battle(llh, lle, new WindowOfBattle(game));
|
||||
battle.startBattle();
|
||||
|
||||
battle.setPlayerAttack(true);
|
||||
battle.setTimerStopped(false);
|
||||
battle.getTimer().start();
|
||||
|
||||
timerOfWaiting(battle);
|
||||
|
||||
battle.setPlayerAttack(true);
|
||||
battle.setTimerStopped(false);
|
||||
battle.getTimer().start();
|
||||
|
||||
timerOfWaiting(battle);
|
||||
|
||||
//Assertion
|
||||
Assertions.assertFalse(battle.checkHealthOfHeroes());
|
||||
Assertions.assertTrue(battle.checkHealthOfEnemies());
|
||||
|
||||
}
|
||||
|
||||
private void timerOfWaiting(Battle battle){
|
||||
while (!battle.isTimerStopped()){
|
||||
sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user