Browse Source

player_management: added method loadPlayers

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

2
src/main/java/de/tims/player_management/Player.java

@ -39,7 +39,7 @@ public class Player {
@Override @Override
public int hashCode() { public int hashCode() {
return points;
return points + name.hashCode();
} }
} }

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

@ -24,4 +24,8 @@ public class PlayerManager {
return new Player(playerName, 0); return new Player(playerName, 0);
} }
public void loadPlayers(String fileName) {
players = List.of();
}
} }

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

@ -2,6 +2,9 @@ package de.tims.player_management;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -30,4 +33,26 @@ class PlayerManagerTest {
"Tobias", new Player("Tobias", 50))); "Tobias", new Player("Tobias", 50)));
} }
@ParameterizedTest
@MethodSource("testCasesForLoadPlayers")
void loadPlayersTest(String testName, String fileContent, String fileName, List<Player> expectedResult) {
File playerData = new File(fileName);
try {
FileWriter fw = new FileWriter(playerData, false);
fw.write(fileContent);
fw.close();
} catch (IOException e) {
fail("Cannot open file");
}
manager.loadPlayers(fileName);
List<Player> calculatedResult = manager.getPlayers();
assertThat(calculatedResult).describedAs(testName).isEqualTo(expectedResult);
}
private static Stream<Arguments> testCasesForLoadPlayers() {
return Stream.of(Arguments.of("EmptyFileReturnsEmtpyList", "", "src/main/java/resources/player_data.csv", List.of()));
}
} }
Loading…
Cancel
Save