Skip to content

Commit

Permalink
more CreateCMD tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Sep 5, 2024
1 parent 0518512 commit 710ca20
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ tasks {
hangar("ViaVersion", "5.0.3")
hangar("ViaBackwards", "5.0.3")
hangar("PlaceholderAPI", "2.11.6")
modrinth("multiverse-core", "4.3.11")
// modrinth("multiverse-core", "4.3.11")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import de.oliver.fancynpcs.tests.annotations.FNAfterEach;
import de.oliver.fancynpcs.tests.annotations.FNBeforeEach;
import de.oliver.fancynpcs.tests.annotations.FNTest;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;

import java.util.UUID;

import static de.oliver.fancynpcs.tests.Expectable.expect;

public class CreateCMDTest {
Expand All @@ -20,13 +23,16 @@ public class CreateCMDTest {

@FNBeforeEach
public void setUp(Player player) {
npcName = "test-" + player.getUniqueId().toString().substring(0, 8);
npcName = "test-" + UUID.randomUUID().toString().substring(0, 8);
createdNpc = null;
}

@FNAfterEach
public void tearDown(Player player) {
NPC_MANAGER.removeNpc(createdNpc);
if (createdNpc != null) {
NPC_MANAGER.removeNpc(createdNpc);
}

expect(NPC_MANAGER.getNpc(npcName)).toBeNull();

createdNpc = null;
Expand Down Expand Up @@ -54,4 +60,80 @@ public void createNpcWithType(Player player) {

expect(createdNpc.getData().getType()).toEqual(EntityType.PIG);
}

@FNTest(name = "Create npc with location")
public void createNpcWithLocation(Player player) {
expect(player.performCommand("npc create " + npcName + " --location 12 154 842")).toBe(true);

createdNpc = NPC_MANAGER.getNpc(npcName);
expect(createdNpc).toBeDefined();

expect(createdNpc.getEntityId()).toBeGreaterThan(-1);

expect(createdNpc.getData().getLocation().x()).toEqual(12d);
expect(createdNpc.getData().getLocation().y()).toEqual(154d);
expect(createdNpc.getData().getLocation().z()).toEqual(842d);
}

@FNTest(name = "Create npc with world")
public void createNpcWithWorld(Player player) {
String worldName = "world_the_nether";
if (Bukkit.getWorld(worldName) == null) {
worldName = "world";
}

expect(player.performCommand("npc create " + npcName + " --world " + worldName)).toBe(true);

createdNpc = NPC_MANAGER.getNpc(npcName);
expect(createdNpc).toBeDefined();

expect(createdNpc.getEntityId()).toBeGreaterThan(-1);

expect(createdNpc.getData().getLocation().getWorld().getName()).toEqual(worldName);
}

@FNTest(name = "Create npc with invalid name")
public void createNpcWithInvalidName(Player player) {
expect(player.performCommand("npc create " + "invalid.name")).toBe(true);

createdNpc = NPC_MANAGER.getNpc("invalid.name");
expect(createdNpc).toBeNull();
}

@FNTest(name = "Create npc with existing name")
public void createNpcWithExistingName(Player player) {
expect(player.performCommand("npc create " + npcName)).toBe(true);

createdNpc = NPC_MANAGER.getNpc(npcName);
expect(createdNpc).toBeDefined();

expect(player.performCommand("npc create " + npcName)).toBe(true);

Npc existingNpc = NPC_MANAGER.getNpc(npcName);
expect(existingNpc).toBeDefined();

expect(existingNpc.getEntityId()).toBeGreaterThan(-1);
expect(existingNpc).toEqual(createdNpc);
}

@FNTest(name = "Create npc with all flags")
public void createNpcWithAllFlags(Player player) {
String worldName = "world_the_nether";
if (Bukkit.getWorld(worldName) == null) {
worldName = "world";
}

expect(player.performCommand("npc create " + npcName + " --type COW --location 137 131 -571 --world " + worldName)).toBe(true);

createdNpc = NPC_MANAGER.getNpc(npcName);
expect(createdNpc).toBeDefined();

expect(createdNpc.getEntityId()).toBeGreaterThan(-1);

expect(createdNpc.getData().getType()).toEqual(EntityType.COW);
expect(createdNpc.getData().getLocation().x()).toEqual(137d);
expect(createdNpc.getData().getLocation().y()).toEqual(131d);
expect(createdNpc.getData().getLocation().z()).toEqual(-571d);
expect(createdNpc.getData().getLocation().getWorld().getName()).toEqual(worldName);
}
}

0 comments on commit 710ca20

Please sign in to comment.