import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.aggregator.AggregateWith; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.CsvFileSource; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.MethodSource; import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertEquals; public class BowlingCalculatorTest { @ParameterizedTest(name = "[{index}] {0} scores {2}") @MethodSource("playerResults") void test(String testName, String playerResult, int expectedScore) { BowlingGameCalculator bgc = new BowlingGameCalculator(); int calculatedScore = bgc.score(playerResult); assertEquals(expectedScore, calculatedScore, String.format("%s: %s", testName, playerResult)); } private static Stream playerResults() { return Stream.of(Arguments.of("worst game", "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", 0)); // 16x 0 } }