Browse Source

player_management: selectPlayer adds new players to player-list

Tobias Krause 3 years ago
committed by Lorenz Hohmann
parent
commit
4cf45ae7fb
  1. 6
      src/main/java/de/tims/player_management/PlayerManager.java
  2. 38
      src/test/java/de/tims/player_management/PlayerManagerTest.java

6
src/main/java/de/tims/player_management/PlayerManager.java

@ -27,7 +27,11 @@ public class PlayerManager {
}
}
return new Player(playerName, 0);
Player newPlayer = new Player(playerName, 0);
players.add(newPlayer);
return newPlayer;
}
public void loadPlayers(String fileName) {

38
src/test/java/de/tims/player_management/PlayerManagerTest.java

@ -5,9 +5,11 @@ import static org.assertj.core.api.Assertions.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@ -25,11 +27,11 @@ class PlayerManagerTest {
}
private static Stream<Arguments> testCasesForSelectPlayer() {
return Stream.of(Arguments.of("NoPlayersYetReturnNewPlayer", List.of(),
return Stream.of(Arguments.of("NoPlayersYetReturnNewPlayer", new LinkedList<Player>(List.of()),
"Tobias", new Player("Tobias", 0)),
Arguments.of("NoPlayerWithNameInListReturnNewPlayer", List.of(new Player("Steffen", 40), new Player("Lorenz", 60)),
Arguments.of("NoPlayerWithNameInListReturnNewPlayer", new LinkedList<Player>(List.of(new Player("Steffen", 40), new Player("Lorenz", 60))),
"Tobias", new Player("Tobias", 0)),
Arguments.of("PlayerWithNameInListReturnPlayerInList", List.of(new Player("Steffen", 40), new Player("Tobias", 50)),
Arguments.of("PlayerWithNameInListReturnPlayerInList", new LinkedList<Player>(List.of(new Player("Steffen", 40), new Player("Tobias", 50))),
"Tobias", new Player("Tobias", 50)));
}
@ -75,4 +77,34 @@ class PlayerManagerTest {
List.of(new Player("Tobias", 50), new Player("Steffen", 60))));
}
@Test
void selectPlayerAddsNewPlayersToList() {
LinkedList<Player> players = new LinkedList<Player>();
players.add(new Player("Steffen", 40));
players.add(new Player("Max", 60));
manager.setPlayers(players);
manager.selectPlayer("Tobias");
List<Player> expectedResult = List.of(new Player("Steffen", 40), new Player("Max", 60), new Player("Tobias", 0));
List<Player> calculatedResult = manager.getPlayers();
assertThat(calculatedResult).describedAs("SelectNewPlayerAddsNewPlayerToPlayersList").isEqualTo(expectedResult);
}
@Test
void selectExistingPlayerDoesntChangeTheList() {
LinkedList<Player> players = new LinkedList<Player>();
players.add(new Player("Steffen", 40));
players.add(new Player("Max", 60));
manager.setPlayers(players);
manager.selectPlayer("Max");
List<Player> expectedResult = List.of(new Player("Steffen", 40), new Player("Max", 60));
List<Player> calculatedResult = manager.getPlayers();
assertThat(calculatedResult).describedAs("SelectNewPlayerAddsNewPlayerToPlayersList").isEqualTo(expectedResult);
}
}
Loading…
Cancel
Save