From fcd63455b493277f3b8f0c000597205003fc8270 Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 4 Jan 2023 02:32:28 +0100 Subject: [PATCH 01/19] refactor: Deleted the dot in front of "out" and "target" in .gitignore --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index a5d9a21..c15a9a2 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,6 @@ hs_err_pid* replay_pid* .DS_Store /.idea/ -/.out/ -/.target/ +/out/ +/target/ *.iml \ No newline at end of file From a9b5c0112a5d41f04cbd19d15b180d6d105c2f2e Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 4 Jan 2023 02:33:39 +0100 Subject: [PATCH 02/19] refactor: Changed the build method of the project in build-project.sh --- build-project.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-project.sh b/build-project.sh index 3891e04..6219802 100644 --- a/build-project.sh +++ b/build-project.sh @@ -1,3 +1,3 @@ mvn test -java src/main/java/org/example/Main.java \ No newline at end of file +mvn compile exec:java -Dexec.mainClass="org.example.Main" From 945fac0dfaa06a4c259a6ac60c4a61f52e04999f Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 4 Jan 2023 02:34:42 +0100 Subject: [PATCH 03/19] Added config files for the game with examples: - crafting.json - gameconfig.json - items.json - playerconfig.json --- src/main/resources/crafting.json | 3 +++ src/main/resources/gameconfig.json | 38 ++++++++++++++++++++++++++++ src/main/resources/items.json | 26 +++++++++++++++++++ src/main/resources/playerconfig.json | 17 +++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 src/main/resources/crafting.json create mode 100644 src/main/resources/gameconfig.json create mode 100644 src/main/resources/items.json create mode 100644 src/main/resources/playerconfig.json diff --git a/src/main/resources/crafting.json b/src/main/resources/crafting.json new file mode 100644 index 0000000..0e0dcd2 --- /dev/null +++ b/src/main/resources/crafting.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/src/main/resources/gameconfig.json b/src/main/resources/gameconfig.json new file mode 100644 index 0000000..a29ef19 --- /dev/null +++ b/src/main/resources/gameconfig.json @@ -0,0 +1,38 @@ +{ + "shopitems": [ + { + "name": "Holz", + "amount": 10, + "gold": 10 + }, + { + "name": "Heiliges Schwert der Engel", + "amount": 1, + "gold": 1000 + }, + { + "name": "Stein", + "amount": 5, + "gold": 100 + } + ], + "locations": [ + { + "name": "Wald", + "items": [ + "Holz", + "Stein" + ], + "mobs": [ + { + "name": "Big Foot", + "hp": 50, + "damage": "10-15", + "items": [ + "Fell" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/items.json b/src/main/resources/items.json new file mode 100644 index 0000000..85b3f26 --- /dev/null +++ b/src/main/resources/items.json @@ -0,0 +1,26 @@ +[ + { + "name": "Holz", + "damage": "1-3", + "crafting": true, + "durability": 1000 + }, + { + "name": "Heiliges Schwert der Engel", + "damage": "1000", + "crafting": false, + "durability": 1000 + }, + { + "name": "Stein", + "damage": "5-10", + "crafting": true, + "durability": 1000 + }, + { + "name": "Fell", + "damage": "0", + "crafting": true, + "durability": 1000 + } +] \ No newline at end of file diff --git a/src/main/resources/playerconfig.json b/src/main/resources/playerconfig.json new file mode 100644 index 0000000..1a2c55e --- /dev/null +++ b/src/main/resources/playerconfig.json @@ -0,0 +1,17 @@ +{ + "name": "null", + "gold": 0, + "hp": 10, + "currentLocation": "Wald", + "inventory": [ + { + "name": "Holz", + "amount": "5", + "durability": 1000 + },{ + "name": "Stein", + "amount": "5", + "durability": 1000 + } + ] +} \ No newline at end of file From 2aaef7f9039b06cdddde04985b9ee67f55f06a11 Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 4 Jan 2023 02:35:47 +0100 Subject: [PATCH 04/19] refactor: Changed the name of the package. org.example -> org.bitbiome --- build-project.sh | 2 +- pom.xml | 2 +- src/main/java/org/{example => bitbiome}/Main.java | 2 +- src/test/java/org/{example => bitbiome}/TestMain.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename src/main/java/org/{example => bitbiome}/Main.java (88%) rename src/test/java/org/{example => bitbiome}/TestMain.java (90%) diff --git a/build-project.sh b/build-project.sh index 6219802..46a589c 100644 --- a/build-project.sh +++ b/build-project.sh @@ -1,3 +1,3 @@ mvn test -mvn compile exec:java -Dexec.mainClass="org.example.Main" +mvn compile exec:java -Dexec.mainClass="org.bitbiome.Main" diff --git a/pom.xml b/pom.xml index 227f1c5..c155580 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.example + org.bitbiome BitBiome 1.0-SNAPSHOT diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/bitbiome/Main.java similarity index 88% rename from src/main/java/org/example/Main.java rename to src/main/java/org/bitbiome/Main.java index 0050cd6..99b078d 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/bitbiome/Main.java @@ -1,4 +1,4 @@ -package org.example; +package org.bitbiome; public class Main { diff --git a/src/test/java/org/example/TestMain.java b/src/test/java/org/bitbiome/TestMain.java similarity index 90% rename from src/test/java/org/example/TestMain.java rename to src/test/java/org/bitbiome/TestMain.java index 1417521..2535f2b 100644 --- a/src/test/java/org/example/TestMain.java +++ b/src/test/java/org/bitbiome/TestMain.java @@ -1,4 +1,4 @@ -package org.example; +package org.bitbiome; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; From 023a5185ccca7f12de53c851f7fdd457bfed2572 Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 4 Jan 2023 02:36:38 +0100 Subject: [PATCH 05/19] Added org.json library to project Version 20180130 --- pom.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pom.xml b/pom.xml index c155580..bd143b9 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,13 @@ test + + + org.json + json + 20180130 + + From 7d3da78ded538a758762f0acef608fdf029ce895 Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 4 Jan 2023 02:39:30 +0100 Subject: [PATCH 06/19] Added JSONParser.java to handle read and search for key events. --- src/main/java/org/bitbiome/JsonParser.java | 30 ++++++++++++++++++++++ src/main/java/org/bitbiome/Main.java | 7 ++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/bitbiome/JsonParser.java diff --git a/src/main/java/org/bitbiome/JsonParser.java b/src/main/java/org/bitbiome/JsonParser.java new file mode 100644 index 0000000..5852e7e --- /dev/null +++ b/src/main/java/org/bitbiome/JsonParser.java @@ -0,0 +1,30 @@ +package org.bitbiome; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.json.JSONTokener; + +import java.io.InputStream; + +public class JsonParser { + public static JSONObject getJSONObject(String fileName) { + String resourceName = "./../../" + fileName; + InputStream is = JsonParser.class.getResourceAsStream(resourceName); + if (is == null) { + throw new NullPointerException("Cannot find resource file " + resourceName); + } + + JSONTokener tokener = new JSONTokener(is); + JSONObject object = new JSONObject(tokener); + System.out.println("Name: " + object.getString("name")); + + System.out.println("Inventory: "); + JSONArray inventory = object.getJSONArray("inventory"); + + for (int i = 0; i < inventory.length(); i++) { + JSONObject invObj = inventory.getJSONObject(i); + System.out.println(" - " + invObj.getString("name")); + } + return object; + } +} diff --git a/src/main/java/org/bitbiome/Main.java b/src/main/java/org/bitbiome/Main.java index 99b078d..ceb58c8 100644 --- a/src/main/java/org/bitbiome/Main.java +++ b/src/main/java/org/bitbiome/Main.java @@ -1,10 +1,15 @@ package org.bitbiome; +import org.json.JSONObject; + +import java.util.Scanner; + public class Main { + private Scanner s = new Scanner(System.in); public static void main(String[] args) { - System.out.println("Hello World!"); + JSONObject playerConfig = JsonParser.getJSONObject("playerconfig.json"); } public static int getLucky() { return 7; From b93b246de1dcaff992190cb26ced7526b80c94dd Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 4 Jan 2023 02:39:58 +0100 Subject: [PATCH 07/19] Added CommandAPI interface This interface is importing one method "performCommand" in all future commands. performCommand has the following parameters: - scanner, Scanner --- src/main/java/org/bitbiome/commands/CommandAPI.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/java/org/bitbiome/commands/CommandAPI.java diff --git a/src/main/java/org/bitbiome/commands/CommandAPI.java b/src/main/java/org/bitbiome/commands/CommandAPI.java new file mode 100644 index 0000000..d3a67c6 --- /dev/null +++ b/src/main/java/org/bitbiome/commands/CommandAPI.java @@ -0,0 +1,8 @@ +package org.bitbiome.commands; + +import java.util.Scanner; + +public interface CommandAPI { + public void performCommand(Scanner scanner, boolean isRunning, String message); + +} From 7b7f81ec650c90ef5ece94fa0c82676c25dde275 Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 4 Jan 2023 02:41:01 +0100 Subject: [PATCH 08/19] Created the game engine An endless loop where a scanner scans the next line after one action and print it. --- .../java/org/bitbiome/InteractionLoop.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/java/org/bitbiome/InteractionLoop.java diff --git a/src/main/java/org/bitbiome/InteractionLoop.java b/src/main/java/org/bitbiome/InteractionLoop.java new file mode 100644 index 0000000..557585f --- /dev/null +++ b/src/main/java/org/bitbiome/InteractionLoop.java @@ -0,0 +1,19 @@ +package org.bitbiome; + +import java.util.Scanner; + +public class InteractionLoop { + + Scanner input = new Scanner(System.in); + + public void run() { + boolean isRunning = true; + while (isRunning) { + String line = input.nextLine().toLowerCase(); + System.out.println(line); + } + } + + + +} From 41ae408d8c4db7bfe22fd950e3480fc55873aeca Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 4 Jan 2023 02:43:00 +0100 Subject: [PATCH 09/19] Created the boot class After creating an object from this class, the game will start by here. Added the CommandListener This listener will add the commands which the game has and will have --- src/main/java/org/bitbiome/Boot.java | 23 +++++++++++ .../bitbiome/commands/CommandListener.java | 38 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/main/java/org/bitbiome/Boot.java create mode 100644 src/main/java/org/bitbiome/commands/CommandListener.java diff --git a/src/main/java/org/bitbiome/Boot.java b/src/main/java/org/bitbiome/Boot.java new file mode 100644 index 0000000..590ef38 --- /dev/null +++ b/src/main/java/org/bitbiome/Boot.java @@ -0,0 +1,23 @@ +package org.bitbiome; + +import org.bitbiome.commands.CommandListener; + +public class Boot { + + private CommandListener cmdListener; + public static Boot instance; + public Boot() { + instance = this; + cmdListener = new CommandListener(); + InteractionLoop game = new InteractionLoop(); + game.run(); + } + + public CommandListener getCmdListener(){ + return cmdListener; + } + +} + + + diff --git a/src/main/java/org/bitbiome/commands/CommandListener.java b/src/main/java/org/bitbiome/commands/CommandListener.java new file mode 100644 index 0000000..9ed47ee --- /dev/null +++ b/src/main/java/org/bitbiome/commands/CommandListener.java @@ -0,0 +1,38 @@ +package org.bitbiome.commands; + +import java.util.HashMap; +import java.util.Scanner; + +public class CommandListener { + + private HashMap commands; + + public CommandListener() { + commands = new HashMap<>(); + + /* + * Commandfield + * + * commands.put("CommandName", new CommandClass()); + * + * + */ + } + + public HashMap returnCommands() { + return commands; + } + + + public boolean perform(String command, Scanner scanner, boolean isRunning, String message) { + + CommandAPI cmd; + if ((cmd = commands.get(command)) != null) { + cmd.performCommand(scanner, isRunning, message); + return true; + } + return false; + } + + +} From a878b6ad0dd209baaff14b603cd2af3441bdba17 Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 4 Jan 2023 02:43:33 +0100 Subject: [PATCH 10/19] The boot class will be created now. --- src/main/java/org/bitbiome/Main.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/Main.java b/src/main/java/org/bitbiome/Main.java index ceb58c8..3d67836 100644 --- a/src/main/java/org/bitbiome/Main.java +++ b/src/main/java/org/bitbiome/Main.java @@ -9,7 +9,8 @@ public class Main { private Scanner s = new Scanner(System.in); public static void main(String[] args) { - JSONObject playerConfig = JsonParser.getJSONObject("playerconfig.json"); + //JSONObject playerConfig = JsonParser.getJSONObject("playerconfig.json"); + new Boot(); } public static int getLucky() { return 7; From 4038f1bfd5b5bb85f488b27ba45a03460868d54f Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 4 Jan 2023 02:45:57 +0100 Subject: [PATCH 11/19] The game loop is now checking if the command exists. --- src/main/java/org/bitbiome/InteractionLoop.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/InteractionLoop.java b/src/main/java/org/bitbiome/InteractionLoop.java index 557585f..e2a1cd0 100644 --- a/src/main/java/org/bitbiome/InteractionLoop.java +++ b/src/main/java/org/bitbiome/InteractionLoop.java @@ -10,7 +10,9 @@ public class InteractionLoop { boolean isRunning = true; while (isRunning) { String line = input.nextLine().toLowerCase(); - System.out.println(line); + if (!Boot.instance.getCmdListener().perform(line.toLowerCase().split(" ")[0], input, isRunning, line)) { + System.out.println("Unknown Command"); + } } } From 0933a56a4d0cc33793b6ec7a3968e88ba6ceb926 Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 4 Jan 2023 02:47:11 +0100 Subject: [PATCH 12/19] Added the help command This command prints a list of all commands which are available --- .../bitbiome/commands/CommandListener.java | 8 +------ .../org/bitbiome/commands/HelpCommand.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/bitbiome/commands/HelpCommand.java diff --git a/src/main/java/org/bitbiome/commands/CommandListener.java b/src/main/java/org/bitbiome/commands/CommandListener.java index 9ed47ee..f10bdfe 100644 --- a/src/main/java/org/bitbiome/commands/CommandListener.java +++ b/src/main/java/org/bitbiome/commands/CommandListener.java @@ -10,13 +10,7 @@ public class CommandListener { public CommandListener() { commands = new HashMap<>(); - /* - * Commandfield - * - * commands.put("CommandName", new CommandClass()); - * - * - */ + commands.put("help", new HelpCommand()); } public HashMap returnCommands() { diff --git a/src/main/java/org/bitbiome/commands/HelpCommand.java b/src/main/java/org/bitbiome/commands/HelpCommand.java new file mode 100644 index 0000000..45e8137 --- /dev/null +++ b/src/main/java/org/bitbiome/commands/HelpCommand.java @@ -0,0 +1,22 @@ +package org.bitbiome.commands; + +import org.bitbiome.Boot; + +import java.util.HashMap; +import java.util.Scanner; + +public class HelpCommand implements CommandAPI { + + + @Override + public void performCommand(Scanner scanner, boolean isRunning, String message) { + HashMap commands = Boot.instance.getCmdListener().returnCommands(); + StringBuilder outputMessage = new StringBuilder(); + outputMessage.append("Hier ist eine Liste der Commands:\n"); + commands.forEach((key, value) -> { + outputMessage.append("- ").append(key).append("\n"); + }); + System.out.println(outputMessage.toString()); + } + +} From d46176e8a274772800dc5dc9ad994be4bd96e654 Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 4 Jan 2023 02:48:31 +0100 Subject: [PATCH 13/19] Added the quit command This command quits the game with exit code 0. --- .../java/org/bitbiome/commands/CommandListener.java | 3 +++ src/main/java/org/bitbiome/commands/QuitCommand.java | 12 ++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/main/java/org/bitbiome/commands/QuitCommand.java diff --git a/src/main/java/org/bitbiome/commands/CommandListener.java b/src/main/java/org/bitbiome/commands/CommandListener.java index f10bdfe..2e62105 100644 --- a/src/main/java/org/bitbiome/commands/CommandListener.java +++ b/src/main/java/org/bitbiome/commands/CommandListener.java @@ -11,6 +11,9 @@ public class CommandListener { commands = new HashMap<>(); commands.put("help", new HelpCommand()); + + commands.put("exit", new QuitCommand()); + commands.put("quit", new QuitCommand()); } public HashMap returnCommands() { diff --git a/src/main/java/org/bitbiome/commands/QuitCommand.java b/src/main/java/org/bitbiome/commands/QuitCommand.java new file mode 100644 index 0000000..13e4e1e --- /dev/null +++ b/src/main/java/org/bitbiome/commands/QuitCommand.java @@ -0,0 +1,12 @@ +package org.bitbiome.commands; + +import java.util.Scanner; + +public class QuitCommand implements CommandAPI { + + @Override + public void performCommand(Scanner scanner, boolean isRunning, String message) { + System.out.println("You quitted!"); + System.exit(0); + } +} From 5a35f0ee84cf9dc1e089c7d67faf2062971cfc4e Mon Sep 17 00:00:00 2001 From: David Hermann Date: Thu, 5 Jan 2023 21:03:37 +0100 Subject: [PATCH 14/19] refactor: Edited help command Prepared for unit test, output message is now hardcoded --- .../java/org/bitbiome/commands/HelpCommand.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/HelpCommand.java b/src/main/java/org/bitbiome/commands/HelpCommand.java index 45e8137..4d88e3a 100644 --- a/src/main/java/org/bitbiome/commands/HelpCommand.java +++ b/src/main/java/org/bitbiome/commands/HelpCommand.java @@ -10,13 +10,14 @@ public class HelpCommand implements CommandAPI { @Override public void performCommand(Scanner scanner, boolean isRunning, String message) { - HashMap commands = Boot.instance.getCmdListener().returnCommands(); + System.out.println(getHelpMessage()); + } + + public static String getHelpMessage() { StringBuilder outputMessage = new StringBuilder(); - outputMessage.append("Hier ist eine Liste der Commands:\n"); - commands.forEach((key, value) -> { - outputMessage.append("- ").append(key).append("\n"); - }); - System.out.println(outputMessage.toString()); + outputMessage.append("Hier ist eine Liste der Commands:\n").append("- help -> Gibt diese Nachricht aus\n").append("- exit/quit -> Beendet das Spiel\n"); + + return outputMessage.toString(); } } From ffca558531ea10966b05b71dc77916203b167139 Mon Sep 17 00:00:00 2001 From: David Hermann Date: Thu, 5 Jan 2023 21:07:36 +0100 Subject: [PATCH 15/19] unittest: Added unittest for the help command --- .../org/bitbiome/commands/HelpCommandTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/test/java/org/bitbiome/commands/HelpCommandTest.java diff --git a/src/test/java/org/bitbiome/commands/HelpCommandTest.java b/src/test/java/org/bitbiome/commands/HelpCommandTest.java new file mode 100644 index 0000000..75006ed --- /dev/null +++ b/src/test/java/org/bitbiome/commands/HelpCommandTest.java @@ -0,0 +1,15 @@ +package org.bitbiome.commands; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class HelpCommandTest { + + @Test + public void testHelpCommand() { + String helpMessage = HelpCommand.getHelpMessage(); + assertEquals("Hier ist eine Liste der Commands:\n- help -> Gibt diese Nachricht aus\n- exit/quit -> Beendet das Spiel\n", helpMessage); + } + + +} From dfc7fae51a0af6e612c91e75fff64590242ae0be Mon Sep 17 00:00:00 2001 From: David Hermann Date: Thu, 5 Jan 2023 21:16:00 +0100 Subject: [PATCH 16/19] refactor: Deleted unit test for main class. Removed scanner from main class. --- src/main/java/org/bitbiome/Main.java | 4 ---- src/test/java/org/bitbiome/TestMain.java | 13 ------------- 2 files changed, 17 deletions(-) delete mode 100644 src/test/java/org/bitbiome/TestMain.java diff --git a/src/main/java/org/bitbiome/Main.java b/src/main/java/org/bitbiome/Main.java index 3d67836..d8f1b51 100644 --- a/src/main/java/org/bitbiome/Main.java +++ b/src/main/java/org/bitbiome/Main.java @@ -6,14 +6,10 @@ import java.util.Scanner; public class Main { - private Scanner s = new Scanner(System.in); public static void main(String[] args) { //JSONObject playerConfig = JsonParser.getJSONObject("playerconfig.json"); new Boot(); } - public static int getLucky() { - return 7; - } } \ No newline at end of file diff --git a/src/test/java/org/bitbiome/TestMain.java b/src/test/java/org/bitbiome/TestMain.java deleted file mode 100644 index 2535f2b..0000000 --- a/src/test/java/org/bitbiome/TestMain.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.bitbiome; - -import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class TestMain { - - @Test - public void testLucky() { - assertEquals(7, Main.getLucky()); - } - -} From b3dfbe360189c4ced486e25ebbfe3c7a0f4f52a9 Mon Sep 17 00:00:00 2001 From: David Hermann Date: Thu, 5 Jan 2023 21:20:24 +0100 Subject: [PATCH 17/19] refactor: outsourced code in String function --- src/main/java/org/bitbiome/commands/QuitCommand.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/QuitCommand.java b/src/main/java/org/bitbiome/commands/QuitCommand.java index 13e4e1e..d969852 100644 --- a/src/main/java/org/bitbiome/commands/QuitCommand.java +++ b/src/main/java/org/bitbiome/commands/QuitCommand.java @@ -6,7 +6,11 @@ public class QuitCommand implements CommandAPI { @Override public void performCommand(Scanner scanner, boolean isRunning, String message) { - System.out.println("You quitted!"); + System.out.println(getQuitMessage()); System.exit(0); } + + public static String getQuitMessage() { + return "You quitted!"; + } } From 59a36a66a6c43cf2576c3b93344c164e89b9efa5 Mon Sep 17 00:00:00 2001 From: David Hermann Date: Thu, 5 Jan 2023 21:21:21 +0100 Subject: [PATCH 18/19] unittest: Added unit test for the quit/exit command --- .../org/bitbiome/commands/QuitCommandTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/test/java/org/bitbiome/commands/QuitCommandTest.java diff --git a/src/test/java/org/bitbiome/commands/QuitCommandTest.java b/src/test/java/org/bitbiome/commands/QuitCommandTest.java new file mode 100644 index 0000000..67a368e --- /dev/null +++ b/src/test/java/org/bitbiome/commands/QuitCommandTest.java @@ -0,0 +1,15 @@ +package org.bitbiome.commands; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class QuitCommandTest { + + + @Test + public void testQuitCommand() { + assertEquals("You quitted!", QuitCommand.getQuitMessage()); + } + +} From ede261e59dbbdb7da786edeb58d3b93ab39bf375 Mon Sep 17 00:00:00 2001 From: David Hermann Date: Thu, 5 Jan 2023 21:22:47 +0100 Subject: [PATCH 19/19] refactor: Deleted unused imports from Main class --- src/main/java/org/bitbiome/Main.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/org/bitbiome/Main.java b/src/main/java/org/bitbiome/Main.java index d8f1b51..e614ea5 100644 --- a/src/main/java/org/bitbiome/Main.java +++ b/src/main/java/org/bitbiome/Main.java @@ -1,8 +1,5 @@ package org.bitbiome; -import org.json.JSONObject; - -import java.util.Scanner; public class Main {