Search in sources :

Example 1 with DummyCommandSender

use of com.builtbroken.mc.testing.junit.testers.DummyCommandSender in project ICBM-Classic by BuiltBrokenModding.

the class CommandUtilsTest method getNumber_playerTilde_zero.

@Test
void getNumber_playerTilde_zero() throws WrongUsageException {
    final DummyCommandSender dummyCommandSender = new DummyCommandSender(testManager);
    double result = CommandUtils.getNumber(dummyCommandSender, "~", 100);
    Assertions.assertEquals(100.0, result);
}
Also used : DummyCommandSender(com.builtbroken.mc.testing.junit.testers.DummyCommandSender) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with DummyCommandSender

use of com.builtbroken.mc.testing.junit.testers.DummyCommandSender in project ICBM-Classic by BuiltBrokenModding.

the class CommandRemoveTest method command_removeMissiles.

@ParameterizedTest
@MethodSource("provideArgsToTest")
void command_removeMissiles(String[] args, boolean removeMissile) {
    dummyCommandSender.position = new Vec3d(100, 20, 100);
    // Spawn some sheep to act as decoys
    TestUtils.sheep(testManager.getWorld(), 100, 20, 100);
    TestUtils.sheep(testManager.getWorld(), 100, 30, 100);
    TestUtils.sheep(testManager.getWorld(), 100, 40, 100);
    TestUtils.missile(testManager.getWorld(), 100, 10, 100);
    TestUtils.missile(testManager.getWorld(), 100, 20, 100);
    // Validate start condition
    Assertions.assertEquals(3, testManager.getWorld().loadedEntityList.stream().filter(e -> e instanceof EntitySheep).count(), "Should start with 3 sheep");
    Assertions.assertEquals(2, testManager.getWorld().loadedEntityList.stream().filter(e -> e instanceof EntityMissile).count(), "Should start with 2 missiles");
    // Trigger command
    Assertions.assertDoesNotThrow(() -> command.handleCommand(testManager.getServer(), dummyCommandSender, args));
    // Validate output
    Assertions.assertEquals(1, dummyCommandSender.messages.size(), "Should have 1 chat message");
    Assertions.assertEquals(CommandRemove.TRANSLATION_REMOVE, dummyCommandSender.pollLastMessage(), "Should get translation");
    // Should still have 3 sheep
    Assertions.assertEquals(3, testManager.getWorld().loadedEntityList.stream().filter(e -> e instanceof EntitySheep).count(), "Should end with 3 sheep");
    Assertions.assertEquals(removeMissile ? 0 : 2, testManager.getWorld().loadedEntityList.stream().filter(e -> e instanceof EntityMissile).filter(Entity::isEntityAlive).count(), "Should end with 0 missiles");
}
Also used : Entity(net.minecraft.entity.Entity) TestManager(com.builtbroken.mc.testing.junit.TestManager) Arguments(org.junit.jupiter.params.provider.Arguments) EntityMissile(icbm.classic.content.entity.missile.EntityMissile) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) EntitySheep(net.minecraft.entity.passive.EntitySheep) DummyCommandSender(com.builtbroken.mc.testing.junit.testers.DummyCommandSender) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) Vec3d(net.minecraft.util.math.Vec3d) WrongUsageException(net.minecraft.command.WrongUsageException) ICBMCommands(icbm.classic.command.ICBMCommands) Assertions(org.junit.jupiter.api.Assertions) TestUtils(icbm.classic.TestUtils) MethodSource(org.junit.jupiter.params.provider.MethodSource) Entity(net.minecraft.entity.Entity) EntitySheep(net.minecraft.entity.passive.EntitySheep) Vec3d(net.minecraft.util.math.Vec3d) EntityMissile(icbm.classic.content.entity.missile.EntityMissile) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with DummyCommandSender

use of com.builtbroken.mc.testing.junit.testers.DummyCommandSender in project ICBM-Classic by BuiltBrokenModding.

the class CommandEntryPointTest method getTabCompletions_zero.

@Test
void getTabCompletions_zero() {
    final DummyCommandSender dummyCommandSender = new DummyCommandSender(testManager);
    List<String> output = commandHandler.getTabCompletions(testManager.getServer(), dummyCommandSender, new String[0], null);
    Assertions.assertEquals(0, output.size());
}
Also used : DummyCommandSender(com.builtbroken.mc.testing.junit.testers.DummyCommandSender) TextComponentString(net.minecraft.util.text.TextComponentString) Test(org.junit.jupiter.api.Test)

Example 4 with DummyCommandSender

use of com.builtbroken.mc.testing.junit.testers.DummyCommandSender in project ICBM-Classic by BuiltBrokenModding.

the class CommandEntryPointTest method getTabCompletions_help.

@Test
void getTabCompletions_help() {
    final DummyCommandSender dummyCommandSender = new DummyCommandSender(testManager);
    List<String> output = commandHandler.getTabCompletions(testManager.getServer(), dummyCommandSender, new String[] { "h" }, null);
    Assertions.assertEquals(1, output.size());
    Assertions.assertEquals(output.get(0), "help");
}
Also used : DummyCommandSender(com.builtbroken.mc.testing.junit.testers.DummyCommandSender) TextComponentString(net.minecraft.util.text.TextComponentString) Test(org.junit.jupiter.api.Test)

Example 5 with DummyCommandSender

use of com.builtbroken.mc.testing.junit.testers.DummyCommandSender in project ICBM-Classic by BuiltBrokenModding.

the class CommandEntryPointTest method execute_nothing.

@Test
void execute_nothing() throws CommandException {
    final DummyCommandSender dummyCommandSender = new DummyCommandSender(testManager);
    // Run command
    commandHandler.execute(testManager.getServer(), dummyCommandSender, new String[0]);
    Assertions.assertEquals(1, dummyCommandSender.messages.size());
    Assertions.assertEquals("/icbm help", dummyCommandSender.messages.poll().getUnformattedText());
}
Also used : DummyCommandSender(com.builtbroken.mc.testing.junit.testers.DummyCommandSender) Test(org.junit.jupiter.api.Test)

Aggregations

DummyCommandSender (com.builtbroken.mc.testing.junit.testers.DummyCommandSender)9 Test (org.junit.jupiter.api.Test)9 TextComponentString (net.minecraft.util.text.TextComponentString)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 TestManager (com.builtbroken.mc.testing.junit.TestManager)2 TestUtils (icbm.classic.TestUtils)2 EntityMissile (icbm.classic.content.entity.missile.EntityMissile)2 Entity (net.minecraft.entity.Entity)2 EntitySheep (net.minecraft.entity.passive.EntitySheep)2 Vec3d (net.minecraft.util.math.Vec3d)2 AfterAll (org.junit.jupiter.api.AfterAll)2 AfterEach (org.junit.jupiter.api.AfterEach)2 Assertions (org.junit.jupiter.api.Assertions)2 FakeBlast (icbm.classic.command.FakeBlast)1 ICBMCommands (icbm.classic.command.ICBMCommands)1 ExplosiveHandler (icbm.classic.lib.explosive.ExplosiveHandler)1 ExplosiveRegistry (icbm.classic.lib.explosive.reg.ExplosiveRegistry)1 Stream (java.util.stream.Stream)1 WrongUsageException (net.minecraft.command.WrongUsageException)1 ResourceLocation (net.minecraft.util.ResourceLocation)1