From 9c5dbc57d7d1ac3825c5e547e12dfc502bdaf465 Mon Sep 17 00:00:00 2001 From: Tanja Herche Date: Wed, 1 Feb 2023 14:56:46 +0100 Subject: [PATCH] Unittest: MapCommand --- .../bitbiome/commands/CommandListener.java | 1 + .../org/bitbiome/commands/MapCommand.java | 23 +++++++++++++++++++ .../org/bitbiome/commands/MapCommandTest.java | 18 +++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/main/java/org/bitbiome/commands/MapCommand.java create mode 100644 src/test/java/org/bitbiome/commands/MapCommandTest.java diff --git a/src/main/java/org/bitbiome/commands/CommandListener.java b/src/main/java/org/bitbiome/commands/CommandListener.java index d59813c..7d03184 100644 --- a/src/main/java/org/bitbiome/commands/CommandListener.java +++ b/src/main/java/org/bitbiome/commands/CommandListener.java @@ -18,6 +18,7 @@ public class CommandListener { commands.put("quit", new QuitCommand()); commands.put("location", new LocationCommand()); commands.put("travel", new TravelCommand()); + commands.put("map", new MapCommand()); } public HashMap returnCommands() { diff --git a/src/main/java/org/bitbiome/commands/MapCommand.java b/src/main/java/org/bitbiome/commands/MapCommand.java new file mode 100644 index 0000000..3b1620c --- /dev/null +++ b/src/main/java/org/bitbiome/commands/MapCommand.java @@ -0,0 +1,23 @@ +package org.bitbiome.commands; + +import org.bitbiome.classes.TravelEngine; + +import java.util.Scanner; + +public class MapCommand implements CommandAPI{ + + @Override + public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { + System.out.println(getMapMessage()); + } + public static String getMapMessage() { + StringBuilder outputMessage = new StringBuilder(); + outputMessage + .append("Map:\n") + .append("Wueste Gruendland Winterland\n\n") + .append("Strand Wald Berge\n\n"); + return outputMessage.toString(); + } + + +} diff --git a/src/test/java/org/bitbiome/commands/MapCommandTest.java b/src/test/java/org/bitbiome/commands/MapCommandTest.java new file mode 100644 index 0000000..def2566 --- /dev/null +++ b/src/test/java/org/bitbiome/commands/MapCommandTest.java @@ -0,0 +1,18 @@ +package org.bitbiome.commands; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class MapCommandTest { + @Test + public void testMapCommand() { + String mapMessage = MapCommand.getMapMessage(); + StringBuilder outputMessage = new StringBuilder(); + outputMessage + .append("Map:\n") + .append("Wueste Gruendland Winterland\n\n") + .append("Strand Wald Berge\n\n"); + assertEquals(outputMessage.toString(), mapMessage); + } +}