From c16ddc6bca0620187744aba4a680f4ef0f6fd398 Mon Sep 17 00:00:00 2001 From: MikeZyeman Date: Fri, 10 Dec 2021 19:55:22 +0100 Subject: [PATCH] Redo if statement with exception throwing --- src/ch/zhaw/catan/SiedlerGame.java | 3 +++ test/ch/zhaw/catan/SiedlerGameTest.java | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index fcf3534..eff8ac0 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -32,6 +32,9 @@ public class SiedlerGame { * or players is not between two and four */ public SiedlerGame(int winPoints, int numberOfPlayers) { + if (winPoints < 3 || numberOfPlayers < Config.MIN_NUMBER_OF_PLAYERS || numberOfPlayers > 4) { + throw new IllegalArgumentException(); + } bank = new Bank(); board = new SiedlerBoard(); board.createFixGameField(); diff --git a/test/ch/zhaw/catan/SiedlerGameTest.java b/test/ch/zhaw/catan/SiedlerGameTest.java index eea1873..42a68ee 100644 --- a/test/ch/zhaw/catan/SiedlerGameTest.java +++ b/test/ch/zhaw/catan/SiedlerGameTest.java @@ -152,7 +152,6 @@ public class SiedlerGameTest { @Test @DisplayName("Starting Siedler game with one player, expects fail") public void startSiedlerGameWithLowerThanMinimumWinPoints() { - Exception exc = assertThrows(IllegalArgumentException.class, () -> { SiedlerGame game = new SiedlerGame(1, 4); });