From f12101901139a270a76ab11e77622957c0dc5875 Mon Sep 17 00:00:00 2001 From: Max Wenzel Date: Fri, 14 Jan 2022 10:31:14 +0100 Subject: [PATCH] Refactoring: boolean foundShip is private now --- src/main/java/de/tims/fleetstorm/ai/Logic.java | 11 ++++++++++- src/test/java/de/tims/fleetstorm/ai/LogicTest.java | 9 ++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/tims/fleetstorm/ai/Logic.java b/src/main/java/de/tims/fleetstorm/ai/Logic.java index 76e29f8..e6838d4 100644 --- a/src/main/java/de/tims/fleetstorm/ai/Logic.java +++ b/src/main/java/de/tims/fleetstorm/ai/Logic.java @@ -10,7 +10,7 @@ public class Logic { private Matchfield matchfield; private Coordinate lastShot; - public boolean foundShip = false; + private boolean foundShip = false; public Coordinate chooseField() { ArrayList possibleFields = new ArrayList(); @@ -66,4 +66,13 @@ public class Logic { System.out.println("Do this"); } + public void setFoundShip(boolean b) { + this.foundShip = b; + } + + public boolean getFoundShip() { + // TODO Auto-generated method stub + return this.foundShip; + } + } diff --git a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java index f266a76..c0b7f08 100644 --- a/src/test/java/de/tims/fleetstorm/ai/LogicTest.java +++ b/src/test/java/de/tims/fleetstorm/ai/LogicTest.java @@ -114,7 +114,14 @@ class LogicTest { logic.setLastShot(new Coordinate(2, 2)); logic.getLastShot().setState(Coordinate.HIT); logic.findShip(); - assertEquals(logic.foundShip, true); + assertEquals(logic.getFoundShip(), true); + } + + @Test + void testGetAndsetFoundShip() { + Logic logic = new Logic(); + logic.setFoundShip(true); + assertEquals(logic.getFoundShip(), true); } }