-
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
Showing
3 changed files
with
160 additions
and
2 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 |
---|---|---|
@@ -1,5 +1,56 @@ | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.MockedStatic; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.mockStatic; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
class SaboteurTest { | ||
private Saboteur saboteur; | ||
private final String name = "Test Saboteur"; | ||
|
||
@BeforeEach | ||
public void init() { | ||
this.saboteur = new Saboteur(name, ""); | ||
} | ||
|
||
@Test | ||
void makeSlippery() { | ||
var saboteurSpy = spy(saboteur); | ||
var pipe = spy(Pipe.class); | ||
assertFalse(pipe.GetSlippery() > 0); | ||
saboteurSpy.MakeSlippery(pipe); | ||
assertTrue(pipe.GetSlippery() > 0); | ||
verify(saboteurSpy, times(1)).DecreaseActionPoints(); | ||
} | ||
|
||
@Test | ||
void getStatus() { | ||
var status = saboteur.GetStatus(); | ||
assertEquals(5, status.size()); | ||
assertEquals(name, status.get(0)); | ||
assertEquals("saboteur", status.get(1)); | ||
assertTrue(Integer.parseInt(status.get(2)) >= 0); | ||
assertTrue(Integer.parseInt(status.get(3)) >= 0); | ||
assertEquals(String.valueOf(saboteur.GetActionPoints()), status.get(4)); | ||
} | ||
|
||
@Test | ||
void interactOptions() { | ||
var field = spy(Field.class); | ||
saboteur.SetField(field); | ||
try (MockedStatic<GameFrame> gameFrameStatic = mockStatic(GameFrame.class)) { | ||
var gameFrameSpy = mock(GameFrame.class); | ||
gameFrameStatic.when(GameFrame::Get).thenReturn(gameFrameSpy); | ||
saboteur.InteractOptions(); | ||
verify(gameFrameSpy, times(1)).DrawField(field); | ||
verify(gameFrameSpy, times(1)).DrawPlayer(saboteur); | ||
} | ||
} | ||
} |
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,111 @@ | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.MockedStatic; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.mockStatic; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
|
||
class TankTest { | ||
private Tank tank; | ||
|
||
@BeforeEach | ||
public void init() { | ||
this.tank = new Tank(); | ||
} | ||
|
||
@Test | ||
void referenceID() { | ||
var referenceID = tank.GetReferenceID(); | ||
assertFalse(referenceID.isEmpty()); | ||
} | ||
|
||
@Test | ||
void numberOfPumps() { | ||
var numberOfPumps = tank.getNumberOfPumps(); | ||
tank.setNumberOfPumps(numberOfPumps + 10); | ||
assertEquals(numberOfPumps + 10, tank.getNumberOfPumps()); | ||
} | ||
|
||
@Test | ||
void numberOfPipes() { | ||
var numberOfPipes = tank.getNumberOfPipes(); | ||
tank.setNumberOfPipes(numberOfPipes + 10); | ||
assertEquals(numberOfPipes + 10, tank.getNumberOfPipes()); | ||
} | ||
|
||
@Test | ||
void generatePipe() { | ||
var numberOfPipes = tank.getNumberOfPipes(); | ||
int rounds = 100; | ||
for (int i = 0; i < rounds; i++) | ||
tank.GeneratePipe(); | ||
assertTrue(tank.getNumberOfPipes() > numberOfPipes); | ||
assertTrue(tank.getNumberOfPumps() < numberOfPipes + rounds); | ||
} | ||
|
||
@Test | ||
void generatePump() { | ||
var numberOfPumps = tank.getNumberOfPumps(); | ||
int rounds = 100; | ||
for (int i = 0; i < rounds; i++) | ||
tank.GeneratePump(); | ||
assertTrue(tank.getNumberOfPumps() > numberOfPumps); | ||
assertTrue(tank.getNumberOfPipes() < numberOfPumps + rounds); | ||
} | ||
|
||
@Test | ||
void decreaseNumberOfPipes() { | ||
var numberOfPipes = tank.getNumberOfPipes(); | ||
tank.DecreaseNumberOfPipes(); | ||
assertEquals(numberOfPipes - 1, tank.getNumberOfPipes()); | ||
} | ||
|
||
@Test | ||
void decreaseNumberOfPumps() { | ||
var numberOfPumps = tank.getNumberOfPumps(); | ||
tank.DecreaseNumberOfPumps(); | ||
assertEquals(numberOfPumps - 1, tank.getNumberOfPumps()); | ||
} | ||
|
||
@Test | ||
void givePipe() { | ||
var fixer = mock(Fixer.class); | ||
var tankSpy = spy(tank); | ||
tankSpy.GivePipe(fixer); | ||
verify(tankSpy, times(1)).DecreaseNumberOfPipes(); | ||
} | ||
|
||
@Test | ||
void givePump() { | ||
var tankSpy = spy(tank); | ||
var fixer = mock(Fixer.class); | ||
tankSpy.GivePump(fixer); | ||
verify(tankSpy, times(1)).DecreaseNumberOfPumps(); | ||
} | ||
|
||
@Test | ||
void step() { | ||
var tankSpy = spy(tank); | ||
tankSpy.Step(); | ||
verify(tankSpy, times(1)).GeneratePipe(); | ||
verify(tankSpy, times(1)).GeneratePump(); | ||
} | ||
|
||
@Test | ||
void acceptWater() { | ||
try (MockedStatic<Game> game = mockStatic(Game.class)) { | ||
var gameSpy = spy(Game.class); | ||
game.when(Game::Get).thenReturn(gameSpy); | ||
var fieldMock = mock(Field.class); | ||
tank.AcceptWater(fieldMock); | ||
verify(gameSpy, times(1)).InceraseFixerPoints(); | ||
} | ||
} | ||
} |