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
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);
}
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 java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.stream.Stream;
@ -29,5 +32,27 @@ class PlayerManagerTest {
Arguments.of("PlayerWithNameInListReturnPlayerInList", List.of(new Player("Steffen", 40), 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