diff --git a/src/main/java/de/oliver/fancynpcs/tests/impl/FancyNpcsTests.java b/src/main/java/de/oliver/fancynpcs/tests/impl/FancyNpcsTests.java index 1a1e3ee7..39fa3607 100644 --- a/src/main/java/de/oliver/fancynpcs/tests/impl/FancyNpcsTests.java +++ b/src/main/java/de/oliver/fancynpcs/tests/impl/FancyNpcsTests.java @@ -3,6 +3,8 @@ import de.oliver.fancynpcs.tests.FNTestClass; import de.oliver.fancynpcs.tests.impl.api.CreateNpcTest; import de.oliver.fancynpcs.tests.impl.commands.CreateCMDTest; +import de.oliver.fancynpcs.tests.impl.commands.DisplayNameCMDTest; +import de.oliver.fancynpcs.tests.impl.commands.TurnToPlayerCMDTest; import de.oliver.fancynpcs.tests.impl.commands.TypeCMDTest; import org.bukkit.entity.Player; @@ -24,6 +26,8 @@ public FancyNpcsTests() { // command tests addTest(CreateCMDTest.class); addTest(TypeCMDTest.class); + addTest(DisplayNameCMDTest.class); + addTest(TurnToPlayerCMDTest.class); } /** diff --git a/src/main/java/de/oliver/fancynpcs/tests/impl/commands/DisplayNameCMDTest.java b/src/main/java/de/oliver/fancynpcs/tests/impl/commands/DisplayNameCMDTest.java new file mode 100644 index 00000000..2bff42bd --- /dev/null +++ b/src/main/java/de/oliver/fancynpcs/tests/impl/commands/DisplayNameCMDTest.java @@ -0,0 +1,68 @@ +package de.oliver.fancynpcs.tests.impl.commands; + +import de.oliver.fancynpcs.FancyNpcs; +import de.oliver.fancynpcs.api.Npc; +import de.oliver.fancynpcs.tests.annotations.FNAfterEach; +import de.oliver.fancynpcs.tests.annotations.FNBeforeEach; +import de.oliver.fancynpcs.tests.annotations.FNTest; +import de.oliver.fancynpcs.tests.impl.api.NpcTestEnv; +import org.bukkit.entity.Player; + +import java.util.List; + +import static de.oliver.fancynpcs.tests.Expectable.expect; + +public class DisplayNameCMDTest { + + private Npc npc; + private String npcName; + + @FNBeforeEach + public void setUp(Player player) { + npc = NpcTestEnv.givenDefaultNpcIsCreated(); + npcName = npc.getData().getName(); + + NpcTestEnv.givenNpcIsRegistered(npc); + } + + @FNAfterEach + public void tearDown(Player player) { + NpcTestEnv.givenNpcIsUnregistered(npc); + + npc = null; + npcName = null; + } + + @FNTest(name = "Set display name") + public void setDisplayName(Player player) { + String displayName = "Test Display Name"; + expect(player.performCommand("npc displayname " + npcName + " " + displayName)).toBe(true); + expect(npc.getData().getDisplayName()).toEqual(displayName); + } + + @FNTest(name = "Set display name to none") + public void setDisplayNameToNone(Player player) { + expect(player.performCommand("npc displayname " + npcName + " @none")).toBe(true); + expect(npc.getData().getDisplayName()).toEqual(""); + } + + @FNTest(name = "Set display name to empty") + public void setDisplayNameToEmpty(Player player) { + expect(player.performCommand("npc displayname " + npcName + " ")).toBe(true); + expect(npc.getData().getDisplayName()).toEqual(""); + } + + @FNTest(name = "Set display name with blocked command") + public void setDisplayNameWithBlockedCommand(Player player) { + List blockedCommands = FancyNpcs.getInstance().getFancyNpcConfig().getBlockedCommands(); + if (blockedCommands.isEmpty()) { + return; + } + String blockedCommand = blockedCommands.get(0); + + expect(player.performCommand("npc displayname " + npcName + " hello")).toBe(true); + + expect(npc.getData().getDisplayName()).toEqual(npcName); + } + +} diff --git a/src/main/java/de/oliver/fancynpcs/tests/impl/commands/TurnToPlayerCMDTest.java b/src/main/java/de/oliver/fancynpcs/tests/impl/commands/TurnToPlayerCMDTest.java new file mode 100644 index 00000000..48e8828b --- /dev/null +++ b/src/main/java/de/oliver/fancynpcs/tests/impl/commands/TurnToPlayerCMDTest.java @@ -0,0 +1,47 @@ +package de.oliver.fancynpcs.tests.impl.commands; + +import de.oliver.fancynpcs.api.Npc; +import de.oliver.fancynpcs.tests.annotations.FNAfterEach; +import de.oliver.fancynpcs.tests.annotations.FNBeforeEach; +import de.oliver.fancynpcs.tests.annotations.FNTest; +import de.oliver.fancynpcs.tests.impl.api.NpcTestEnv; +import org.bukkit.entity.Player; + +import static de.oliver.fancynpcs.tests.Expectable.expect; + +public class TurnToPlayerCMDTest { + + private Npc npc; + private String npcName; + + @FNBeforeEach + public void setUp(Player player) { + npc = NpcTestEnv.givenDefaultNpcIsCreated(); + npcName = npc.getData().getName(); + + NpcTestEnv.givenNpcIsRegistered(npc); + } + + @FNAfterEach + public void tearDown(Player player) { + NpcTestEnv.givenNpcIsUnregistered(npc); + + npc = null; + npcName = null; + } + + @FNTest(name = "Set turnToPlayer to true") + public void setTurnToPlayerToTrue(Player player) { + expect(player.performCommand("npc turn_to_player " + npcName + " true")).toBe(true); + expect(npc.getData().isTurnToPlayer()).toBe(true); + } + + @FNTest(name = "Set turnToPlayer to false") + public void setTurnToPlayerToFalse(Player player) { + npc.getData().setTurnToPlayer(true); + + expect(player.performCommand("npc turn_to_player " + npcName + " false")).toBe(true); + expect(npc.getData().isTurnToPlayer()).toBe(false); + } + +}