use of js.ExecutorTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testSetSlot.
@Test
public void testSetSlot() throws Exception {
InventoryClickEvent vEvent = mock(InventoryClickEvent.class);
Inventory vInv = mock(Inventory.class);
ItemStack vItem = mock(ItemStack.class);
when(vEvent.getInventory()).thenReturn(vInv);
when(vInv.getSize()).thenReturn(36);
ExecutorTest test = new ExecutorTest(engine, "SETSLOT");
test.addVariable("event", vEvent);
test.withArgs(1, vItem).test();
verify(vInv).setItem(1, vItem);
test.assertValid(33, vItem);
test.assertInvalid("hi", vItem);
test.assertInvalid(0);
test.assertInvalid("NOPE");
test.assertInvalid(true, 0);
}
use of js.ExecutorTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testClearChat.
@Test
public void testClearChat() throws Exception {
Player player = mock(Player.class);
Player player2 = mock(Player.class);
Player nullP = null;
JsTest test = new ExecutorTest(engine, "CLEARCHAT").addVariable("player", player);
// case1
test.withArgs().test();
verify(player, times(30)).sendMessage("");
// case2
test.withArgs(player2).test();
verify(player2, times(30)).sendMessage("");
// Unexpected Cases
assertJSError(() -> test.withArgs(nullP).test(), "Found unexpected parameter - player: null");
assertJSError(() -> test.withArgs(1, 2).test(), "Too many parameters found! CLEARCHAT accept up to one parameter.");
}
use of js.ExecutorTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testPlayer_SetMaxHealth.
@SuppressWarnings("deprecation")
@Test
public void testPlayer_SetMaxHealth() throws Exception {
Player player = mock(Player.class);
JsTest test = new ExecutorTest(engine, "SETMAXHEALTH").addVariable("player", player);
// case1
test.withArgs(30).test();
verify(player).setMaxHealth(30.0);
// case2
test.withArgs(35.4).test();
verify(player).setMaxHealth(35.4);
// Unexpected Cases
assertJSError(() -> test.withArgs(20, 33).test(), "Incorrect Number of arguments for Executor SETMAXHEALTH");
assertJSError(() -> test.withArgs("NONO").test(), "Invalid argument for SETMAXHEALTH: NONO");
assertJSError(() -> test.withArgs(-30).test(), "Argument for Executor SETMAXHEALTH should not be negative or zero");
assertJSError(() -> test.withArgs(2098).test(), "Maximum health cannot be greater than 2048");
}
use of js.ExecutorTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testClearPotion.
@Test
public void testClearPotion() throws Exception {
Player p = mock(Player.class);
ExecutorTest test = new ExecutorTest(engine, "CLEARPOTION");
test.addVariable("player", p);
test.test();
Assert.assertEquals(0, test.getOverload());
Assert.assertEquals(1, test.getOverload("SPEED"));
Assert.assertFalse(test.isValid(0));
Assert.assertFalse(test.isValid("SPEED", "SPEED"));
}
use of js.ExecutorTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testWeather.
@Test
public void testWeather() throws Exception {
JsTest test = new ExecutorTest(engine, "WEATHER");
World mockWorld = mock(World.class);
when(server.getWorld("merp")).thenReturn(mockWorld);
test.withArgs("merp", true).test();
verify(mockWorld).setStorm(true);
when(server.getWorld("merp")).thenReturn(null);
assertJSError(() -> test.withArgs("merp", true, true).test(), "Invalid parameters! [String, Boolean]");
assertJSError(() -> test.withArgs("merp", 1).test(), "Invalid parameters! [String, Boolean]");
assertJSError(() -> test.withArgs(mockWorld, false).test(), "Invalid parameters! [String, Boolean]");
assertJSError(() -> test.withArgs("merp", true).test(), "Unknown world named merp");
}
Aggregations