Skip to content

Commit

Permalink
Add DisplayNameCMDTest and TurnToPlayerCMDTest
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Sep 5, 2024
1 parent 97c6550 commit 7368045
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -24,6 +26,8 @@ public FancyNpcsTests() {
// command tests
addTest(CreateCMDTest.class);
addTest(TypeCMDTest.class);
addTest(DisplayNameCMDTest.class);
addTest(TurnToPlayerCMDTest.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = "<red>Test <orange>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("<empty>");
}

@FNTest(name = "Set display name to empty")
public void setDisplayNameToEmpty(Player player) {
expect(player.performCommand("npc displayname " + npcName + " <empty>")).toBe(true);
expect(npc.getData().getDisplayName()).toEqual("<empty>");
}

@FNTest(name = "Set display name with blocked command")
public void setDisplayNameWithBlockedCommand(Player player) {
List<String> blockedCommands = FancyNpcs.getInstance().getFancyNpcConfig().getBlockedCommands();
if (blockedCommands.isEmpty()) {
return;
}
String blockedCommand = blockedCommands.get(0);

expect(player.performCommand("npc displayname " + npcName + " <click:run_command:'/" + blockedCommand + "'>hello</click>")).toBe(true);

expect(npc.getData().getDisplayName()).toEqual(npcName);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit 7368045

Please sign in to comment.