use of js.JsTest 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.JsTest 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");
}
use of js.JsTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testGUI.
@Test
public void testGUI() throws Exception {
IPlayer vip = mock(IPlayer.class);
TriggerReactorCore tr = mock(TriggerReactorCore.class);
AbstractInventoryTriggerManager invManager = mock(AbstractInventoryTriggerManager.class);
IInventory iInv = mock(IInventory.class);
JsTest test = new ExecutorTest(engine, "GUI").addVariable("player", vip).addVariable("plugin", tr);
when(tr.getInvManager()).thenReturn(invManager);
when(invManager.openGUI(vip, "Hi")).thenReturn(iInv);
test.withArgs("Hi").test();
verify(invManager).openGUI(vip, "Hi");
assertJSError(() -> test.withArgs().test(), "Invalid parameters. Need [String]");
when(invManager.openGUI(vip, "hello")).thenReturn(null);
assertJSError(() -> test.withArgs("hello").test(), "No such Inventory Trigger named hello");
}
use of js.JsTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testClearEntity.
@Test
public void testClearEntity() throws Exception {
Player player = mock(Player.class);
List<Entity> entities = new ArrayList<>();
for (int i = 0; i < 10; i++) {
entities.add(mock(Entity.class));
}
JsTest test = new ExecutorTest(engine, "CLEARENTITY").addVariable("player", player);
when(player.getNearbyEntities(2d, 2d, 2d)).thenReturn(entities);
test.withArgs(2).test();
for (Entity ve : entities) {
verify(ve).remove();
}
assertJSError(() -> test.withArgs().test(), "Invalid parameters! [Number]");
assertJSError(() -> test.withArgs("NO").test(), "Invalid parameters! [Number]");
}
use of js.JsTest 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");
}
Aggregations