use of js.ExecutorTest 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");
}
use of js.ExecutorTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testPlayer_SetHealth.
@Test
public void testPlayer_SetHealth() throws Exception {
Player player = mock(Player.class);
JsTest test = new ExecutorTest(engine, "SETHEALTH").addVariable("player", player);
when(player.getMaxHealth()).thenReturn(20.0);
// case1
test.withArgs(2).test();
verify(player).setHealth(2.0);
// case2
test.withArgs(3.0).test();
verify(player).setHealth(3.0);
// Unexpected Cases
assertJSError(() -> test.withArgs(1, 334).test(), "Incorrect Number of arguments for executor SETHEALTH");
assertJSError(() -> test.withArgs("yeah").test(), "Invalid argument for SETHEALTH: yeah");
assertJSError(() -> test.withArgs(-17).test(), "Argument for Exector SETHEALTH should not be negative");
assertJSError(() -> test.withArgs(50).test(), "Argument for Executor SETHEALTH is greater than the max health");
}
use of js.ExecutorTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testCloseGUI.
@Test
public void testCloseGUI() throws Exception {
Player player = mock(Player.class);
JsTest test = new ExecutorTest(engine, "CLOSEGUI").addVariable("player", player);
// only happy case
test.withArgs().test();
verify(player).closeInventory();
}
use of js.ExecutorTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testKick.
@Test
public void testKick() throws Exception {
Player player = mock(Player.class);
Player player2 = mock(Player.class);
Player nullP = null;
String msg = ChatColor.translateAlternateColorCodes('&', "&c[TR] You've been kicked from the server.");
String msg2 = ChatColor.translateAlternateColorCodes('&', "&cKICKED");
// case1
ExecutorTest test = new ExecutorTest(engine, "KICK");
test.addVariable("player", player);
test.withArgs().test();
verify(player).kickPlayer(msg);
// case2
test.withArgs(msg2).test();
verify(player).kickPlayer(msg2);
// case3
test.withArgs(player2).test();
verify(player2).kickPlayer(msg);
// case4
test.withArgs(player2, msg2).test();
verify(player2).kickPlayer(msg2);
// Unexpected Exception Cases
test.assertInvalid(1);
test.assertInvalid(player, 232);
test.assertInvalid(1, 2, 3);
test.addVariable("player", null);
test.assertInvalid(null, "msg");
test.assertInvalid(nullP);
assertJSError(() -> test.withArgs().test(), "Too few arguments! You should enter at least on argument if you use KICK executor from console.");
}
use of js.ExecutorTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testSetPlayerInv.
@Test
public void testSetPlayerInv() throws Exception {
Player player = mock(Player.class);
ItemStack vItem = mock(ItemStack.class);
PlayerInventory vInv = mock(PlayerInventory.class);
when(player.getInventory()).thenReturn(vInv);
when(vInv.getSize()).thenReturn(36);
ExecutorTest test = new ExecutorTest(engine, "SETPLAYERINV");
test.addVariable("player", player);
test.withArgs(1, vItem).test();
verify(vInv).setItem(1, vItem);
test.assertInvalid(0);
test.assertInvalid("HELLO");
test.assertInvalid(0, "hu");
test.assertInvalid(true, 0);
}
Aggregations