Search in sources :

Example 41 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testSetItemLore.

@Test
public void testSetItemLore() throws Exception {
    ItemStack vItem = mock(ItemStack.class);
    ItemMeta vIM = mock(ItemMeta.class);
    ExecutorTest test = new ExecutorTest(engine, "SETITEMLORE");
    when(vItem.getItemMeta()).thenReturn(vIM);
    test.withArgs("NO\nNO", vItem).test();
    verify(vItem).setItemMeta(vIM);
    test.assertValid("herllo", vItem);
    test.assertInvalid(0);
    test.assertInvalid("HELLO");
    test.assertInvalid(0, "hu");
    test.assertInvalid(true, 0);
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 42 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testFallingBlock.

@Test
public void testFallingBlock() throws Exception {
    Player player = mock(Player.class);
    World world = mock(World.class);
    when(player.getWorld()).thenReturn(world);
    new ExecutorTest(engine, "FALLINGBLOCK").addVariable("player", player).withArgs("STONE", 44.5, 6, 78.9).test();
    verify(world).spawnFallingBlock(new Location(world, 44.5, 6, 78.9), Material.STONE, (byte) 0);
}
Also used : Player(org.bukkit.entity.Player) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 43 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testTppos.

@Test
public void testTppos() throws Exception {
    Player player = mock(Player.class);
    World world = mock(World.class);
    Location location = new Location(world, 1, 1, 1);
    when(player.getWorld()).thenReturn(world);
    when(player.getLocation()).thenReturn(location);
    new ExecutorTest(engine, "TPPOS").withArgs("~33 ~-2 ~9").addVariable("player", player).test();
    verify(player).teleport(new Location(world, 1 + 33, 1 - 2, 1 + 9));
}
Also used : Player(org.bukkit.entity.Player) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 44 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testLeverOff.

@Test
public void testLeverOff() throws Exception {
    Location vLoc = mock(Location.class);
    Block vBlock = mock(Block.class);
    BlockState vBS = mock(BlockState.class);
    Lever vLever = mock(Lever.class);
    JsTest test = new ExecutorTest(engine, "LEVEROFF");
    when(vLoc.getBlock()).thenReturn(vBlock);
    when(vBlock.getState()).thenReturn(vBS);
    when(vBS.getData()).thenReturn(vLever);
    test.withArgs(vLoc).test();
    verify(vLever).setPowered(false);
    assertJSError(() -> test.withArgs().test(), "Invalid parameters. Need [Location<location or number number number>]");
// TODO - need test for the situation of args.length == 3
}
Also used : BlockState(org.bukkit.block.BlockState) Lever(org.bukkit.material.Lever) Block(org.bukkit.block.Block) JsTest(js.JsTest) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 45 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testPlayer_SetSaturation.

@Test
public void testPlayer_SetSaturation() throws Exception {
    Player player = mock(Player.class);
    JsTest test = new ExecutorTest(engine, "SETSATURATION").addVariable("player", player);
    // case1
    test.withArgs(25).test();
    verify(player).setSaturation(25.0F);
    // case2
    test.withArgs(44.0).test();
    verify(player).setSaturation(44.0F);
    // Unexpected Cases
    assertJSError(() -> test.withArgs().test(), "Incorrect Number of arguments for Executor SETSATURATION");
    assertJSError(() -> test.withArgs("Hi").test(), "Invalid argument for SETSATURATION: Hi");
    assertJSError(() -> test.withArgs(-45).test(), "Argument for Executor SETSATURATION should not be negative");
}
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)

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