Search in sources :

Example 46 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testSetOffHand.

@Test
public void testSetOffHand() throws Exception {
    Player player = mock(Player.class);
    ItemStack vItem = mock(ItemStack.class);
    PlayerInventory vInv = mock(PlayerInventory.class);
    ExecutorTest test = new ExecutorTest(engine, "SETOFFHAND");
    test.addVariable("player", player);
    when(player.getInventory()).thenReturn(vInv);
    test.withArgs(vItem).test();
    verify(vInv).setItemInOffHand(vItem);
    test.assertInvalid(0);
    test.assertInvalid("HELLO");
    test.assertInvalid(true);
}
Also used : Player(org.bukkit.entity.Player) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) PlayerInventory(org.bukkit.inventory.PlayerInventory) ItemStack(org.bukkit.inventory.ItemStack) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 47 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testSetCount.

@Test
public void testSetCount() throws Exception {
    ItemStack vItem = mock(ItemStack.class);
    Material stone = Material.valueOf("STONE");
    when(vItem.getType()).thenReturn(stone);
    ExecutorTest test = new ExecutorTest(engine, "SETCOUNT");
    test.withArgs(3, vItem).test();
    verify(vItem).setAmount(3);
    test.assertValid(1, vItem);
    test.assertInvalid(1, 3);
    test.assertInvalid("h", "d");
    test.assertInvalid(vItem, 2);
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 48 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testLightning.

@Test
public void testLightning() throws Exception {
    Location vLoc = mock(Location.class);
    World vWorld = mock(World.class);
    JsTest test = new ExecutorTest(engine, "LIGHTNING");
    when(vLoc.getWorld()).thenReturn(vWorld);
    test.withArgs(vLoc).test();
    verify(vWorld).strikeLightning(vLoc);
    assertJSError(() -> test.withArgs().test(), "Invalid parameters! [String, Number, Number, Number] or [Location]");
    assertJSError(() -> test.withArgs("hff").test(), "Invalid parameters! [String, Number, Number, Number] or [Location]");
// TODO - need test for the situation of args.length == 4
}
Also used : JsTest(js.JsTest) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 49 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testPlayer_SetFlyMode.

@Test
public void testPlayer_SetFlyMode() throws Exception {
    Player mockPlayer = mock(Player.class);
    JsTest test = new ExecutorTest(engine, "SETFLYMODE").addVariable("player", mockPlayer);
    for (boolean b : new boolean[] { true, false }) {
        test.withArgs(b).test();
        verify(mockPlayer).setAllowFlight(eq(b));
        verify(mockPlayer).setFlying(eq(b));
    }
    assertJSError(() -> test.withArgs(true, true).test(), "Incorrect number of arguments for executor SETFLYMODE");
    assertJSError(() -> test.withArgs("merp").test(), "Invalid argument for executor SETFLYMODE: merp");
}
Also used : Player(org.bukkit.entity.Player) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) JsTest(js.JsTest) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 50 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testVelocity.

@Test
public void testVelocity() throws Exception {
    Player player = mock(Player.class);
    new ExecutorTest(engine, "VELOCITY").withArgs(1, -2, 3).addVariable("player", player).test();
    verify(player).setVelocity(new Vector(1, -2, 3));
}
Also used : Player(org.bukkit.entity.Player) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) Vector(org.bukkit.util.Vector) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Aggregations

ExecutorTest (js.ExecutorTest)63 JsTest (js.JsTest)61 Test (org.junit.Test)60 Player (org.bukkit.entity.Player)48 IPlayer (io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer)43 Block (org.bukkit.block.Block)16 ItemStack (org.bukkit.inventory.ItemStack)11 Location (org.bukkit.Location)6 World (org.bukkit.World)5 PlayerInventory (org.bukkit.inventory.PlayerInventory)5 BlockState (org.bukkit.block.BlockState)4 ArrayList (java.util.ArrayList)3 Entity (org.bukkit.entity.Entity)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 Lever (org.bukkit.material.Lever)3 BukkitTriggerReactorCore (io.github.wysohn.triggerreactor.bukkit.main.BukkitTriggerReactorCore)2 IInventory (io.github.wysohn.triggerreactor.core.bridge.IInventory)2 AbstractJavaPlugin (io.github.wysohn.triggerreactor.bukkit.main.AbstractJavaPlugin)1 VaultSupport (io.github.wysohn.triggerreactor.bukkit.manager.trigger.share.api.vault.VaultSupport)1 TriggerReactorCore (io.github.wysohn.triggerreactor.core.main.TriggerReactorCore)1