Redo if statement with exception throwing

This commit is contained in:
MikeZyeman 2021-12-10 19:55:22 +01:00
parent 3049650bc4
commit c16ddc6bca
2 changed files with 3 additions and 1 deletions

View File

@ -32,6 +32,9 @@ public class SiedlerGame {
* or players is not between two and four * or players is not between two and four
*/ */
public SiedlerGame(int winPoints, int numberOfPlayers) { public SiedlerGame(int winPoints, int numberOfPlayers) {
if (winPoints < 3 || numberOfPlayers < Config.MIN_NUMBER_OF_PLAYERS || numberOfPlayers > 4) {
throw new IllegalArgumentException();
}
bank = new Bank(); bank = new Bank();
board = new SiedlerBoard(); board = new SiedlerBoard();
board.createFixGameField(); board.createFixGameField();

View File

@ -152,7 +152,6 @@ public class SiedlerGameTest {
@Test @Test
@DisplayName("Starting Siedler game with one player, expects fail") @DisplayName("Starting Siedler game with one player, expects fail")
public void startSiedlerGameWithLowerThanMinimumWinPoints() { public void startSiedlerGameWithLowerThanMinimumWinPoints() {
Exception exc = assertThrows(IllegalArgumentException.class, () -> { Exception exc = assertThrows(IllegalArgumentException.class, () -> {
SiedlerGame game = new SiedlerGame(1, 4); SiedlerGame game = new SiedlerGame(1, 4);
}); });