From 491b0a39b491e1702c5cf7aa65451decb9d603de Mon Sep 17 00:00:00 2001 From: marcomarrelli Date: Fri, 16 Feb 2024 16:31:05 +0100 Subject: [PATCH] Fixed All Remaining Gradlew Check Tests --- .../pvzclone/controller/api/Controller.java | 2 +- .../java/pvzclone/model/api/GameState.java | 2 +- .../java/pvzclone/model/impl/LevelImpl.java | 14 ++++++------- .../pvzclone/model/impl/LevelsManager.java | 4 ++++ src/main/java/pvzclone/model/impl/Pair.java | 4 ++-- .../java/pvzclone/view/impl/FieldCell.java | 16 +++++++++++---- .../pvzclone/view/impl/FieldCellListener.java | 6 +++--- .../java/pvzclone/view/impl/GamePanel.java | 20 +++++++++++-------- .../java/pvzclone/view/impl/LevelPanel.java | 2 +- .../java/pvzclone/view/impl/MenuPanel.java | 2 +- .../pvzclone/view/impl/SwingViewImpl.java | 2 +- src/test/java/pvzclone/LevelTest.java | 8 ++++---- 12 files changed, 49 insertions(+), 33 deletions(-) diff --git a/src/main/java/pvzclone/controller/api/Controller.java b/src/main/java/pvzclone/controller/api/Controller.java index f69a64f..ec0e0a7 100644 --- a/src/main/java/pvzclone/controller/api/Controller.java +++ b/src/main/java/pvzclone/controller/api/Controller.java @@ -51,7 +51,7 @@ public interface Controller { /** * Sets the number of the Level to the number of the argument passed. * - * @param numberOfTheLevel + * @param numberOfTheLevel level index. */ void chooseLevel(int numberOfTheLevel); diff --git a/src/main/java/pvzclone/model/api/GameState.java b/src/main/java/pvzclone/model/api/GameState.java index a138cce..375a101 100644 --- a/src/main/java/pvzclone/model/api/GameState.java +++ b/src/main/java/pvzclone/model/api/GameState.java @@ -47,7 +47,7 @@ public interface GameState { int getZombiesGenerated(); /** - * @return {@true} number of zombies killed is equals + * @return if number of zombies killed is equals * to the effective number to be killed. */ boolean areZombieAllKilled(); diff --git a/src/main/java/pvzclone/model/impl/LevelImpl.java b/src/main/java/pvzclone/model/impl/LevelImpl.java index 3f73ae3..8c64e39 100644 --- a/src/main/java/pvzclone/model/impl/LevelImpl.java +++ b/src/main/java/pvzclone/model/impl/LevelImpl.java @@ -40,7 +40,7 @@ public LevelImpl(final int zombieCount, final int zombieWaveCount, } /** - * @see {@link Level#getZombieCount()} + * @see Level#getZombieCount() */ @Override public int getZombieCount() { @@ -48,7 +48,7 @@ public int getZombieCount() { } /** - * @see {@link Level#getZombieWaveCount()} + * @see Level#getZombieWaveCount() */ @Override public int getZombieWaveCount() { @@ -56,7 +56,7 @@ public int getZombieWaveCount() { } /** - * @see {@link Level#getZombieCountInWave()} + * @see Level#getZombieCountInWave() */ @Override public int getZombieCountInWave() { @@ -64,7 +64,7 @@ public int getZombieCountInWave() { } /** - * @see {@link Level#getSunSpawnRate()} + * @see Level#getSunSpawnRate() */ @Override public long getSunSpawnRate() { @@ -72,7 +72,7 @@ public long getSunSpawnRate() { } /** - * @see {@link Level#getZombieSpawnRate()} + * @see Level#getZombieSpawnRate() */ @Override public long getZombieSpawnRate() { @@ -80,7 +80,7 @@ public long getZombieSpawnRate() { } /** - * @see {@link Level#getSunSpawnRateDecrementRange()} + * @see Level#getSunSpawnRateDecrementRange() */ @Override public long getSunSpawnRateDecrementRange() { @@ -88,7 +88,7 @@ public long getSunSpawnRateDecrementRange() { } /** - * @see {@link Level#getZombieSpawnRateDecrementRange()} + * @see Level#getZombieSpawnRateDecrementRange() */ @Override public long getZombieSpawnRateDecrementRange() { diff --git a/src/main/java/pvzclone/model/impl/LevelsManager.java b/src/main/java/pvzclone/model/impl/LevelsManager.java index cbfe155..0b0acd3 100644 --- a/src/main/java/pvzclone/model/impl/LevelsManager.java +++ b/src/main/java/pvzclone/model/impl/LevelsManager.java @@ -59,6 +59,10 @@ public int getLevelCount() { * @return the number of levels. */ public LevelImpl createLevel(final int delta) { + if (delta < 0 || delta >= MAX_LEVELS) { + throw new IllegalArgumentException("Invalid delta: '" + delta + "'!"); + } + return new LevelImpl( LevelsManager.ZOMBIE_COUNT + (LevelsManager.ZOMBIE_COUNT_STEP * delta), diff --git a/src/main/java/pvzclone/model/impl/Pair.java b/src/main/java/pvzclone/model/impl/Pair.java index 6e3c551..29d1e97 100644 --- a/src/main/java/pvzclone/model/impl/Pair.java +++ b/src/main/java/pvzclone/model/impl/Pair.java @@ -3,8 +3,8 @@ import java.util.Objects; /** - * A standard generic Pair, with getters, hashCode, equals, and toString - * well implemented. + * A standard generic Pair<X,Y>. + * It comprehends getters, hashCode, equals, and toString. * * @param first element type. * @param second element type. diff --git a/src/main/java/pvzclone/view/impl/FieldCell.java b/src/main/java/pvzclone/view/impl/FieldCell.java index 8aee175..1207b29 100644 --- a/src/main/java/pvzclone/view/impl/FieldCell.java +++ b/src/main/java/pvzclone/view/impl/FieldCell.java @@ -15,24 +15,32 @@ * The center of the cell is saved and its bounds will be calculated * using the constants declared inside {@link GamePanel} * - * @see {@link GamePanel} + * @see GamePanel * @author Marco Marrelli */ @SuppressFBWarnings(value = { "EI_EXPOSE_REP2" -}, justification = "parent is intended to be modified") +}, justification = "Parent is Intended to be Modified.") public class FieldCell extends JButton { private static final long serialVersionUID = 1234500005L; /** Cell Text Initializer, used for {@link JButton#JButton(String)}. */ public static final String CELL_TEXT_INITIALIZER = ""; - private final GamePanel parent; private final transient Pair coord; + private final transient Controller controller; + + /** The Game Panel (the parent). */ + private final GamePanel parent; + + /** The Color for the Hover on the Cell. */ private final Color hoverColor = new Color(225, 215, 235); + + /** The Border Settings for the Hover on the Cell. */ private final Border hoverBorder = new LineBorder(hoverColor, 3); + + /** If the Cell has a Plant or Not. */ private boolean hasPlant; - private final transient Controller controller; /** * Field Cell Constructor. diff --git a/src/main/java/pvzclone/view/impl/FieldCellListener.java b/src/main/java/pvzclone/view/impl/FieldCellListener.java index 4f22311..ec9fd50 100644 --- a/src/main/java/pvzclone/view/impl/FieldCellListener.java +++ b/src/main/java/pvzclone/view/impl/FieldCellListener.java @@ -8,7 +8,7 @@ /** * Mouse Event Listener for the {@link FieldCell} Component. * - * @see {@link FieldCell} + * @see FieldCell * @author Marco Marrelli */ @@ -29,14 +29,14 @@ public FieldCellListener(final FieldCell parent) { } /** - * @see {@link FieldCellListener#muouseReleased()} + * @see FieldCellListener#mouseReleased(MouseEvent) */ @Override public void mouseClicked(final MouseEvent e) { } /** - * @see {@link FieldCellListener#muouseReleased()} + * @see FieldCellListener#mouseReleased(MouseEvent) */ @Override public void mousePressed(final MouseEvent e) { diff --git a/src/main/java/pvzclone/view/impl/GamePanel.java b/src/main/java/pvzclone/view/impl/GamePanel.java index 76fc89d..7a69358 100644 --- a/src/main/java/pvzclone/view/impl/GamePanel.java +++ b/src/main/java/pvzclone/view/impl/GamePanel.java @@ -76,31 +76,35 @@ public final class GamePanel extends GenericPanel { private static final int SUN_ENTITY_WIDTH = 140; private static final int SUN_ENTITY_HEIGHT = 106; + private final transient Map entities = new HashMap<>(); + + private final transient Set>> images = new HashSet<>(); + + private final transient SwingViewImpl parent; + + private transient Pair scale; + /** Field Cell Width. */ public static final int CELL_WIDTH = X_OFFSET - X_MARGIN; /** Field Cell Height. */ public static final int CELL_HEIGHT = Y_OFFSET - Y_MARGIN; + /** Cell Matrix on the Game Field. */ private final FieldCell[][] fieldMatrix; + /** Show how many suns the player has. */ private final JLabel points; - private final transient Map entities = new HashMap<>(); - private final transient Set>> images = new HashSet<>(); - + /** Flag checking if the user is planting or not. */ private boolean userIsPlanting; - private final transient SwingViewImpl parent; - - private transient Pair scale; - /** * Game Panel Constructor. * * @param parent the application's view. * @param backgroundSource the background image source. - * @see {@link GenericPanel} + * @see GenericPanel */ public GamePanel(final SwingViewImpl parent, final String backgroundSource) { super(parent, backgroundSource); diff --git a/src/main/java/pvzclone/view/impl/LevelPanel.java b/src/main/java/pvzclone/view/impl/LevelPanel.java index 14b71b0..ace6d49 100644 --- a/src/main/java/pvzclone/view/impl/LevelPanel.java +++ b/src/main/java/pvzclone/view/impl/LevelPanel.java @@ -37,7 +37,7 @@ public class LevelPanel extends GenericPanel { * * @param parent the application's view. * @param backgroundSource the background image source. - * @see {@link GenericPanel} + * @see GenericPanel */ public LevelPanel(final SwingViewImpl parent, final String backgroundSource) { super(parent, backgroundSource); diff --git a/src/main/java/pvzclone/view/impl/MenuPanel.java b/src/main/java/pvzclone/view/impl/MenuPanel.java index d78567f..07243e2 100644 --- a/src/main/java/pvzclone/view/impl/MenuPanel.java +++ b/src/main/java/pvzclone/view/impl/MenuPanel.java @@ -38,7 +38,7 @@ public class MenuPanel extends GenericPanel { * * @param parent the application's view. * @param backgroundSource the background image source. - * @see {@link GenericPanel} + * @see GenericPanel */ public MenuPanel(final SwingViewImpl parent, final String backgroundSource) { super(parent, backgroundSource); diff --git a/src/main/java/pvzclone/view/impl/SwingViewImpl.java b/src/main/java/pvzclone/view/impl/SwingViewImpl.java index dc9185d..5c8b350 100644 --- a/src/main/java/pvzclone/view/impl/SwingViewImpl.java +++ b/src/main/java/pvzclone/view/impl/SwingViewImpl.java @@ -161,7 +161,7 @@ public String getSceneConstraint() { /** * Updates the View. * - * @see {@link pvzclone.view.impl.GenericPanel#paintComponents(java.awt.Graphics)} + * @see pvzclone.view.impl.GenericPanel#paintComponents(java.awt.Graphics) */ @Override public void update() { diff --git a/src/test/java/pvzclone/LevelTest.java b/src/test/java/pvzclone/LevelTest.java index 5c3b959..2568443 100644 --- a/src/test/java/pvzclone/LevelTest.java +++ b/src/test/java/pvzclone/LevelTest.java @@ -4,9 +4,9 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrowsExactly; +import static org.junit.jupiter.api.Assertions.assertTrue; -//import java.util.List; -//import java.util.ArrayList; +import java.util.ArrayList; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -40,7 +40,7 @@ void checkLevelGenerationLimits() { void checkCreatedLevel() { assertEquals(this.correctLevelManager.createLevel(0).getClass(), LevelImpl.class); - //assertThrowsExactly(IllegalArgumentException.class, () -> this.correctLevelManager.createLevel(-1)); + assertThrowsExactly(IllegalArgumentException.class, () -> this.correctLevelManager.createLevel(-1)); } @Test @@ -60,6 +60,6 @@ void checkLevelListGetter() { assertFalse(this.correctLevelManager.getLevelList().isEmpty()); assertEquals(this.correctLevelManager.getLevelList().size(), this.correctLevelManager.getLevelCount()); - //assertEquals(this.correctLevelManager.getLevelList().getClass(), ArrayList.class); + assertTrue(this.correctLevelManager.getLevelList() instanceof ArrayList); } }