diff --git a/.gradle/8.14/executionHistory/executionHistory.bin b/.gradle/8.14/executionHistory/executionHistory.bin index 712f219d..6a5210f0 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 1d725e3a..3353b4ae 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 f742fd64..6d7b787e 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 44e7aed2..e12de6f6 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 216adf20..8dcf4d23 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 dada4118..56923cab 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 a629a9b1..92155b57 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 bb150d04..18bb7804 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/jacoco/test.exec b/build/jacoco/test.exec index 9be5ca14..c914d072 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 95604b4d..532e5406 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 8a5844f8..97b7f9a7 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.017s
+
0.096s

duration

@@ -63,6 +63,9 @@
  • Tests
  • +
  • +Standard output +
  • Tests

    @@ -78,7 +81,7 @@ Assert Add Task is programmed defensively assertAddTaskOnlyAcceptsValidParameters() -0.003s +0.007s passed @@ -90,31 +93,31 @@ Assert non-existent commands are recognized as such assertInvalidCommandsDontCrash() -0s +0.015s passed Assert List isn't empty after adding a task assertListNowEmptyAfterAdd() -0.002s +0.045s passed Assert that added tasks can't be Null assertNewTasksAreNotNull() -0.002s +0.003s passed Assert that Remove Task is programmed defensively assertRemoveTaskOnlyAcceptsValidParameters() -0.002s +0.014s passed Assert that removing a non-existent worker throws an Exception assertRemovingNonExistentWorkerFails() -0.002s +0.006s passed @@ -125,6 +128,13 @@
    +
    +

    Standard output

    + +
    Unknown command. Type 'help' for available commands.
    +
    +
    +
    Generated by -Gradle 8.14 at 04.01.2026, 15:20:17

    +Gradle 8.14 at 04.01.2026, 16:08:46

    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 b88b9466..0ed2f764 100644 --- a/build/reports/tests/test/classes/hhn.temp.project.GoodCasesTest.html +++ b/build/reports/tests/test/classes/hhn.temp.project.GoodCasesTest.html @@ -41,7 +41,7 @@
    -
    0.133s
    +
    0.083s

    duration

    @@ -66,6 +66,9 @@
  • Tests
  • +
  • +Standard output +
  • Failed tests

    @@ -118,7 +121,7 @@ Check that every required surface command actually works assertCommandsAreRecognized() -0.014s +0.012s passed @@ -130,7 +133,7 @@ Check that editing is possible through UI assertEditingTasksIsPossibleThroughUi() -0.067s +0.026s failed @@ -142,43 +145,43 @@ Check that every task command works assertFinishingTasksIsPossibleThroughUi() -0.005s +0.006s passed Check Getters assertGettersWorkCorrectly() -0.026s +0.007s passed Assert that removing a worker removes the worker from the worker list assertRemoveWorkerActuallyRemoves() -0.004s +0.003s failed Assert that removing Workers is possible through the UI assertRemovingWorkersIsPossibleThroughUI() -0.003s +0.005s passed Assert that the Scanner is actually started when AM calls start assertScannerExists() -0.001s +0.002s passed Assert that Task State is actually changed when submitted as finished assertTaskStateChanges() -0.002s +0.011s passed Assert that added Tasks are added to the List assertTasksShowInList() -0.003s +0.002s passed @@ -190,11 +193,49 @@ Assert that Worker can remove Task assertWorkerCanRemoveOwnTask() -0.001s +0.002s passed
    +
    +

    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
    +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
    +Worker removed
    +Unknown command. Type 'help' for available commands.
    +Unknown command. Type 'help' for available commands.
    +
    +
    +
    Generated by -Gradle 8.14 at 04.01.2026, 15:20:17

    +Gradle 8.14 at 04.01.2026, 16:08:46

    diff --git a/build/reports/tests/test/index.html b/build/reports/tests/test/index.html index a413e1e1..5d1594bf 100644 --- a/build/reports/tests/test/index.html +++ b/build/reports/tests/test/index.html @@ -38,7 +38,7 @@
    -
    0.988s
    +
    0.911s

    duration

    @@ -113,7 +113,7 @@ 25 5 0 -0.988s +0.911s 80% @@ -140,7 +140,7 @@ 8 0 0 -0.017s +0.096s 100% @@ -150,7 +150,7 @@ 1 0 0 -0.739s +0.037s 100% @@ -160,7 +160,7 @@ 3 3 0 -0.099s +0.695s 0% @@ -170,7 +170,7 @@ 13 2 0 -0.133s +0.083s 84% @@ -184,7 +184,7 @@ Generated by -Gradle 8.14 at 04.01.2026, 15:20:17

    +Gradle 8.14 at 04.01.2026, 16:08:46

    diff --git a/build/reports/tests/test/packages/hhn.temp.project.html b/build/reports/tests/test/packages/hhn.temp.project.html index a9d8a356..eb358303 100644 --- a/build/reports/tests/test/packages/hhn.temp.project.html +++ b/build/reports/tests/test/packages/hhn.temp.project.html @@ -40,7 +40,7 @@
    -
    0.988s
    +
    0.911s

    duration

    @@ -111,7 +111,7 @@ 8 0 0 -0.017s +0.096s 100% @@ -121,7 +121,7 @@ 1 0 0 -0.739s +0.037s 100% @@ -131,7 +131,7 @@ 3 3 0 -0.099s +0.695s 0% @@ -141,7 +141,7 @@ 13 2 0 -0.133s +0.083s 84% @@ -154,7 +154,7 @@ Generated by -Gradle 8.14 at 04.01.2026, 15:20:17

    +Gradle 8.14 at 04.01.2026, 16:08:46

    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 2800d73f..c500e876 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,15 @@ - + - - - - - + + + + + - - + + 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 a5443b83..ebcb5f4a 100644 --- a/build/test-results/test/TEST-hhn.temp.project.GoodCasesTest.xml +++ b/build/test-results/test/TEST-hhn.temp.project.GoodCasesTest.xml @@ -1,8 +1,8 @@ - + - - + + 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) @@ -16,14 +16,14 @@ 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,9 +35,41 @@ at java.base@17.0.2/java.util.ArrayList.forEach(ArrayList.java:1511) - - + + - + diff --git a/build/test-results/test/binary/results.bin b/build/test-results/test/binary/results.bin index bd0f2cb3..02748925 100644 Binary files a/build/test-results/test/binary/results.bin and b/build/test-results/test/binary/results.bin differ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index 8fdfc32c..4cb61a0d 100644 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/build/tmp/compileTestJava/compileTransaction/stash-dir/GoodCasesTest.class.uniqueId0 b/build/tmp/compileTestJava/compileTransaction/stash-dir/GoodCasesTest.class.uniqueId0 index 55ac4429..d33dc2b5 100644 Binary files a/build/tmp/compileTestJava/compileTransaction/stash-dir/GoodCasesTest.class.uniqueId0 and b/build/tmp/compileTestJava/compileTransaction/stash-dir/GoodCasesTest.class.uniqueId0 differ diff --git a/build/tmp/compileTestJava/previous-compilation-data.bin b/build/tmp/compileTestJava/previous-compilation-data.bin index 3a27f487..bcb2433d 100644 Binary files a/build/tmp/compileTestJava/previous-compilation-data.bin and b/build/tmp/compileTestJava/previous-compilation-data.bin differ diff --git a/src/main/java/hhn/temp/project/AssignmentManager.java b/src/main/java/hhn/temp/project/AssignmentManager.java index ed41652a..53a24a17 100644 --- a/src/main/java/hhn/temp/project/AssignmentManager.java +++ b/src/main/java/hhn/temp/project/AssignmentManager.java @@ -17,8 +17,7 @@ public class AssignmentManager { taskMap = new HashMap<>(); int workerIdCounter = 1000; int taskIdCounter = 0; - userInterface = new UserCommands(); - userInterface.start(); + userInterface = new UserCommands(this); } public int createWorker(String name) { @@ -80,5 +79,12 @@ public class AssignmentManager { public UserCommands getUserCommands() { return userInterface; } + public void startCLI() { + userInterface.start(); + } + + public void stopCLI() { + userInterface.stop(); + } } diff --git a/src/main/java/hhn/temp/project/UserCommands.java b/src/main/java/hhn/temp/project/UserCommands.java index c9abdf06..a5862043 100644 --- a/src/main/java/hhn/temp/project/UserCommands.java +++ b/src/main/java/hhn/temp/project/UserCommands.java @@ -1,24 +1,234 @@ package hhn.temp.project; import java.util.Scanner; +import java.util.concurrent.atomic.AtomicBoolean; + +public class UserCommands implements Runnable { + private Scanner scanner; + private AssignmentManager manager; + private boolean inTaskSelection = false; + private boolean inWorkerSelection = false; + private Integer selectedTaskId = null; + private Integer selectedWorkerId = null; + private AtomicBoolean running = new AtomicBoolean(false); + private Thread cliThread; + + public UserCommands(AssignmentManager manager) { + this.manager = manager; + } + + @Override + public void run() { + scanner = new Scanner(System.in); + running.set(true); + + while (running.get()) { + printPrompt(); + String input = scanner.nextLine().trim(); + + if ("exit".equalsIgnoreCase(input)) { + stop(); + continue; + } + + handleInput(input); + } + scanner.close(); + } -public class UserCommands { - Scanner scanner; public void start() { - boolean close = false; -// scanner = new Scanner(System.in); -// while (!close) { -// System.out.println("Type '?' or 'help' for a list of commands"); -// System.out.println("Please enter a command:"); -// String input = scanner.nextLine(); -// handleInput(input); -// } -// scanner.close(); + if (cliThread == null || !cliThread.isAlive()) { + cliThread = new Thread(this, "CLI-Thread"); + cliThread.start(); + } } - public void handleInput(String input) { + public void stop() { + running.set(false); + if (cliThread != null) { + cliThread.interrupt(); + } } + + private void printPrompt() { + if (!running.get()) return; + + if (inTaskSelection && selectedTaskId != null) { + System.out.println("Task " + selectedTaskId + " selected. Commands: finish, unfinish, remove, edit, back"); + } else if (inWorkerSelection && selectedWorkerId != null) { + System.out.println("Worker " + selectedWorkerId + " selected. Commands: remove, back"); + } else { + System.out.println("Type '?' or 'help' for a list of commands"); + } + System.out.print("> "); + } + + public void handleInput(String input) { + if (input == null || input.isEmpty()) { + return; + } + + if ("?".equals(input) || "help".equalsIgnoreCase(input)) { + showHelp(); + return; + } + + try { + if (inTaskSelection) { + handleTaskSelectionInput(input); + } else if (inWorkerSelection) { + handleWorkerSelectionInput(input); + } else { + handleMainMenuInput(input); + } + } catch (Exception e) { + System.out.println("Error: " + e.getMessage()); + } + } + + 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"); + } + } + + 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); + 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); + break; + + case "selecttask": + inTaskSelection = true; + System.out.print("Enter task ID: "); + String taskIdInput = scanner.nextLine().trim(); + selectedTaskId = Integer.parseInt(taskIdInput); + break; + + case "listworkers": + inWorkerSelection = true; + System.out.print("Enter worker ID: "); + String workerIdInput = scanner.nextLine().trim(); + selectedWorkerId = Integer.parseInt(workerIdInput); + break; + + default: + System.out.println("Unknown command. Type 'help' for available commands."); + } + } + + private void handleTaskSelectionInput(String input) { + switch (input.toLowerCase()) { + case "finish": + manager.finishTask(manager.getTask(selectedTaskId).getWorkerId(), selectedTaskId); + System.out.println("Task marked as finished"); + break; + + case "unfinish": + 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(); + 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"); + } + break; + + case "back": + resetSelection(); + break; + + default: + try { + selectedTaskId = Integer.parseInt(input); + } catch (NumberFormatException e) { + 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 resetSelection() { + inTaskSelection = false; + inWorkerSelection = false; + selectedTaskId = null; + selectedWorkerId = null; + } + public Scanner getScanner() { return scanner; } + + // For testing - allows setting scanner + public void setScanner(Scanner scanner) { + this.scanner = scanner; + } + + public boolean isRunning() { + return running.get(); + } }