Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
bertalanaron committed May 16, 2024
2 parents ac187d3 + c37d50c commit 34281d1
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 2 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
53 changes: 52 additions & 1 deletion src/test/java/SaboteurTest.java
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);
}
}
}
108 changes: 107 additions & 1 deletion src/test/java/TankTest.java
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();
}
}
}

0 comments on commit 34281d1

Please sign in to comment.