Skip to content

Commit 20095f3

Browse files
committed
Update CommandNamespaceTests after rebasing CommandAPI#478
1 parent 7b09a17 commit 20095f3

File tree

1 file changed

+3
-19
lines changed
  • commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test

1 file changed

+3
-19
lines changed

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/CommandNamespaceTests.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.mojang.brigadier.exceptions.CommandSyntaxException;
44
import com.mojang.brigadier.tree.CommandNode;
55
import com.mojang.brigadier.tree.RootCommandNode;
6-
import dev.jorel.commandapi.Brigadier;
76
import dev.jorel.commandapi.CommandAPI;
87
import dev.jorel.commandapi.CommandAPIBukkitConfig;
98
import dev.jorel.commandapi.CommandAPICommand;
@@ -14,7 +13,6 @@
1413
import dev.jorel.commandapi.arguments.StringArgument;
1514
import org.bukkit.Bukkit;
1615
import org.bukkit.ChatColor;
17-
import org.bukkit.Location;
1816
import org.bukkit.command.CommandMap;
1917
import org.bukkit.command.CommandSender;
2018
import org.bukkit.command.SimpleCommandMap;
@@ -30,8 +28,6 @@
3028
import org.junit.jupiter.params.provider.ValueSource;
3129
import org.mockito.Mockito;
3230

33-
import java.lang.reflect.Method;
34-
3531
import static org.junit.jupiter.api.Assertions.*;
3632
import static org.mockito.ArgumentMatchers.isA;
3733

@@ -70,8 +66,9 @@ Player enableWithNamespaces() {
7066
assertDoesNotThrow(() -> server.getScheduler().performOneTick());
7167
assertFalse(CommandAPI.canRegister());
7268

73-
// Get a CraftPlayer for running VanillaCommandWrapper commands
74-
Player runCommandsPlayer = Mockito.mock(MockPlatform.getInstance().getCraftPlayerClass());
69+
// Get a mocked CraftPlayer for running VanillaCommandWrapper commands
70+
Player runCommandsPlayer = server.setupMockedCraftPlayer();
71+
7572
// Ensure player can have permissions modified
7673
PermissibleBase perm = new PermissibleBase(runCommandsPlayer);
7774
Mockito.when(runCommandsPlayer.addAttachment(isA(Plugin.class))).thenAnswer(invocation ->
@@ -87,19 +84,6 @@ Player enableWithNamespaces() {
8784
Mockito.when(runCommandsPlayer.hasPermission(isA(String.class))).thenAnswer(invocation ->
8885
perm.hasPermission(invocation.getArgument(0, String.class))
8986
);
90-
// Get location is used when creating the BrigadierSource in MockNMS
91-
Mockito.when(runCommandsPlayer.getLocation()).thenReturn(new Location(null, 0, 0, 0));
92-
93-
// Provide proper handle as VanillaCommandWrapper expects
94-
Method getHandle = assertDoesNotThrow(() -> runCommandsPlayer.getClass().getDeclaredMethod("getHandle"));
95-
Object brigadierSource = Brigadier.getBrigadierSourceFromCommandSender(runCommandsPlayer);
96-
Object handle = Mockito.mock(getHandle.getReturnType(), invocation -> brigadierSource);
97-
// This is a funny quirk of Mockito, but you don't need to put the method call you want to mock inside `when`
98-
// As long as the method is called, `when` knows what you are talking about
99-
// That means we can mock `CraftPlayer#getHandle` indirectly using reflection
100-
// See the additional response in https://stackoverflow.com/a/10131885
101-
assertDoesNotThrow(() -> getHandle.invoke(runCommandsPlayer));
102-
Mockito.when(null).thenReturn(handle);
10387

10488
return runCommandsPlayer;
10589
}

0 commit comments

Comments
 (0)