Search in sources :

Example 26 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testSetBlock2_1.

@Test
public void testSetBlock2_1() throws Exception {
    // {block id} {block data} {Location instance}
    World mockWorld = mock(World.class);
    Player player = mock(Player.class);
    Block block = mock(Block.class);
    when(player.getWorld()).thenReturn(mockWorld);
    when(mockWorld.getBlockAt(any(Location.class))).thenReturn(block);
    when(server.getWorld("world")).thenReturn(mockWorld);
    new ExecutorTest(engine, "SETBLOCK").addVariable("player", player).withArgs("GLASS", 2, new Location(mockWorld, 33, 96, -15)).test();
    verify(block).setType(eq(Material.GLASS));
}
Also used : Player(org.bukkit.entity.Player) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) Block(org.bukkit.block.Block) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 27 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testPlayer_SetFlySpeed.

@Test
public void testPlayer_SetFlySpeed() throws Exception {
    Player player = mock(Player.class);
    JsTest test = new ExecutorTest(engine, "SETFLYSPEED").addVariable("player", player);
    // only case
    test.withArgs(0.5).test();
    verify(player).setFlySpeed(0.5F);
    // Unexpected cases
    assertJSError(() -> test.withArgs().test(), "Incorrect Number of arguments for Executor SETFLYSPEED");
    assertJSError(() -> test.withArgs(0.5, 13).test(), "Incorrect Number of arguments for Executor SETFLYSPEED");
    assertJSError(() -> test.withArgs("HI").test(), "Invalid argument for SETFLYSPEED: HI");
    assertJSError(() -> test.withArgs(4).test(), "Argument for Executor SETFLYSPEED is outside of range -1..1");
    assertJSError(() -> test.withArgs(-4).test(), "Argument for Executor SETFLYSPEED is outside of range -1..1");
}
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 28 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testPlayer_SetGameMode.

@Test
public void testPlayer_SetGameMode() throws Exception {
    Player player = mock(Player.class);
    JsTest test = new ExecutorTest(engine, "SETGAMEMODE").addVariable("player", player);
    // only case
    test.withArgs("creative").test();
    verify(player).setGameMode(GameMode.valueOf("CREATIVE"));
    // case2
    test.withArgs(2).test();
    verify(player).setGameMode(GameMode.valueOf("ADVENTURE"));
    // Unexpected Cases
    assertJSError(() -> test.withArgs().test(), "Incorrect number of arguments for executor SETGAMEMODE");
    assertJSError(() -> test.withArgs(34).test(), "Invalid argument for Executor SETGAMEMODE: 34");
    assertJSError(() -> test.withArgs("hElLo").test(), "Unknown GAEMMODE value hElLo");
}
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 29 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testServer.

@Test
public void testServer() throws Exception {
    BukkitTriggerReactorCore plugin = mock(BukkitTriggerReactorCore.class);
    AbstractJavaPlugin.BungeeCordHelper helper = mock(AbstractJavaPlugin.BungeeCordHelper.class);
    Player player = mock(Player.class);
    when(plugin.getBungeeHelper()).thenReturn(helper);
    new ExecutorTest(engine, "SERVER").addVariable("player", player).addVariable("plugin", plugin).withArgs("someServer").test();
    verify(helper).sendToServer(player, "someServer");
}
Also used : Player(org.bukkit.entity.Player) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) BukkitTriggerReactorCore(io.github.wysohn.triggerreactor.bukkit.main.BukkitTriggerReactorCore) AbstractJavaPlugin(io.github.wysohn.triggerreactor.bukkit.main.AbstractJavaPlugin) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 30 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testMessageNull.

@Test
public void testMessageNull() throws Exception {
    Player mockPlayer = mock(Player.class);
    new ExecutorTest(engine, "MESSAGE").addVariable("player", mockPlayer).withArgs(new Object[] { null }).test();
    String expected = "null";
    verify(mockPlayer).sendMessage(argThat((String str) -> expected.equals(str)));
}
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)

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