Skip to content

Commit 4b74a3a

Browse files
committed
Add ProxiedNativeCommandSenderTests
1 parent 8b05856 commit 4b74a3a

File tree

12 files changed

+363
-20
lines changed
  • commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test
    • commandapi-bukkit-test-impl-1.16.5/src/main/java/dev/jorel/commandapi/test
    • commandapi-bukkit-test-impl-1.17/src/main/java/dev/jorel/commandapi/test
    • commandapi-bukkit-test-impl-1.18/src/main/java/dev/jorel/commandapi/test
    • commandapi-bukkit-test-impl-1.19.2/src/main/java/dev/jorel/commandapi/test
    • commandapi-bukkit-test-impl-1.19.4/src/main/java/dev/jorel/commandapi/test
    • commandapi-bukkit-test-impl-1.20.2/src/main/java/dev/jorel/commandapi/test
    • commandapi-bukkit-test-impl-1.20.3/src/main/java/dev/jorel/commandapi/test
    • commandapi-bukkit-test-impl-1.20.5/src/main/java/dev/jorel/commandapi/test
    • commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test
    • commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test
    • commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test

12 files changed

+363
-20
lines changed

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.16.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.bukkit.inventory.ItemFactory;
3636
import org.bukkit.potion.PotionEffectType;
3737
import org.bukkit.scoreboard.Team;
38+
import org.mockito.ArgumentMatchers;
3839
import org.mockito.Mockito;
3940

4041
import com.google.common.collect.ImmutableMap;
@@ -361,6 +362,32 @@ public CommandListenerWrapper getBrigadierSourceFromCommandSender(AbstractComman
361362
Mockito.when(clw.getPosition()).thenReturn(new Vec3D(0, 0, 0));
362363
Mockito.when(clw.i()).thenReturn(new Vec2F(0, 0));
363364
}
365+
366+
// NativeProxyCommandSender construction (NMS#createNativeProxyCommandSender)
367+
// Make sure these builder methods work as expected
368+
Mockito.when(clw.a(ArgumentMatchers.<Vec3D>any())).thenAnswer(invocation -> {
369+
Mockito.when(clw.getPosition()).thenReturn(invocation.getArgument(0));
370+
return clw;
371+
});
372+
Mockito.when(clw.a(ArgumentMatchers.<Vec2F>any())).thenAnswer(invocation -> {
373+
Mockito.when(clw.i()).thenReturn(invocation.getArgument(0));
374+
return clw;
375+
});
376+
Mockito.when(clw.a(ArgumentMatchers.<WorldServer>any())).thenAnswer(invocation -> {
377+
Mockito.when(clw.getWorld()).thenReturn(invocation.getArgument(0));
378+
return clw;
379+
});
380+
Mockito.when(clw.a(ArgumentMatchers.<net.minecraft.server.v1_16_R3.Entity>any())).thenAnswer(invocation -> {
381+
net.minecraft.server.v1_16_R3.Entity entity = invocation.getArgument(0);
382+
String name = entity.getDisplayName().getString();
383+
IChatBaseComponent displayName = entity.getScoreboardDisplayName();
384+
385+
Mockito.when(clw.getEntity()).thenReturn(entity);
386+
Mockito.when(clw.getName()).thenReturn(name);
387+
Mockito.when(clw.getScoreboardDisplayName()).thenReturn(displayName);
388+
return clw;
389+
});
390+
364391
return clw;
365392
}
366393

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.17/src/main/java/dev/jorel/commandapi/test/MockNMS.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,32 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen
344344
Mockito.when(css.getPosition()).thenReturn(new Vec3(0, 0, 0));
345345
Mockito.when(css.getRotation()).thenReturn(new Vec2(0, 0));
346346
}
347+
348+
// NativeProxyCommandSender construction (NMS#createNativeProxyCommandSender)
349+
// Make sure these builder methods work as expected
350+
Mockito.when(css.withPosition(any())).thenAnswer(invocation -> {
351+
Mockito.when(css.getPosition()).thenReturn(invocation.getArgument(0));
352+
return css;
353+
});
354+
Mockito.when(css.withRotation(any())).thenAnswer(invocation -> {
355+
Mockito.when(css.getRotation()).thenReturn(invocation.getArgument(0));
356+
return css;
357+
});
358+
Mockito.when(css.withLevel(any())).thenAnswer(invocation -> {
359+
Mockito.when(css.getLevel()).thenReturn(invocation.getArgument(0));
360+
return css;
361+
});
362+
Mockito.when(css.withEntity(any())).thenAnswer(invocation -> {
363+
net.minecraft.world.entity.Entity entity = invocation.getArgument(0);
364+
String name = entity.getName().getString();
365+
net.minecraft.network.chat.Component displayName = entity.getDisplayName();
366+
367+
Mockito.when(css.getEntity()).thenReturn(entity);
368+
Mockito.when(css.getTextName()).thenReturn(name);
369+
Mockito.when(css.getDisplayName()).thenReturn(displayName);
370+
return css;
371+
});
372+
347373
return css;
348374
}
349375

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.18/src/main/java/dev/jorel/commandapi/test/MockNMS.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,32 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen
361361
Mockito.when(css.getPosition()).thenReturn(new Vec3(0, 0, 0));
362362
Mockito.when(css.getRotation()).thenReturn(new Vec2(0, 0));
363363
}
364+
365+
// NativeProxyCommandSender construction (NMS#createNativeProxyCommandSender)
366+
// Make sure these builder methods work as expected
367+
Mockito.when(css.withPosition(any())).thenAnswer(invocation -> {
368+
Mockito.when(css.getPosition()).thenReturn(invocation.getArgument(0));
369+
return css;
370+
});
371+
Mockito.when(css.withRotation(any())).thenAnswer(invocation -> {
372+
Mockito.when(css.getRotation()).thenReturn(invocation.getArgument(0));
373+
return css;
374+
});
375+
Mockito.when(css.withLevel(any())).thenAnswer(invocation -> {
376+
Mockito.when(css.getLevel()).thenReturn(invocation.getArgument(0));
377+
return css;
378+
});
379+
Mockito.when(css.withEntity(any())).thenAnswer(invocation -> {
380+
net.minecraft.world.entity.Entity entity = invocation.getArgument(0);
381+
String name = entity.getName().getString();
382+
net.minecraft.network.chat.Component displayName = entity.getDisplayName();
383+
384+
Mockito.when(css.getEntity()).thenReturn(entity);
385+
Mockito.when(css.getTextName()).thenReturn(name);
386+
Mockito.when(css.getDisplayName()).thenReturn(displayName);
387+
return css;
388+
});
389+
364390
return css;
365391
}
366392

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,32 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen
357357
Mockito.when(css.getPosition()).thenReturn(new Vec3(0, 0, 0));
358358
Mockito.when(css.getRotation()).thenReturn(new Vec2(0, 0));
359359
}
360+
361+
// NativeProxyCommandSender construction (NMS#createNativeProxyCommandSender)
362+
// Make sure these builder methods work as expected
363+
Mockito.when(css.withPosition(any())).thenAnswer(invocation -> {
364+
Mockito.when(css.getPosition()).thenReturn(invocation.getArgument(0));
365+
return css;
366+
});
367+
Mockito.when(css.withRotation(any())).thenAnswer(invocation -> {
368+
Mockito.when(css.getRotation()).thenReturn(invocation.getArgument(0));
369+
return css;
370+
});
371+
Mockito.when(css.withLevel(any())).thenAnswer(invocation -> {
372+
Mockito.when(css.getLevel()).thenReturn(invocation.getArgument(0));
373+
return css;
374+
});
375+
Mockito.when(css.withEntity(any())).thenAnswer(invocation -> {
376+
net.minecraft.world.entity.Entity entity = invocation.getArgument(0);
377+
String name = entity.getName().getString();
378+
net.minecraft.network.chat.Component displayName = entity.getDisplayName();
379+
380+
Mockito.when(css.getEntity()).thenReturn(entity);
381+
Mockito.when(css.getTextName()).thenReturn(name);
382+
Mockito.when(css.getDisplayName()).thenReturn(displayName);
383+
return css;
384+
});
385+
360386
return css;
361387
}
362388

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.19.4/src/main/java/dev/jorel/commandapi/test/MockNMS.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,32 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen
360360
Mockito.when(css.getPosition()).thenReturn(new Vec3(0, 0, 0));
361361
Mockito.when(css.getRotation()).thenReturn(new Vec2(0, 0));
362362
}
363+
364+
// NativeProxyCommandSender construction (NMS#createNativeProxyCommandSender)
365+
// Make sure these builder methods work as expected
366+
Mockito.when(css.withPosition(any())).thenAnswer(invocation -> {
367+
Mockito.when(css.getPosition()).thenReturn(invocation.getArgument(0));
368+
return css;
369+
});
370+
Mockito.when(css.withRotation(any())).thenAnswer(invocation -> {
371+
Mockito.when(css.getRotation()).thenReturn(invocation.getArgument(0));
372+
return css;
373+
});
374+
Mockito.when(css.withLevel(any())).thenAnswer(invocation -> {
375+
Mockito.when(css.getLevel()).thenReturn(invocation.getArgument(0));
376+
return css;
377+
});
378+
Mockito.when(css.withEntity(any())).thenAnswer(invocation -> {
379+
net.minecraft.world.entity.Entity entity = invocation.getArgument(0);
380+
String name = entity.getName().getString();
381+
net.minecraft.network.chat.Component displayName = entity.getDisplayName();
382+
383+
Mockito.when(css.getEntity()).thenReturn(entity);
384+
Mockito.when(css.getTextName()).thenReturn(name);
385+
Mockito.when(css.getDisplayName()).thenReturn(displayName);
386+
return css;
387+
});
388+
363389
return css;
364390
}
365391

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.2/src/main/java/dev/jorel/commandapi/test/MockNMS.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,32 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen
355355
Mockito.when(css.getPosition()).thenReturn(new Vec3(0, 0, 0));
356356
Mockito.when(css.getRotation()).thenReturn(new Vec2(0, 0));
357357
}
358+
359+
// NativeProxyCommandSender construction (NMS#createNativeProxyCommandSender)
360+
// Make sure these builder methods work as expected
361+
Mockito.when(css.withPosition(any())).thenAnswer(invocation -> {
362+
Mockito.when(css.getPosition()).thenReturn(invocation.getArgument(0));
363+
return css;
364+
});
365+
Mockito.when(css.withRotation(any())).thenAnswer(invocation -> {
366+
Mockito.when(css.getRotation()).thenReturn(invocation.getArgument(0));
367+
return css;
368+
});
369+
Mockito.when(css.withLevel(any())).thenAnswer(invocation -> {
370+
Mockito.when(css.getLevel()).thenReturn(invocation.getArgument(0));
371+
return css;
372+
});
373+
Mockito.when(css.withEntity(any())).thenAnswer(invocation -> {
374+
net.minecraft.world.entity.Entity entity = invocation.getArgument(0);
375+
String name = entity.getName().getString();
376+
net.minecraft.network.chat.Component displayName = entity.getDisplayName();
377+
378+
Mockito.when(css.getEntity()).thenReturn(entity);
379+
Mockito.when(css.getTextName()).thenReturn(name);
380+
Mockito.when(css.getDisplayName()).thenReturn(displayName);
381+
return css;
382+
});
383+
358384
return css;
359385
}
360386

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.3/src/main/java/dev/jorel/commandapi/test/MockNMS.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,32 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen
368368
Mockito.when(css.getPosition()).thenReturn(new Vec3(0, 0, 0));
369369
Mockito.when(css.getRotation()).thenReturn(new Vec2(0, 0));
370370
}
371+
372+
// NativeProxyCommandSender construction (NMS#createNativeProxyCommandSender)
373+
// Make sure these builder methods work as expected
374+
Mockito.when(css.withPosition(any())).thenAnswer(invocation -> {
375+
Mockito.when(css.getPosition()).thenReturn(invocation.getArgument(0));
376+
return css;
377+
});
378+
Mockito.when(css.withRotation(any())).thenAnswer(invocation -> {
379+
Mockito.when(css.getRotation()).thenReturn(invocation.getArgument(0));
380+
return css;
381+
});
382+
Mockito.when(css.withLevel(any())).thenAnswer(invocation -> {
383+
Mockito.when(css.getLevel()).thenReturn(invocation.getArgument(0));
384+
return css;
385+
});
386+
Mockito.when(css.withEntity(any())).thenAnswer(invocation -> {
387+
net.minecraft.world.entity.Entity entity = invocation.getArgument(0);
388+
String name = entity.getName().getString();
389+
net.minecraft.network.chat.Component displayName = entity.getDisplayName();
390+
391+
Mockito.when(css.getEntity()).thenReturn(entity);
392+
Mockito.when(css.getTextName()).thenReturn(name);
393+
Mockito.when(css.getDisplayName()).thenReturn(displayName);
394+
return css;
395+
});
396+
371397
return css;
372398
}
373399

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,32 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen
387387
Mockito.when(css.getPosition()).thenReturn(new Vec3(0, 0, 0));
388388
Mockito.when(css.getRotation()).thenReturn(new Vec2(0, 0));
389389
}
390+
391+
// NativeProxyCommandSender construction (NMS#createNativeProxyCommandSender)
392+
// Make sure these builder methods work as expected
393+
Mockito.when(css.withPosition(any())).thenAnswer(invocation -> {
394+
Mockito.when(css.getPosition()).thenReturn(invocation.getArgument(0));
395+
return css;
396+
});
397+
Mockito.when(css.withRotation(any())).thenAnswer(invocation -> {
398+
Mockito.when(css.getRotation()).thenReturn(invocation.getArgument(0));
399+
return css;
400+
});
401+
Mockito.when(css.withLevel(any())).thenAnswer(invocation -> {
402+
Mockito.when(css.getLevel()).thenReturn(invocation.getArgument(0));
403+
return css;
404+
});
405+
Mockito.when(css.withEntity(any())).thenAnswer(invocation -> {
406+
net.minecraft.world.entity.Entity entity = invocation.getArgument(0);
407+
String name = entity.getName().getString();
408+
net.minecraft.network.chat.Component displayName = entity.getDisplayName();
409+
410+
Mockito.when(css.getEntity()).thenReturn(entity);
411+
Mockito.when(css.getTextName()).thenReturn(name);
412+
Mockito.when(css.getDisplayName()).thenReturn(displayName);
413+
return css;
414+
});
415+
390416
return css;
391417
}
392418

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20/src/main/java/dev/jorel/commandapi/test/MockNMS.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,32 @@ public CommandSourceStack getBrigadierSourceFromCommandSender(AbstractCommandSen
355355
Mockito.when(css.getPosition()).thenReturn(new Vec3(0, 0, 0));
356356
Mockito.when(css.getRotation()).thenReturn(new Vec2(0, 0));
357357
}
358+
359+
// NativeProxyCommandSender construction (NMS#createNativeProxyCommandSender)
360+
// Make sure these builder methods work as expected
361+
Mockito.when(css.withPosition(any())).thenAnswer(invocation -> {
362+
Mockito.when(css.getPosition()).thenReturn(invocation.getArgument(0));
363+
return css;
364+
});
365+
Mockito.when(css.withRotation(any())).thenAnswer(invocation -> {
366+
Mockito.when(css.getRotation()).thenReturn(invocation.getArgument(0));
367+
return css;
368+
});
369+
Mockito.when(css.withLevel(any())).thenAnswer(invocation -> {
370+
Mockito.when(css.getLevel()).thenReturn(invocation.getArgument(0));
371+
return css;
372+
});
373+
Mockito.when(css.withEntity(any())).thenAnswer(invocation -> {
374+
net.minecraft.world.entity.Entity entity = invocation.getArgument(0);
375+
String name = entity.getName().getString();
376+
net.minecraft.network.chat.Component displayName = entity.getDisplayName();
377+
378+
Mockito.when(css.getEntity()).thenReturn(entity);
379+
Mockito.when(css.getTextName()).thenReturn(name);
380+
Mockito.when(css.getDisplayName()).thenReturn(displayName);
381+
return css;
382+
});
383+
358384
return css;
359385
}
360386

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl/src/main/java/dev/jorel/commandapi/test/MockPlatform.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
package dev.jorel.commandapi.test;
22

3+
import com.google.gson.JsonObject;
4+
import com.google.gson.JsonParser;
5+
import com.mojang.brigadier.CommandDispatcher;
6+
import com.mojang.brigadier.context.CommandContext;
7+
import com.mojang.brigadier.context.ParsedArgument;
8+
import dev.jorel.commandapi.CommandAPIBukkit;
9+
import dev.jorel.commandapi.SafeVarHandle;
10+
import dev.jorel.commandapi.wrappers.ParticleData;
11+
import org.bukkit.NamespacedKey;
12+
import org.bukkit.Particle;
13+
import org.bukkit.Sound;
14+
import org.bukkit.entity.Player;
15+
import org.bukkit.inventory.ItemFactory;
16+
import org.bukkit.inventory.ItemStack;
17+
import org.bukkit.potion.PotionEffectType;
18+
319
import java.io.BufferedReader;
420
import java.io.IOException;
521
import java.io.InputStream;
@@ -15,27 +31,10 @@
1531
import java.util.stream.Stream;
1632

1733
import org.bukkit.Keyed;
18-
import org.bukkit.NamespacedKey;
19-
import org.bukkit.Particle;
2034
import org.bukkit.Registry;
21-
import org.bukkit.Sound;
22-
import org.bukkit.entity.Player;
23-
import org.bukkit.inventory.ItemFactory;
24-
import org.bukkit.inventory.ItemStack;
25-
import org.bukkit.potion.PotionEffectType;
2635
import org.jetbrains.annotations.NotNull;
2736
import org.jetbrains.annotations.Nullable;
2837

29-
import com.google.gson.JsonObject;
30-
import com.google.gson.JsonParser;
31-
import com.mojang.brigadier.CommandDispatcher;
32-
import com.mojang.brigadier.context.CommandContext;
33-
import com.mojang.brigadier.context.ParsedArgument;
34-
35-
import dev.jorel.commandapi.CommandAPIBukkit;
36-
import dev.jorel.commandapi.SafeVarHandle;
37-
import dev.jorel.commandapi.wrappers.ParticleData;
38-
3938
public abstract class MockPlatform<CLW> extends CommandAPIBukkit<CLW> {
4039
/*****************
4140
* Instantiation *

0 commit comments

Comments
 (0)