Search in sources :

Example 21 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testSetHeldItem.

@Test
public void testSetHeldItem() throws Exception {
    Player player = mock(Player.class);
    ItemStack vItem = mock(ItemStack.class);
    PlayerInventory piv = mock(PlayerInventory.class);
    ExecutorTest test = new ExecutorTest(engine, "SETHELDITEM");
    test.addVariable("player", player);
    when(player.getInventory()).thenReturn(piv);
    test.withArgs(vItem).test();
    verify(piv).setItemInHand(vItem);
    Assert.assertEquals(0, test.getOverload(vItem));
    test.assertInvalid(0);
    test.assertInvalid("NUUP");
    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 22 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testPlayer_SetFood.

@Test
public void testPlayer_SetFood() throws Exception {
    Player player = mock(Player.class);
    JsTest test = new ExecutorTest(engine, "SETFOOD").addVariable("player", player);
    // case1
    test.withArgs(3).test();
    verify(player).setFoodLevel(3);
    // case2
    test.withArgs(4.0).test();
    verify(player).setFoodLevel(4);
    // Unexpected Cases
    assertJSError(() -> test.withArgs().test(), "Incorrect Number of arguments for Executor SETFOOD");
    assertJSError(() -> test.withArgs("HI").test(), "Invalid argument for Executor SETFOOD: HI");
    assertJSError(() -> test.withArgs(3.4).test(), "Argument for Executor SETFOOD should be a whole number");
    assertJSError(() -> test.withArgs(-3.0).test(), "Argument for Executor SETFOOD 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)

Example 23 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testBroadcast.

@Test
public void testBroadcast() throws Exception {
    Collection<Player> players = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        players.add(mock(Player.class));
    }
    String message = "&cHey all";
    String colored = ChatColor.translateAlternateColorCodes('&', message);
    doReturn(players).when(server).getOnlinePlayers();
    new ExecutorTest(engine, "BROADCAST").withArgs(message).test();
    for (Player mockPlayer : players) {
        verify(mockPlayer).sendMessage(argThat((String s) -> colored.equals(s)));
    }
}
Also used : Player(org.bukkit.entity.Player) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) ArrayList(java.util.ArrayList) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 24 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testLeverOn.

@Test
public void testLeverOn() 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, "LEVERON");
    when(vLoc.getBlock()).thenReturn(vBlock);
    when(vBlock.getState()).thenReturn(vBS);
    when(vBS.getData()).thenReturn(vLever);
    test.withArgs(vLoc).test();
    verify(vLever).setPowered(true);
    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 25 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testPlayer_SetXp.

@Test
public void testPlayer_SetXp() throws Exception {
    Player player = mock(Player.class);
    JsTest test = new ExecutorTest(engine, "SETXP").addVariable("player", player);
    // case1
    test.withArgs(0.3).test();
    verify(player).setExp(0.3F);
    // case2
    test.withArgs(1).test();
    verify(player).setExp(1.0F);
    // Unexpected Cases
    assertJSError(() -> test.withArgs().test(), "Incorrect number of arguments for executor SETXP");
    assertJSError(() -> test.withArgs("lmao").test(), "Invalid argument for SETXP: lmao");
    assertJSError(() -> test.withArgs(33).test(), "33 is outside of the allowable range of 0..1 for executor SETXP");
}
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