diff --git a/pom.xml b/pom.xml index 9bfa8e4..119baba 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,7 @@ 1.8 1.8 + 17 UTF-8 diff --git a/src/test/java/SaboteurTest.java b/src/test/java/SaboteurTest.java index 6ee2736..ffa257f 100644 --- a/src/test/java/SaboteurTest.java +++ b/src/test/java/SaboteurTest.java @@ -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 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); + } + } } \ No newline at end of file diff --git a/src/test/java/TankTest.java b/src/test/java/TankTest.java index 71621de..f74ca5d 100644 --- a/src/test/java/TankTest.java +++ b/src/test/java/TankTest.java @@ -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 = 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(); + } + } } \ No newline at end of file