Search in sources :

Example 31 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testSetSlot.

@Test
public void testSetSlot() throws Exception {
    InventoryClickEvent vEvent = mock(InventoryClickEvent.class);
    Inventory vInv = mock(Inventory.class);
    ItemStack vItem = mock(ItemStack.class);
    when(vEvent.getInventory()).thenReturn(vInv);
    when(vInv.getSize()).thenReturn(36);
    ExecutorTest test = new ExecutorTest(engine, "SETSLOT");
    test.addVariable("event", vEvent);
    test.withArgs(1, vItem).test();
    verify(vInv).setItem(1, vItem);
    test.assertValid(33, vItem);
    test.assertInvalid("hi", vItem);
    test.assertInvalid(0);
    test.assertInvalid("NOPE");
    test.assertInvalid(true, 0);
}
Also used : InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) PlayerInventory(org.bukkit.inventory.PlayerInventory) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 32 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testClearChat.

@Test
public void testClearChat() throws Exception {
    Player player = mock(Player.class);
    Player player2 = mock(Player.class);
    Player nullP = null;
    JsTest test = new ExecutorTest(engine, "CLEARCHAT").addVariable("player", player);
    // case1
    test.withArgs().test();
    verify(player, times(30)).sendMessage("");
    // case2
    test.withArgs(player2).test();
    verify(player2, times(30)).sendMessage("");
    // Unexpected Cases
    assertJSError(() -> test.withArgs(nullP).test(), "Found unexpected parameter - player: null");
    assertJSError(() -> test.withArgs(1, 2).test(), "Too many parameters found! CLEARCHAT accept up to one parameter.");
}
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 33 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testPlayer_SetMaxHealth.

@SuppressWarnings("deprecation")
@Test
public void testPlayer_SetMaxHealth() throws Exception {
    Player player = mock(Player.class);
    JsTest test = new ExecutorTest(engine, "SETMAXHEALTH").addVariable("player", player);
    // case1
    test.withArgs(30).test();
    verify(player).setMaxHealth(30.0);
    // case2
    test.withArgs(35.4).test();
    verify(player).setMaxHealth(35.4);
    // Unexpected Cases
    assertJSError(() -> test.withArgs(20, 33).test(), "Incorrect Number of arguments for Executor SETMAXHEALTH");
    assertJSError(() -> test.withArgs("NONO").test(), "Invalid argument for SETMAXHEALTH: NONO");
    assertJSError(() -> test.withArgs(-30).test(), "Argument for Executor SETMAXHEALTH should not be negative or zero");
    assertJSError(() -> test.withArgs(2098).test(), "Maximum health cannot be greater than 2048");
}
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 34 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testClearPotion.

@Test
public void testClearPotion() throws Exception {
    Player p = mock(Player.class);
    ExecutorTest test = new ExecutorTest(engine, "CLEARPOTION");
    test.addVariable("player", p);
    test.test();
    Assert.assertEquals(0, test.getOverload());
    Assert.assertEquals(1, test.getOverload("SPEED"));
    Assert.assertFalse(test.isValid(0));
    Assert.assertFalse(test.isValid("SPEED", "SPEED"));
}
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 35 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testWeather.

@Test
public void testWeather() throws Exception {
    JsTest test = new ExecutorTest(engine, "WEATHER");
    World mockWorld = mock(World.class);
    when(server.getWorld("merp")).thenReturn(mockWorld);
    test.withArgs("merp", true).test();
    verify(mockWorld).setStorm(true);
    when(server.getWorld("merp")).thenReturn(null);
    assertJSError(() -> test.withArgs("merp", true, true).test(), "Invalid parameters! [String, Boolean]");
    assertJSError(() -> test.withArgs("merp", 1).test(), "Invalid parameters! [String, Boolean]");
    assertJSError(() -> test.withArgs(mockWorld, false).test(), "Invalid parameters! [String, Boolean]");
    assertJSError(() -> test.withArgs("merp", true).test(), "Unknown world named merp");
}
Also used : 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