Browse Source

Unittest: Coloring

remotes/origin/map
Tanja Herche 2 years ago
parent
commit
b6d57e2cf5
  1. 11
      src/main/java/org/bitbiome/commands/MapCommand.java
  2. 9
      src/test/java/org/bitbiome/commands/MapCommandTest.java

11
src/main/java/org/bitbiome/commands/MapCommand.java

@ -2,19 +2,24 @@ package org.bitbiome.commands;
import org.bitbiome.classes.TravelEngine;
import org.json.JSONArray;
import java.util.Scanner;
import org.bitbiome.classes.Colors;
public class MapCommand implements CommandAPI{
@Override
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) {
System.out.println(getMapMessage(travelEngine));
}
public static String getLocationMessage(TravelEngine travelEngine) {
return "Du befindest dich gerade hier: " + travelEngine.getPlayer().getLocation().getName();
}
public static String getMapMessage(TravelEngine travelEngine) {
StringBuilder outputMessage = new StringBuilder();
JSONArray locations = travelEngine.getLocationList();
outputMessage
.append("Map:\n")
.append(locations.getJSONObject(5).getString("name") + " " + locations.getJSONObject(4).getString("name") + " " + locations.getJSONObject(2).getString("name") + "\n\n")
.append(locations.getJSONObject(1).getString("name") + " " + locations.getJSONObject(0).getString("name") + " " + locations.getJSONObject(3).getString("name") + "\n\n");
.append(Colors.ANSI_BLUE + getLocationMessage(travelEngine) + "\n" + Colors.ANSI_RESET)
.append(Colors.ANSI_BLUE + "Deine Karte:\n" + Colors.ANSI_RESET)
.append(Colors.ANSI_BLUE + locations.getJSONObject(5).getString("name") + " " + locations.getJSONObject(4).getString("name") + " " + locations.getJSONObject(2).getString("name") + "\n\n" + Colors.ANSI_RESET)
.append(Colors.ANSI_BLUE + locations.getJSONObject(1).getString("name") + " " + locations.getJSONObject(0).getString("name") + " " + locations.getJSONObject(3).getString("name") + "\n\n" + Colors.ANSI_RESET);
return outputMessage.toString();
}

9
src/test/java/org/bitbiome/commands/MapCommandTest.java

@ -1,5 +1,6 @@
package org.bitbiome.commands;
import org.bitbiome.classes.Colors;
import org.bitbiome.classes.TravelEngine;
import org.bitbiome.entities.Player;
import org.junit.jupiter.api.Test;
@ -14,9 +15,11 @@ public class MapCommandTest {
String mapMessage = MapCommand.getMapMessage(outputtest);
StringBuilder outputMessage = new StringBuilder();
outputMessage
.append("Map:\n")
.append("Wueste Gruenland Winterland\n\n")
.append("Strand Wald Berge\n\n");
.append(Colors.ANSI_BLUE + "Du befindest dich gerade hier: Wald" + "\n" + Colors.ANSI_RESET)
.append(Colors.ANSI_BLUE + "Deine Karte:\n" + Colors.ANSI_RESET)
.append(Colors.ANSI_BLUE + "Wueste" + " " + "Gruenland" + " " + "Winterland" + "\n\n" + Colors.ANSI_RESET)
.append(Colors.ANSI_BLUE + "Strand" + " " + "Wald" + " " + "Berge" + "\n\n" + Colors.ANSI_RESET);
assertEquals(outputMessage.toString(), mapMessage);
}
}
Loading…
Cancel
Save