From 1aeb383f8c567fe8a8cf844344235ae86eccd62b Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Tue, 1 Feb 2022 08:52:08 +0100 Subject: [PATCH] Implement choose Method --- src/main/java/Player.java | 10 ++++++++++ src/test/java/PlayerTest.java | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/main/java/Player.java b/src/main/java/Player.java index 0ed8bd6..091eb59 100644 --- a/src/main/java/Player.java +++ b/src/main/java/Player.java @@ -1,5 +1,7 @@ +import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; +import java.util.Scanner; public class Player { @@ -7,6 +9,7 @@ public class Player { ArrayList
figures; int startHome; int endHome; + Scanner scanner; public Player (String name, int startHome, int endHome) { this.name = name; @@ -50,4 +53,11 @@ public class Player { } return false; } + + public int choose() { + scanner = new Scanner(System.in); + System.out.println("Eingabe:"); + int input = scanner.nextInt(); + return input; + } } diff --git a/src/test/java/PlayerTest.java b/src/test/java/PlayerTest.java index 07a3033..d63631d 100644 --- a/src/test/java/PlayerTest.java +++ b/src/test/java/PlayerTest.java @@ -6,6 +6,10 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -172,4 +176,18 @@ public class PlayerTest { false) ); } + + @Test + void checkChooseMethod() { + + InputStream stdin = System.in; + System.setIn(new ByteArrayInputStream("0\n".getBytes())); + + int calculatedResult = p.choose(); + + System.setIn(stdin); + + int expectedResult = 0; + assertThat(calculatedResult).describedAs("Choose one Figure").isEqualTo(expectedResult); + } }