Browse Source

Implement choose Method

AIPlayer
Jonas Wagner 3 years ago
parent
commit
1aeb383f8c
  1. 10
      src/main/java/Player.java
  2. 18
      src/test/java/PlayerTest.java

10
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<Figure> 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;
}
}

18
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);
}
}
Loading…
Cancel
Save