-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d58921
commit ac187d3
Showing
7 changed files
with
315 additions
and
6 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
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 |
---|---|---|
@@ -1,5 +1,171 @@ | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
class ActionHandlerTest { | ||
private ActionHandler actionHandler; | ||
private static MockedStatic<Game> gameClass; | ||
private static MockedStatic<GameFrame> gameFrameClass; | ||
|
||
@BeforeEach | ||
public void init() { | ||
this.actionHandler = new ActionHandler(); | ||
} | ||
|
||
@BeforeAll | ||
static void initOnce() { | ||
gameClass = Mockito.mockStatic(Game.class); | ||
gameFrameClass = mockStatic(GameFrame.class); | ||
} | ||
|
||
@Test | ||
void PlayerTurn_hasPoints() { | ||
Player player = Mockito.mock(Player.class); | ||
|
||
when(player.GetActionPoints()) | ||
.thenReturn(2) | ||
.thenReturn(1) | ||
.thenReturn(0); | ||
actionHandler.PlayerTurn(player); | ||
|
||
verify(player, times(2)).InteractOptions(); | ||
} | ||
|
||
@Test | ||
void PlayerTurn_noPoints() { | ||
Player player = Mockito.mock(Player.class); | ||
|
||
when(player.GetActionPoints()) | ||
.thenReturn(0); | ||
actionHandler.PlayerTurn(player); | ||
|
||
verify(player, times(0)).InteractOptions(); | ||
} | ||
|
||
@Test | ||
void HandleTurn() { | ||
try { | ||
Game game = mock(Game.class); | ||
gameClass.when(Game::Get).thenReturn(game); | ||
|
||
Player player = mock(Player.class); | ||
ArrayList<Player> players = new ArrayList<>(); | ||
players.add(player); | ||
|
||
when(game.GetPlayers()) | ||
.thenReturn(players); | ||
|
||
when(game.GetActivePlayer()) | ||
.thenReturn(player); | ||
|
||
GameFrame gameFrame = mock(GameFrame.class); | ||
gameFrameClass.when(GameFrame::Get) | ||
.thenReturn(gameFrame); | ||
|
||
GameField gameField = mock(GameField.class); | ||
when(gameFrame.GetPlayerLayer()) | ||
.thenReturn(gameField); | ||
|
||
when(player.GetActionPoints()) | ||
.thenReturn(3) | ||
.thenReturn(2) | ||
.thenReturn(1) | ||
.thenReturn(0); | ||
|
||
Field field = mock(Field.class); | ||
when(player.GetField()) | ||
.thenReturn(field); | ||
|
||
Map map = mock(Map.class); | ||
when(game.GetMap()) | ||
.thenReturn(map); | ||
|
||
Field field2 = mock(Field.class); | ||
ArrayList<ArrayList<Field>> mapFields1 = new ArrayList<>(); | ||
ArrayList<ArrayList<Field>> mapFields2 = new ArrayList<>(); | ||
ArrayList<Field> mapFields2Inner = new ArrayList<>(); | ||
mapFields2Inner.add(field2); | ||
mapFields2.add(mapFields2Inner); | ||
when(map.GetFields()) | ||
.thenReturn(mapFields1) | ||
.thenReturn(mapFields2); | ||
|
||
actionHandler.HandleTurn(); | ||
|
||
verify(gameField, times(1)).UpdateField(any()); | ||
verify(game, times(1)).SetActivePlayer(player); | ||
verify(player, times(1)).SetActionPoints(3); | ||
verify(gameFrame, times(1)).DrawField(field); | ||
verify(gameFrame, times(1)).DrawPlayer(player); | ||
|
||
verify(player, times(3)).InteractOptions(); | ||
|
||
verify(gameFrame, times(1)).DrawField(field2); | ||
|
||
verify(gameFrame, times(1)).DrawPoints(); | ||
} catch(Exception e) { | ||
throw e; | ||
} | ||
} | ||
|
||
@Test | ||
void WorldTurn() { | ||
try { | ||
Game game = mock(Game.class); | ||
gameClass.when(Game::Get) | ||
.thenReturn(game); | ||
|
||
Map map = mock(Map.class); | ||
when(game.GetMap()) | ||
.thenReturn(map); | ||
|
||
Field field1 = mock(Field.class); | ||
Field field2 = mock(Field.class); | ||
|
||
ArrayList<ArrayList<Field>> fieldsMat = new ArrayList<>(); | ||
ArrayList<Field> fieldsRow = new ArrayList<>(); | ||
fieldsRow.add(field1); | ||
fieldsRow.add(field2); | ||
fieldsMat.add(fieldsRow); | ||
when(map.GetFields()) | ||
.thenReturn(fieldsMat); | ||
|
||
when(field1.GetPOut()) | ||
.thenReturn(field2); | ||
when(field2.GetPIn()) | ||
.thenReturn(field1); | ||
|
||
when(map.GetDirection(field1, field2)) | ||
.thenReturn("left"); | ||
when(map.GetDirection(field2, field1)) | ||
.thenReturn("right"); | ||
|
||
when(field1.GetBeenStepped()) | ||
.thenReturn(false).thenReturn(true); | ||
when(field2.GetBeenStepped()) | ||
.thenReturn(false).thenReturn(true); | ||
|
||
GameFrame gameFrame = mock(GameFrame.class); | ||
gameFrameClass.when(GameFrame::Get).thenReturn(gameFrame); | ||
|
||
actionHandler.WorldTurn(); | ||
|
||
verify(field1, times(1)).Step(); | ||
verify(field2, times(1)).Step(); | ||
|
||
verify(field1, times(1)).SetBeenStepped(true); | ||
verify(field2, times(1)).SetBeenStepped(true); | ||
|
||
} | ||
verify(gameFrame, times(1)).DrawField(field1); | ||
verify(gameFrame, times(1)).DrawField(field2); | ||
} catch(Exception e) { | ||
throw e; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,27 @@ | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class BlankFieldTest { | ||
private BlankField field; | ||
|
||
@BeforeEach | ||
public void init() { | ||
this.field = new BlankField(); | ||
} | ||
|
||
@Test | ||
void GetReferenceID() { | ||
this.field = new BlankField("refID"); | ||
|
||
assertEquals("refID", field.GetReferenceID()); | ||
} | ||
|
||
@Test | ||
void CanAcceptPlayer() { | ||
assertEquals(false, field.CanAcceptPlayer()); | ||
} | ||
|
||
|
||
} |
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 |
---|---|---|
@@ -1,5 +1,72 @@ | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
|
||
class FixerTest { | ||
private Fixer fixer; | ||
|
||
@BeforeEach | ||
void init() { | ||
fixer = new Fixer("fixer", "picture"); | ||
} | ||
|
||
@Test | ||
void Fix() { | ||
Active active = Mockito.mock(Active.class); | ||
|
||
fixer.Fix(active); | ||
|
||
verify(active, times(1)).Fix(); | ||
} | ||
|
||
@Test | ||
void RemoveActivePipe() { | ||
Pipe pipe = Mockito.mock(Pipe.class); | ||
|
||
fixer.RemoveActivePipe(pipe); | ||
|
||
verify(pipe, times(1)).Remove(fixer); | ||
} | ||
|
||
@Test | ||
void CarryPump() { | ||
Tank tank = Mockito.mock(Tank.class); | ||
|
||
fixer.CarryPump(tank); | ||
|
||
verify(tank, times(1)).GivePump(fixer); | ||
} | ||
|
||
@Test | ||
void CarryPipe() { | ||
Tank tank = Mockito.mock(Tank.class); | ||
|
||
fixer.CarryPipe(tank); | ||
|
||
verify(tank, times(1)).GivePipe(fixer); | ||
} | ||
|
||
@Test | ||
void ActiveGetSet() { | ||
Active active = Mockito.mock(Active.class); | ||
|
||
fixer.SetActive(active); | ||
|
||
assertEquals(active, fixer.GetActive()); | ||
} | ||
|
||
@Test | ||
void HasActiveGetSet() { | ||
boolean hasActive = true; | ||
|
||
fixer.SetHasActive(hasActive); | ||
|
||
assertEquals(hasActive, fixer.GetHasActive()); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,5 +1,20 @@ | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class FountainTest { | ||
private Fountain fountain; | ||
|
||
@BeforeEach | ||
void init() { | ||
this.fountain = new Fountain(); | ||
} | ||
|
||
@Test | ||
void GetReferenceID() { | ||
this.fountain = new Fountain("ref"); | ||
assertEquals("ref", fountain.GetReferenceID()); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,5 +1,41 @@ | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
class GameTest { | ||
private Game game; | ||
|
||
@BeforeEach | ||
void init() { | ||
this.game = Game.Get(); | ||
} | ||
|
||
@Test | ||
void ResetPlayers() { | ||
game.ResetPlayers(); | ||
|
||
// Player player1 = Mockito.mock(Player.class); | ||
// Player player2 = Mockito.mock(Player.class); | ||
// ArrayList<Player> players = new ArrayList<>(); | ||
// players.add(player1); | ||
// players.add(player2); | ||
|
||
// this.game = Mockito.spy(Game.class); | ||
|
||
// when(game.getPlayerCount()) | ||
// .thenReturn(2); | ||
|
||
// game.getPlayerCount(); | ||
|
||
|
||
// this.game = Game.Get(); | ||
// game.SetPlayers(players); | ||
} | ||
|
||
} |