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));
}
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));
}
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));
}
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.");
}
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");
}
Aggregations