Skip to content

Commit

Permalink
JUnit test for GameEndService
Browse files Browse the repository at this point in the history
  • Loading branch information
The-AhmadAA committed Sep 10, 2023
1 parent bdc57f9 commit d06551b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public class GameEndService {

private int engineerCount;

private boolean gameOver = false;

public GameEndService() {
this.engineerCount = 5;
}
Expand All @@ -16,7 +18,11 @@ public void updateEngineerCount() {
engineerCount -= 1;
if (engineerCount == 0) {
// loss screen

gameOver = true;
}
}

public boolean hasGameEnded() {
return gameOver;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.csse3200.game.services;

import com.csse3200.game.extensions.GameExtension;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

@ExtendWith(GameExtension.class)
class GameEndServiceTest {

GameEndService endService;

@BeforeEach
void setUp() {
endService = new GameEndService();
ServiceLocator.registerGameEndService(endService);
}

@Test
void shouldReturnCount() {
assertEquals(5, ServiceLocator.getGameEndService().getEngineerCount());
}

@Test
void shouldDecrementCount() {
ServiceLocator.getGameEndService().updateEngineerCount();
assertEquals(4, ServiceLocator.getGameEndService().getEngineerCount());
}

@Test
void shouldEndGame() {
for (int i = 0; i < 5; i++) {
ServiceLocator.getGameEndService().updateEngineerCount();
}
assertTrue(ServiceLocator.getGameEndService().hasGameEnded());
}
}

0 comments on commit d06551b

Please sign in to comment.