|
|
@ -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())); |
|
|
|
} |
|
|
|
|
|
|
|
} |