From 40086a331fe724a46a677d8a8f5e6ac4ba9f1051 Mon Sep 17 00:00:00 2001 From: Janis Date: Tue, 31 Mar 2026 08:43:44 +0200 Subject: [PATCH] fix: improve TerminalUI coverage and make MoveCommand/ResetCommand immutable **TerminalUI Coverage Fix:** - Added explicit test for empty input case (lines 64-65 previously uncovered) - Test "TerminalUI should explicitly handle empty input by re-prompting" validates that multiple empty inputs are properly handled by re-prompting - UI module coverage improved to near-100% **MoveCommand Immutability (Anti-pattern Fix):** - Changed MoveCommand fields from var to val: moveResult, previousBoard, previousHistory, previousTurn - Changed ResetCommand fields from var to val: previousBoard, previousHistory, previousTurn - Updated GameEngine to use .copy() instead of direct mutation when updating command state (lines 88, 95, 103, 112) - Removed 3 edge-case tests that relied on command mutation (now impossible with immutable fields) **MoveCommand Immutability Tests:** - Added MoveCommandImmutabilityTest to verify: - Fields cannot be mutated after creation - equals/hashCode respect immutability invariant - .copy() creates new instances with updated values All tests pass; 100% core coverage maintained. Co-Authored-By: Claude Haiku 4.5 --- .idea/gradle.xml | 1 + .idea/scala_compiler.xml | 2 +- .../de/nowchess/chess/command/Command.scala | 14 ++-- .../de/nowchess/chess/engine/GameEngine.scala | 16 ++--- .../command/MoveCommandImmutabilityTest.scala | 65 +++++++++++++++++++ .../engine/GameEngineEdgeCasesTest.scala | 36 ---------- .../nowchess/ui/terminal/TerminalUITest.scala | 24 +++++++ 7 files changed, 106 insertions(+), 52 deletions(-) create mode 100644 modules/core/src/test/scala/de/nowchess/chess/command/MoveCommandImmutabilityTest.scala diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 4f4edba..f1d0a36 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -12,6 +12,7 @@ diff --git a/.idea/scala_compiler.xml b/.idea/scala_compiler.xml index 8db25d6..a0f8d4f 100644 --- a/.idea/scala_compiler.xml +++ b/.idea/scala_compiler.xml @@ -5,7 +5,7 @@