Search in sources :

Example 6 with DummyCommandSender

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

the class CommandUtilsTest method getNumber_playerTilde_offset.

@Test
void getNumber_playerTilde_offset() throws WrongUsageException {
    final DummyCommandSender dummyCommandSender = new DummyCommandSender(testManager);
    double result = CommandUtils.getNumber(dummyCommandSender, "~3", 100);
    Assertions.assertEquals(103.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 7 with DummyCommandSender

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

the class CommandEntryPointTest method getTabCompletions_nothing.

@Test
void getTabCompletions_nothing() {
    final DummyCommandSender dummyCommandSender = new DummyCommandSender(testManager);
    List<String> output = commandHandler.getTabCompletions(testManager.getServer(), dummyCommandSender, new String[] { "a" }, 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 8 with DummyCommandSender

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

the class CommandLagTest method command_removeMissiles.

@Test
void command_removeMissiles() {
    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, 10, -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, new String[0]));
    // Validate output
    Assertions.assertEquals(1, dummyCommandSender.messages.size(), "Should have 1 chat message");
    Assertions.assertEquals(CommandLag.TRANSLATION_LAG_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(0, 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) FakeBlast(icbm.classic.command.FakeBlast) TestManager(com.builtbroken.mc.testing.junit.TestManager) 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) ExplosiveHandler(icbm.classic.lib.explosive.ExplosiveHandler) Vec3d(net.minecraft.util.math.Vec3d) Assertions(org.junit.jupiter.api.Assertions) TestUtils(icbm.classic.TestUtils) Entity(net.minecraft.entity.Entity) EntitySheep(net.minecraft.entity.passive.EntitySheep) Vec3d(net.minecraft.util.math.Vec3d) EntityMissile(icbm.classic.content.entity.missile.EntityMissile) Test(org.junit.jupiter.api.Test)

Example 9 with DummyCommandSender

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

the class CommandBlastListTest method listBlasts.

@Test
void listBlasts() throws CommandException {
    // Setup blast registry
    ICBMClassicAPI.EXPLOSIVE_REGISTRY = new ExplosiveRegistry();
    ICBMClassicAPI.EXPLOSIVE_REGISTRY.register(new ResourceLocation("tree", "bat"), EnumTier.FOUR, () -> null);
    ICBMClassicAPI.EXPLOSIVE_REGISTRY.register(new ResourceLocation("tree", "cat"), EnumTier.FOUR, () -> null);
    ICBMClassicAPI.EXPLOSIVE_REGISTRY.register(new ResourceLocation("bo", "fat"), EnumTier.FOUR, () -> null);
    ((ExplosiveRegistry) ICBMClassicAPI.EXPLOSIVE_REGISTRY).lockNewExplosives();
    final DummyCommandSender dummyCommandSender = new DummyCommandSender(testManager);
    // Trigger
    commandBlastList.handleCommand(testManager.getServer(), dummyCommandSender, new String[0]);
    // Should only have 1 message to sender
    Assertions.assertEquals(1, dummyCommandSender.messages.size());
    Assertions.assertEquals("Explosive Types: bo:fat, tree:bat, tree:cat", dummyCommandSender.messages.poll().getUnformattedText());
    // Cleanup
    ICBMClassicAPI.EXPLOSIVE_REGISTRY = null;
}
Also used : DummyCommandSender(com.builtbroken.mc.testing.junit.testers.DummyCommandSender) ExplosiveRegistry(icbm.classic.lib.explosive.reg.ExplosiveRegistry) ResourceLocation(net.minecraft.util.ResourceLocation) 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