From 4d69cc3e7609f2c9fdf4f3b43baa142144351c69 Mon Sep 17 00:00:00 2001 From: Lorenz Hohmann Date: Sat, 15 Jan 2022 14:46:46 +0100 Subject: [PATCH] Added test case when field was already shot (expect false) --- src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java | 3 +++ .../java/de/tims/fleetstorm/matchfield/CoordinateTest.java | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java b/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java index c3d3394..aeebdbf 100644 --- a/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java +++ b/src/main/java/de/tims/fleetstorm/matchfield/Coordinate.java @@ -45,6 +45,9 @@ public class Coordinate { } public boolean shoot() { + if (this.state == Coordinate.SHOT) + return false; + if (this.state == Coordinate.SHIP) { this.state = Coordinate.HIT; return true; diff --git a/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java b/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java index fd4b73e..779e432 100644 --- a/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java +++ b/src/test/java/de/tims/fleetstorm/matchfield/CoordinateTest.java @@ -1,6 +1,7 @@ package de.tims.fleetstorm.matchfield; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -74,6 +75,7 @@ class CoordinateTest { matchfield.setShip(new Coordinate(3, 3), 4, 1); assertTrue(matchfield.getField(0, 0).shoot()); + assertFalse(matchfield.getField(0, 0).shoot()); } }