diff --git a/.gradle/8.14/executionHistory/executionHistory.bin b/.gradle/8.14/executionHistory/executionHistory.bin index 3497c161..1822e65e 100644 Binary files a/.gradle/8.14/executionHistory/executionHistory.bin and b/.gradle/8.14/executionHistory/executionHistory.bin differ diff --git a/.gradle/8.14/executionHistory/executionHistory.lock b/.gradle/8.14/executionHistory/executionHistory.lock index 12a812dc..7ce4ac52 100644 Binary files a/.gradle/8.14/executionHistory/executionHistory.lock and b/.gradle/8.14/executionHistory/executionHistory.lock differ diff --git a/.gradle/8.14/fileHashes/fileHashes.bin b/.gradle/8.14/fileHashes/fileHashes.bin index 593de86a..e5f38381 100644 Binary files a/.gradle/8.14/fileHashes/fileHashes.bin and b/.gradle/8.14/fileHashes/fileHashes.bin differ diff --git a/.gradle/8.14/fileHashes/fileHashes.lock b/.gradle/8.14/fileHashes/fileHashes.lock index ffde176c..f44e5128 100644 Binary files a/.gradle/8.14/fileHashes/fileHashes.lock and b/.gradle/8.14/fileHashes/fileHashes.lock differ diff --git a/.gradle/8.14/fileHashes/resourceHashesCache.bin b/.gradle/8.14/fileHashes/resourceHashesCache.bin index 2416311d..77cc7861 100644 Binary files a/.gradle/8.14/fileHashes/resourceHashesCache.bin and b/.gradle/8.14/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index aa759ee6..ec28e392 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index 92155b57..c1eb5ca4 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/build/classes/java/main/hhn/temp/project/AssignmentManager.class b/build/classes/java/main/hhn/temp/project/AssignmentManager.class index 118b4b11..4749de0a 100644 Binary files a/build/classes/java/main/hhn/temp/project/AssignmentManager.class and b/build/classes/java/main/hhn/temp/project/AssignmentManager.class differ diff --git a/build/classes/java/test/hhn/temp/project/GoodCasesTest.class b/build/classes/java/test/hhn/temp/project/GoodCasesTest.class index 76246c73..1b0eb457 100644 Binary files a/build/classes/java/test/hhn/temp/project/GoodCasesTest.class and b/build/classes/java/test/hhn/temp/project/GoodCasesTest.class differ diff --git a/build/jacoco/test.exec b/build/jacoco/test.exec index 9c7dda03..44afc237 100644 Binary files a/build/jacoco/test.exec and b/build/jacoco/test.exec differ diff --git a/build/reports/problems/problems-report.html b/build/reports/problems/problems-report.html index 532e5406..615d6f90 100644 --- a/build/reports/problems/problems-report.html +++ b/build/reports/problems/problems-report.html @@ -650,7 +650,7 @@ code + .copy-button { diff --git a/build/reports/tests/test/classes/hhn.temp.project.BadCasesTest.html b/build/reports/tests/test/classes/hhn.temp.project.BadCasesTest.html index f736b509..2e827fd4 100644 --- a/build/reports/tests/test/classes/hhn.temp.project.BadCasesTest.html +++ b/build/reports/tests/test/classes/hhn.temp.project.BadCasesTest.html @@ -41,7 +41,7 @@
-
0.021s
+
0.016s

duration

@@ -87,7 +87,7 @@ Assert only existing tasks can be edited assertEditOnlyExistingTasks() -0.004s +0.003s passed @@ -99,19 +99,19 @@ Assert List isn't empty after adding a task assertListNowEmptyAfterAdd() -0.004s +0.002s passed Assert that added tasks can't be Null assertNewTasksAreNotNull() -0.003s +0.002s passed Assert that Remove Task is programmed defensively assertRemoveTaskOnlyAcceptsValidParameters() -0.002s +0.001s passed @@ -143,7 +143,7 @@ Generated by -Gradle 8.14 at 04.01.2026, 16:32:20

+Gradle 8.14 at 06.01.2026, 19:34:44

diff --git a/build/reports/tests/test/classes/hhn.temp.project.GoodCasesTest.html b/build/reports/tests/test/classes/hhn.temp.project.GoodCasesTest.html index 34111ba9..853b19ce 100644 --- a/build/reports/tests/test/classes/hhn.temp.project.GoodCasesTest.html +++ b/build/reports/tests/test/classes/hhn.temp.project.GoodCasesTest.html @@ -29,7 +29,7 @@
-
2
+
1

failures

@@ -41,7 +41,7 @@
-
0.051s
+
0.085s

duration

@@ -51,7 +51,7 @@
-
84%
+
92%

successful

@@ -73,24 +73,6 @@

Failed tests

- -

Check that editing is possible through UI

- -
org.opentest4j.AssertionFailedError: expected: <Walk> but was: <Run>
-	at app//org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
-	at app//org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
-	at app//org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
-	at app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
-	at app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
-	at app//org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1141)
-	at app//hhn.temp.project.GoodCasesTest.assertEditingTasksIsPossibleThroughUi(GoodCasesTest.java:133)
-	at java.base@17.0.2/java.lang.reflect.Method.invoke(Method.java:568)
-	at java.base@17.0.2/java.util.ArrayList.forEach(ArrayList.java:1511)
-	at java.base@17.0.2/java.util.ArrayList.forEach(ArrayList.java:1511)
-
-
-
-

Assert that removing a worker removes the worker from the worker list

@@ -121,7 +103,7 @@ Check that every required surface command actually works assertCommandsAreRecognized() -0.004s +0.017s passed @@ -131,51 +113,51 @@ passed -Check that editing is possible through UI -assertEditingTasksIsPossibleThroughUi() -0.008s -failed +Check that editing is possible through UI +assertEditingTasksIsPossibleThroughUi() +0.014s +passed Assert existing Tasks can be edited assertExistingTasksCanBeEdited() -0.003s +0.001s passed Check that every task command works assertFinishingTasksIsPossibleThroughUi() -0.005s +0.008s passed Check Getters assertGettersWorkCorrectly() -0.014s +0.019s passed Assert that removing a worker removes the worker from the worker list assertRemoveWorkerActuallyRemoves() -0.005s +0.012s failed Assert that removing Workers is possible through the UI assertRemovingWorkersIsPossibleThroughUI() -0.002s +0.005s passed Assert that the Scanner is actually started when AM calls start assertScannerExists() -0.002s +0.001s passed Assert that Task State is actually changed when submitted as finished assertTaskStateChanges() -0.004s +0.002s passed @@ -187,7 +169,7 @@ Assert that a Worker can add a Task assertWorkerCanAddTask() -0.001s +0.003s passed @@ -201,35 +183,74 @@

Standard output

-
Enter task ID: Error: Cannot invoke "java.util.Scanner.nextLine()" because "this.scanner" is null
-Enter new name;description: Error: Cannot invoke "java.util.Scanner.nextLine()" because "this.scanner" is null
-Unknown command. Type 'help' for available commands.
-Available commands:
-  createWorker  - Create a new worker
-  createTask    - Create a new task
-  selectTask    - Select a task to work with
-  listWorkers   - List all workers
-  help/?        - Show this help
-  exit          - Exit the program
-Available commands:
-  createWorker  - Create a new worker
-  createTask    - Create a new task
-  selectTask    - Select a task to work with
-  listWorkers   - List all workers
-  help/?        - Show this help
-  exit          - Exit the program
-Enter worker name: Error: Cannot invoke "java.util.Scanner.nextLine()" because "this.scanner" is null
-Enter worker ID: Error: Cannot invoke "java.util.Scanner.nextLine()" because "this.scanner" is null
-Enter task ID: Error: Cannot invoke "java.util.Scanner.nextLine()" because "this.scanner" is null
-Unknown command. Type 'help' for available commands.
-Unknown command. Type 'help' for available commands.
-Enter task ID: Error: Cannot invoke "java.util.Scanner.nextLine()" because "this.scanner" is null
+
Enter task ID:
+Task 1 (Run) selected
+Commands: finish, unfinish, remove, edit, back
+Enter new name;description:
+Task edited
+=== Available Commands ===
+General:
+  help, ? - Show this help
+  exit - Exit the program
+  listworkers - List all workers and select one
+  selecttask - Select a task by ID
+  createtask - Create a new task
+  createworker - Create a new worker
+  listtasks - List all tasks
+  listunfinished - List unfinished tasks
+  listfinished - List finished tasks
+
+When a task is selected:
+  finish - Mark task as finished
+  unfinish - Mark task as unfinished
+  remove - Remove the task
+  edit - Edit task name and description
+  back - Return to main menu
+
+When a worker is selected:
+  remove - Remove the worker
+  back - Return to main menu
+=== Available Commands ===
+General:
+  help, ? - Show this help
+  exit - Exit the program
+  listworkers - List all workers and select one
+  selecttask - Select a task by ID
+  createtask - Create a new task
+  createworker - Create a new worker
+  listtasks - List all tasks
+  listunfinished - List unfinished tasks
+  listfinished - List finished tasks
+
+When a task is selected:
+  finish - Mark task as finished
+  unfinish - Mark task as unfinished
+  remove - Remove the task
+  edit - Edit task name and description
+  back - Return to main menu
+
+When a worker is selected:
+  remove - Remove the worker
+  back - Return to main menu
+Enter worker name:
+Created worker with ID: 1
+Enter task ID:
+Invalid input. Please enter a task ID or 'back':
+Invalid input. Please enter a task ID or 'back':
+Enter task ID:
+Task 1 (Run) selected
+Commands: finish, unfinish, remove, edit, back
 Task marked as finished
 Task marked as unfinished
 Task removed
 Unknown command. Type 'help' for available commands.
 Unknown command. Type 'help' for available commands.
-Enter worker ID: Error: Cannot invoke "java.util.Scanner.nextLine()" because "this.scanner" is null
+Available workers:
+  1: Alfred
+  2: Balfred
+Enter worker ID to select (or 'back'):
+Worker 1 (Alfred) selected
+Commands: remove, back
 Worker removed
 Unknown command. Type 'help' for available commands.
 Unknown command. Type 'help' for available commands.
@@ -244,7 +265,7 @@ Unknown command. Type 'help' for available commands.
 
 
 
Generated by -Gradle 8.14 at 04.01.2026, 16:32:20

+Gradle 8.14 at 06.01.2026, 19:34:44

diff --git a/build/reports/tests/test/index.html b/build/reports/tests/test/index.html index ac37d130..f5786cff 100644 --- a/build/reports/tests/test/index.html +++ b/build/reports/tests/test/index.html @@ -26,7 +26,7 @@
-
5
+
4

failures

@@ -38,7 +38,7 @@
-
1.810s
+
1.063s

duration

@@ -48,7 +48,7 @@
-
80%
+
84%

successful

@@ -84,10 +84,6 @@
  • GoodCasesTest. -Check that editing is possible through UI -
  • -
  • -GoodCasesTest. Assert that removing a worker removes the worker from the worker list
  • @@ -111,10 +107,10 @@ hhn.temp.project 25 -5 +4 0 -1.810s -80% +1.063s +84% @@ -140,7 +136,7 @@ 8 0 0 -0.021s +0.016s 100% @@ -150,7 +146,7 @@ 1 0 0 -0.027s +0.070s 100% @@ -160,7 +156,7 @@ 3 3 0 -1.711s +0.892s 0% @@ -168,10 +164,10 @@ hhn.temp.project.GoodCasesTest 13 -2 +1 0 -0.051s -84% +0.085s +92% @@ -184,7 +180,7 @@ Generated by -Gradle 8.14 at 04.01.2026, 16:32:20

    +Gradle 8.14 at 06.01.2026, 19:34:44

    diff --git a/build/reports/tests/test/packages/hhn.temp.project.html b/build/reports/tests/test/packages/hhn.temp.project.html index 0b27113d..b3490be6 100644 --- a/build/reports/tests/test/packages/hhn.temp.project.html +++ b/build/reports/tests/test/packages/hhn.temp.project.html @@ -28,7 +28,7 @@
    -
    5
    +
    4

    failures

    @@ -40,7 +40,7 @@
    -
    1.810s
    +
    1.063s

    duration

    @@ -50,7 +50,7 @@
    -
    80%
    +
    84%

    successful

    @@ -83,10 +83,6 @@
  • GoodCasesTest. -Check that editing is possible through UI -
  • -
  • -GoodCasesTest. Assert that removing a worker removes the worker from the worker list
  • @@ -111,7 +107,7 @@ 8 0 0 -0.021s +0.016s 100% @@ -121,7 +117,7 @@ 1 0 0 -0.027s +0.070s 100% @@ -131,7 +127,7 @@ 3 3 0 -1.711s +0.892s 0% @@ -139,10 +135,10 @@ GoodCasesTest 13 -2 +1 0 -0.051s -84% +0.085s +92% @@ -154,7 +150,7 @@ Generated by -Gradle 8.14 at 04.01.2026, 16:32:20

    +Gradle 8.14 at 06.01.2026, 19:34:44

    diff --git a/build/test-results/test/TEST-hhn.temp.project.BadCasesTest.xml b/build/test-results/test/TEST-hhn.temp.project.BadCasesTest.xml index 2715170c..9f98525e 100644 --- a/build/test-results/test/TEST-hhn.temp.project.BadCasesTest.xml +++ b/build/test-results/test/TEST-hhn.temp.project.BadCasesTest.xml @@ -1,14 +1,14 @@ - + - + - + - + - + diff --git a/build/test-results/test/TEST-hhn.temp.project.GoodCasesTest.xml b/build/test-results/test/TEST-hhn.temp.project.GoodCasesTest.xml index 28baa303..68e169e9 100644 --- a/build/test-results/test/TEST-hhn.temp.project.GoodCasesTest.xml +++ b/build/test-results/test/TEST-hhn.temp.project.GoodCasesTest.xml @@ -1,29 +1,16 @@ - + - - - org.opentest4j.AssertionFailedError: expected: <Walk> but was: <Run> - at app//org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151) - at app//org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132) - at app//org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197) - at app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182) - at app//org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177) - at app//org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1141) - at app//hhn.temp.project.GoodCasesTest.assertEditingTasksIsPossibleThroughUi(GoodCasesTest.java:133) - at java.base@17.0.2/java.lang.reflect.Method.invoke(Method.java:568) - at java.base@17.0.2/java.util.ArrayList.forEach(ArrayList.java:1511) - at java.base@17.0.2/java.util.ArrayList.forEach(ArrayList.java:1511) - - - + + + - - - - - + + + + + org.opentest4j.AssertionFailedError: Expected java.lang.IllegalArgumentException to be thrown, but nothing was thrown. at app//org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:152) at app//org.junit.jupiter.api.AssertThrows.assertThrows(AssertThrows.java:73) @@ -35,38 +22,77 @@ at java.base@17.0.2/java.util.ArrayList.forEach(ArrayList.java:1511) - - + + - "); } @@ -89,73 +111,90 @@ public class UserCommands implements Runnable { } try { - if (inTaskSelection) { - handleTaskSelectionInput(input); - } else if (inWorkerSelection) { - handleWorkerSelectionInput(input); - } else { - handleMainMenuInput(input); + switch (currentState) { + case MAIN_MENU: + handleMainMenuInput(input); + break; + case TASK_SELECTED: + handleTaskSelectionInput(input); + break; + case WORKER_SELECTED: + handleWorkerSelectionInput(input); + break; + case AWAITING_EDIT_INPUT: + handleEditInput(input); + break; + case AWAITING_CREATE_TASK_WORKER: + handleCreateTaskWorkerInput(input); + break; + case AWAITING_CREATE_TASK_NAME: + handleCreateTaskNameInput(input); + break; + case AWAITING_CREATE_TASK_DESC: + handleCreateTaskDescInput(input); + break; + case AWAITING_CREATE_WORKER_NAME: + handleCreateWorkerNameInput(input); + break; + case AWAITING_TASK_SELECTION: + handleTaskIdInput(input); + break; } } catch (Exception e) { System.out.println("Error: " + e.getMessage()); + resetToMainMenu(); } } private void showHelp() { - if (inTaskSelection && selectedTaskId != null) { - System.out.println("Task commands:"); - System.out.println(" finish - Mark task as finished"); - System.out.println(" unfinish - Mark task as unfinished"); - System.out.println(" remove - Remove this task"); - System.out.println(" edit - Edit task (prompts for name;description)"); - System.out.println(" back - Return to main menu"); - } else if (inWorkerSelection && selectedWorkerId != null) { - System.out.println("Worker commands:"); - System.out.println(" remove - Remove this worker"); - System.out.println(" back - Return to main menu"); - } else { - System.out.println("Available commands:"); - System.out.println(" createWorker - Create a new worker"); - System.out.println(" createTask - Create a new task"); - System.out.println(" selectTask - Select a task to work with"); - System.out.println(" listWorkers - List all workers"); - System.out.println(" help/? - Show this help"); - System.out.println(" exit - Exit the program"); - } + System.out.println("=== Available Commands ==="); + System.out.println("General:"); + System.out.println(" help, ? - Show this help"); + System.out.println(" exit - Exit the program"); + System.out.println(" listworkers - List all workers and select one"); + System.out.println(" selecttask - Select a task by ID"); + System.out.println(" createtask - Create a new task"); + System.out.println(" createworker - Create a new worker"); + System.out.println(" listtasks - List all tasks"); + System.out.println(" listunfinished - List unfinished tasks"); + System.out.println(" listfinished - List finished tasks"); + + System.out.println("\nWhen a task is selected:"); + System.out.println(" finish - Mark task as finished"); + System.out.println(" unfinish - Mark task as unfinished"); + System.out.println(" remove - Remove the task"); + System.out.println(" edit - Edit task name and description"); + System.out.println(" back - Return to main menu"); + + System.out.println("\nWhen a worker is selected:"); + System.out.println(" remove - Remove the worker"); + System.out.println(" back - Return to main menu"); } private void handleMainMenuInput(String input) { switch (input.toLowerCase()) { case "createworker": - System.out.print("Enter worker name: "); - String workerName = scanner.nextLine().trim(); - int workerId = manager.createWorker(workerName); - System.out.println("Created worker with ID: " + workerId); + System.out.println("Enter worker name:"); + currentState = InputState.AWAITING_CREATE_WORKER_NAME; break; case "createtask": - System.out.print("Enter worker ID: "); - int workerIdForTask = Integer.parseInt(scanner.nextLine().trim()); - System.out.print("Enter task name: "); - String taskName = scanner.nextLine().trim(); - System.out.print("Enter task description: "); - String taskDesc = scanner.nextLine().trim(); - int taskId = manager.addTask(workerIdForTask, taskName, taskDesc); - System.out.println("Created task with ID: " + taskId); + System.out.println("Enter worker ID:"); + currentState = InputState.AWAITING_CREATE_TASK_WORKER; break; case "selecttask": - inTaskSelection = true; - System.out.print("Enter task ID: "); - String taskIdInput = scanner.nextLine().trim(); - selectedTaskId = Integer.parseInt(taskIdInput); + System.out.println("Enter task ID:"); + currentState = InputState.AWAITING_TASK_SELECTION; // Change to new state break; case "listworkers": - inWorkerSelection = true; - System.out.print("Enter worker ID: "); - String workerIdInput = scanner.nextLine().trim(); - selectedWorkerId = Integer.parseInt(workerIdInput); + System.out.println("Available workers:"); + for (Worker w : manager.getWorkerMap().values()) { + System.out.println(" " + w.getId() + ": " + w.getName()); + } + System.out.println("Enter worker ID to select (or 'back'):"); + currentState = InputState.WORKER_SELECTED; break; default: @@ -163,86 +202,187 @@ public class UserCommands implements Runnable { } } + private void handleWorkerSelectionInput(String input) { + if ("back".equalsIgnoreCase(input)) { + resetToMainMenu(); + return; + } + + try { + int workerId = Integer.parseInt(input.trim()); + Worker worker = manager.getWorker(workerId); + if (worker != null) { + selectedWorkerId = workerId; + System.out.println("Worker " + workerId + " (" + worker.getName() + ") selected"); + System.out.println("Commands: remove, back"); + } else { + System.out.println("Worker not found. Please enter a valid worker ID:"); + } + } catch (NumberFormatException e) { + if (selectedWorkerId != null) { + handleWorkerCommand(input); + } else { + System.out.println("Invalid input. Please enter a worker ID or 'back':"); + } + } + } + + private void handleWorkerCommand(String input) { + switch (input.toLowerCase()) { + case "remove": + manager.removeWorker(selectedWorkerId); + System.out.println("Worker removed"); + resetToMainMenu(); + break; + + case "back": + resetToMainMenu(); + break; + + default: + System.out.println("Unknown command. Available commands: remove, back"); + } + } + + private void handleCreateWorkerNameInput(String input) { + int workerId = manager.createWorker(input.trim()); + System.out.println("Created worker with ID: " + workerId); + resetToMainMenu(); + } + private void handleTaskIdInput(String input) { + if ("back".equalsIgnoreCase(input)) { + resetToMainMenu(); + return; + } + + try { + int taskId = Integer.parseInt(input.trim()); + Task task = manager.getTask(taskId); + if (task != null) { + selectedTaskId = taskId; + currentState = InputState.TASK_SELECTED; + System.out.println("Task " + taskId + " (" + task.getName() + ") selected"); + System.out.println("Commands: finish, unfinish, remove, edit, back"); + } else { + System.out.println("Task not found. Please enter a valid task ID:"); + } + } catch (NumberFormatException e) { + System.out.println("Invalid input. Please enter a task ID or 'back':"); + } + } + + + private void handleCreateTaskWorkerInput(String input) { + try { + tempWorkerId = Integer.parseInt(input.trim()); + System.out.println("Enter task name:"); + currentState = InputState.AWAITING_CREATE_TASK_NAME; + } catch (NumberFormatException e) { + System.out.println("Invalid worker ID. Please enter a number:"); + } + } + + private void handleCreateTaskNameInput(String input) { + tempTaskName = input.trim(); + System.out.println("Enter task description:"); + currentState = InputState.AWAITING_CREATE_TASK_DESC; + } + + private void handleCreateTaskDescInput(String input) { + int taskId = manager.addTask(tempWorkerId, tempTaskName, input.trim()); + System.out.println("Created task with ID: " + taskId); + resetToMainMenu(); + } + + private void resetToMainMenu() { + currentState = InputState.MAIN_MENU; + selectedTaskId = null; + selectedWorkerId = null; + tempWorkerId = null; + tempTaskName = null; + } + private void handleTaskSelectionInput(String input) { + if ("back".equalsIgnoreCase(input)) { + resetToMainMenu(); + return; + } + + try { + int taskId = Integer.parseInt(input.trim()); + Task task = manager.getTask(taskId); + if (task != null) { + selectedTaskId = taskId; + currentState = InputState.TASK_SELECTED; + System.out.println("Task " + taskId + " (" + task.getName() + ") selected"); + System.out.println("Commands: finish, unfinish, remove, edit, back"); + } else { + System.out.println("Task not found. Please enter a valid task ID:"); + } + } catch (NumberFormatException e) { + if (selectedTaskId != null) { + handleTaskCommand(input); + } else { + System.out.println("Invalid input. Please enter a task ID or 'back':"); + } + } + } + + private void handleTaskCommand(String input) { switch (input.toLowerCase()) { case "finish": - manager.finishTask(manager.getTask(selectedTaskId).getWorkerId(), selectedTaskId); + manager.finishTask(manager.getTask(selectedTaskId).getWorkerId(),selectedTaskId); System.out.println("Task marked as finished"); break; case "unfinish": - manager.unfinishTask(manager.getTask(selectedTaskId).getWorkerId(), selectedTaskId); + manager.unfinishTask(manager.getTask(selectedTaskId).getWorkerId(),selectedTaskId); System.out.println("Task marked as unfinished"); break; case "remove": manager.removeTask(selectedTaskId); System.out.println("Task removed"); - resetSelection(); + resetToMainMenu(); break; case "edit": - System.out.print("Enter new name;description: "); - String editInput = scanner.nextLine().trim(); - String[] parts = editInput.split(";", 2); - if (parts.length == 2) { - manager.editTask(manager.getTask(selectedTaskId).getWorkerId(),selectedTaskId,parts[0],parts[1]); - System.out.println("Task edited"); - } else { - System.out.println("Invalid format. Use: name;description"); - } + System.out.println("Enter new name;description:"); + currentState = InputState.AWAITING_EDIT_INPUT; break; case "back": - resetSelection(); + resetToMainMenu(); break; default: - try { - selectedTaskId = Integer.parseInt(input); - } catch (NumberFormatException e) { - System.out.println("Unknown command. Type 'help' for available commands."); - } + System.out.println("Unknown command. Type 'help' for available commands."); } } - private void handleWorkerSelectionInput(String input) { - switch (input.toLowerCase()) { - case "remove": - manager.removeWorker(selectedWorkerId); - System.out.println("Worker removed"); - resetSelection(); - break; - - case "back": - resetSelection(); - break; - - default: - try { - selectedWorkerId = Integer.parseInt(input); - } catch (NumberFormatException e) { - System.out.println("Unknown command. Type 'help' for available commands."); - } + private void handleEditInput(String input) { + String[] parts = input.split(";", 2); + if (parts.length == 2) { + manager.editTask(manager.getTask(selectedTaskId).getWorkerId(), selectedTaskId, parts[0], parts[1]); + System.out.println("Task edited"); + } else { + System.out.println("Invalid format. Use: name;description"); + System.out.println("Please try again:"); + return; } - } - - private void resetSelection() { - inTaskSelection = false; - inWorkerSelection = false; - selectedTaskId = null; - selectedWorkerId = null; + currentState = InputState.TASK_SELECTED; } public Scanner getScanner() { return scanner; } - // For testing - allows setting scanner + //only for testing public void setScanner(Scanner scanner) { this.scanner = scanner; } + //only for testing public boolean isRunning() { return running.get(); } diff --git a/test/hhn/temp/project/GoodCasesTest.java b/test/hhn/temp/project/GoodCasesTest.java index 3dabeaf9..6f9cd642 100644 --- a/test/hhn/temp/project/GoodCasesTest.java +++ b/test/hhn/temp/project/GoodCasesTest.java @@ -129,10 +129,10 @@ public class GoodCasesTest { manager.getUserCommands().handleInput("selectTask"); manager.getUserCommands().handleInput(taskId + ""); manager.getUserCommands().handleInput("edit"); - assertDoesNotThrow(() -> manager.getUserCommands().handleInput("Walk;Walk 3 Miles")); + manager.getUserCommands().handleInput("Walk;Walk 3 Miles"); assertEquals("Walk", manager.getTask(taskId).getName()); assertEquals("Walk 3 Miles", manager.getTask(taskId).getDescription()); - assertDoesNotThrow(() -> manager.getUserCommands().handleInput("back")); + manager.getUserCommands().handleInput("back"); } @Test @DisplayName("Assert that removing Workers is possible through the UI")