Search in sources :

Example 1 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class TestExecutors method testSetBlockSetData1_2.

@Test
public void testSetBlockSetData1_2() throws Exception {
    // {block id} {block data} {x} {y} {z}
    World mockWorld = Mockito.mock(World.class);
    Player player = Mockito.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(4, 3, 33, 96, -15).test();
    verify(block).setType(eq(Material.COBBLESTONE));
    verify(block).setData(eq((byte) 3));
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) World(org.bukkit.World) Location(org.bukkit.Location) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) ExecutorTest(js.ExecutorTest) JsTest(js.JsTest)

Example 2 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class TestExecutors method testSetBlockSetData.

public void testSetBlockSetData() throws Exception {
    World mockWorld = Mockito.mock(World.class);
    Block mockBlock = mock(Block.class);
    JsTest test = new ExecutorTest(engine, "SETBLOCK");
    test.addVariable("block", mockBlock);
    when(server.getWorld("world")).thenReturn(mockWorld);
    test.withArgs(1).test();
    verify(mockBlock).setType(eq(Material.STONE));
    verify(mockBlock).setData(eq((byte) 0));
}
Also used : Block(org.bukkit.block.Block) JsTest(js.JsTest) World(org.bukkit.World) ExecutorTest(js.ExecutorTest)

Example 3 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class TestExecutors method testSetBlockSetData2.

@Test
public void testSetBlockSetData2() throws Exception {
    // {block id} {block data} {Location instance}
    World mockWorld = Mockito.mock(World.class);
    Player player = Mockito.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(3, 2, new Location(mockWorld, 33, 96, -15)).test();
    verify(block).setType(eq(Material.DIRT));
    verify(block).setData(eq((byte) 2));
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) World(org.bukkit.World) Location(org.bukkit.Location) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) ExecutorTest(js.ExecutorTest) JsTest(js.JsTest)

Example 4 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testSetBlock1.

@Test
public void testSetBlock1() throws Exception {
    // {block id} {x} {y} {z}
    World mockWorld = mock(World.class);
    Player player = mock(Player.class);
    when(player.getWorld()).thenReturn(mockWorld);
    when(server.getWorld("world")).thenReturn(mockWorld);
    assertJSError(() -> new ExecutorTest(engine, "SETBLOCK").withArgs("STONE", 22, 80, 33).test(), "cannot use #SETBLOCK in non-player related event. Or use Location instance.");
}
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 5 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testBurn.

@Test
public void testBurn() throws Exception {
    // happy cases
    Player mockPlayer = mock(Player.class);
    Entity mockEntity = mock(Entity.class);
    JsTest test = new ExecutorTest(engine, "BURN").addVariable("player", mockPlayer);
    test.withArgs(3).test();
    verify(mockPlayer).setFireTicks(60);
    test.withArgs(0.101).test();
    verify(mockPlayer).setFireTicks(2);
    test.withArgs(mockEntity, 1).test();
    verify(mockEntity).setFireTicks(20);
    when(server.getPlayer("merp")).thenReturn(mockPlayer);
    test.withArgs("merp", 5).test();
    verify(mockPlayer).setFireTicks(100);
    // sad cases
    when(server.getPlayer("merp")).thenReturn(null);
    assertJSError(() -> test.withArgs(-1).test(), "The number of seconds to burn should be positive");
    assertJSError(() -> test.withArgs().test(), "Invalid number of parameters. Need [Number] or [Entity<entity or string>, Number]");
    assertJSError(() -> test.withArgs(1, 1, 1).test(), "Invalid number of parameters. Need [Number] or [Entity<entity or string>, Number]");
    assertJSError(() -> test.withArgs(true).test(), "Invalid number for seconds to burn: true");
    assertJSError(() -> test.withArgs(null, 4).test(), "player to burn should not be null");
    assertJSError(() -> test.withArgs("merp", 3).test(), "player to burn does not exist");
    assertJSError(() -> test.withArgs(3, 3).test(), "invalid entity to burn: 3");
    assertJSError(() -> test.withArgs(mockEntity, "merp").test(), "The number of seconds to burn should be a number");
    assertJSError(() -> test.withArgs(mockEntity, -1).test(), "The number of seconds to burn should be positive");
}
Also used : Entity(org.bukkit.entity.Entity) 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