Search in sources :

Example 11 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testGive.

@Test
public void testGive() throws Exception {
    Player player = mock(Player.class);
    PlayerInventory playerInv = mock(PlayerInventory.class);
    ItemStack vItem = mock(ItemStack.class);
    JsTest test = new ExecutorTest(engine, "GIVE").addVariable("player", player);
    when(player.getInventory()).thenReturn(playerInv);
    when(playerInv.firstEmpty()).thenReturn(4);
    test.withArgs(vItem).test();
    verify(playerInv).addItem(vItem);
    assertJSError(() -> test.withArgs().test(), "Invalid parameters. Need [ItemStack]");
    when(playerInv.firstEmpty()).thenReturn(-1);
    assertJSError(() -> test.withArgs(vItem).test(), "Player has no empty slot.");
    when(playerInv.firstEmpty()).thenReturn(7);
    assertJSError(() -> test.withArgs("hi").test(), "Invalid ItemStack: hi");
}
Also used : Player(org.bukkit.entity.Player) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) JsTest(js.JsTest) PlayerInventory(org.bukkit.inventory.PlayerInventory) ItemStack(org.bukkit.inventory.ItemStack) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 12 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testPlayer_SetHealth.

@Test
public void testPlayer_SetHealth() throws Exception {
    Player player = mock(Player.class);
    JsTest test = new ExecutorTest(engine, "SETHEALTH").addVariable("player", player);
    when(player.getMaxHealth()).thenReturn(20.0);
    // case1
    test.withArgs(2).test();
    verify(player).setHealth(2.0);
    // case2
    test.withArgs(3.0).test();
    verify(player).setHealth(3.0);
    // Unexpected Cases
    assertJSError(() -> test.withArgs(1, 334).test(), "Incorrect Number of arguments for executor SETHEALTH");
    assertJSError(() -> test.withArgs("yeah").test(), "Invalid argument for SETHEALTH: yeah");
    assertJSError(() -> test.withArgs(-17).test(), "Argument for Exector SETHEALTH should not be negative");
    assertJSError(() -> test.withArgs(50).test(), "Argument for Executor SETHEALTH is greater than the max health");
}
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 13 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testCloseGUI.

@Test
public void testCloseGUI() throws Exception {
    Player player = mock(Player.class);
    JsTest test = new ExecutorTest(engine, "CLOSEGUI").addVariable("player", player);
    // only happy case
    test.withArgs().test();
    verify(player).closeInventory();
}
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 14 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testKick.

@Test
public void testKick() throws Exception {
    Player player = mock(Player.class);
    Player player2 = mock(Player.class);
    Player nullP = null;
    String msg = ChatColor.translateAlternateColorCodes('&', "&c[TR] You've been kicked from the server.");
    String msg2 = ChatColor.translateAlternateColorCodes('&', "&cKICKED");
    // case1
    ExecutorTest test = new ExecutorTest(engine, "KICK");
    test.addVariable("player", player);
    test.withArgs().test();
    verify(player).kickPlayer(msg);
    // case2
    test.withArgs(msg2).test();
    verify(player).kickPlayer(msg2);
    // case3
    test.withArgs(player2).test();
    verify(player2).kickPlayer(msg);
    // case4
    test.withArgs(player2, msg2).test();
    verify(player2).kickPlayer(msg2);
    // Unexpected Exception Cases
    test.assertInvalid(1);
    test.assertInvalid(player, 232);
    test.assertInvalid(1, 2, 3);
    test.addVariable("player", null);
    test.assertInvalid(null, "msg");
    test.assertInvalid(nullP);
    assertJSError(() -> test.withArgs().test(), "Too few arguments! You should enter at least on argument if you use KICK executor from console.");
}
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 15 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testSetPlayerInv.

@Test
public void testSetPlayerInv() throws Exception {
    Player player = mock(Player.class);
    ItemStack vItem = mock(ItemStack.class);
    PlayerInventory vInv = mock(PlayerInventory.class);
    when(player.getInventory()).thenReturn(vInv);
    when(vInv.getSize()).thenReturn(36);
    ExecutorTest test = new ExecutorTest(engine, "SETPLAYERINV");
    test.addVariable("player", player);
    test.withArgs(1, vItem).test();
    verify(vInv).setItem(1, vItem);
    test.assertInvalid(0);
    test.assertInvalid("HELLO");
    test.assertInvalid(0, "hu");
    test.assertInvalid(true, 0);
}
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)

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