use of js.ExecutorTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testSetHeldItem.
@Test
public void testSetHeldItem() throws Exception {
Player player = mock(Player.class);
ItemStack vItem = mock(ItemStack.class);
PlayerInventory piv = mock(PlayerInventory.class);
ExecutorTest test = new ExecutorTest(engine, "SETHELDITEM");
test.addVariable("player", player);
when(player.getInventory()).thenReturn(piv);
test.withArgs(vItem).test();
verify(piv).setItemInHand(vItem);
Assert.assertEquals(0, test.getOverload(vItem));
test.assertInvalid(0);
test.assertInvalid("NUUP");
test.assertInvalid(true);
}
use of js.ExecutorTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testPlayer_SetFood.
@Test
public void testPlayer_SetFood() throws Exception {
Player player = mock(Player.class);
JsTest test = new ExecutorTest(engine, "SETFOOD").addVariable("player", player);
// case1
test.withArgs(3).test();
verify(player).setFoodLevel(3);
// case2
test.withArgs(4.0).test();
verify(player).setFoodLevel(4);
// Unexpected Cases
assertJSError(() -> test.withArgs().test(), "Incorrect Number of arguments for Executor SETFOOD");
assertJSError(() -> test.withArgs("HI").test(), "Invalid argument for Executor SETFOOD: HI");
assertJSError(() -> test.withArgs(3.4).test(), "Argument for Executor SETFOOD should be a whole number");
assertJSError(() -> test.withArgs(-3.0).test(), "Argument for Executor SETFOOD should not be negative");
}
use of js.ExecutorTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testBroadcast.
@Test
public void testBroadcast() throws Exception {
Collection<Player> players = new ArrayList<>();
for (int i = 0; i < 5; i++) {
players.add(mock(Player.class));
}
String message = "&cHey all";
String colored = ChatColor.translateAlternateColorCodes('&', message);
doReturn(players).when(server).getOnlinePlayers();
new ExecutorTest(engine, "BROADCAST").withArgs(message).test();
for (Player mockPlayer : players) {
verify(mockPlayer).sendMessage(argThat((String s) -> colored.equals(s)));
}
}
use of js.ExecutorTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testLeverOn.
@Test
public void testLeverOn() throws Exception {
Location vLoc = mock(Location.class);
Block vBlock = mock(Block.class);
BlockState vBS = mock(BlockState.class);
Lever vLever = mock(Lever.class);
JsTest test = new ExecutorTest(engine, "LEVERON");
when(vLoc.getBlock()).thenReturn(vBlock);
when(vBlock.getState()).thenReturn(vBS);
when(vBS.getData()).thenReturn(vLever);
test.withArgs(vLoc).test();
verify(vLever).setPowered(true);
assertJSError(() -> test.withArgs().test(), "Invalid parameters. Need [Location<location or number number number>]");
// TODO - need test for the situation of args.length == 3
}
use of js.ExecutorTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testPlayer_SetXp.
@Test
public void testPlayer_SetXp() throws Exception {
Player player = mock(Player.class);
JsTest test = new ExecutorTest(engine, "SETXP").addVariable("player", player);
// case1
test.withArgs(0.3).test();
verify(player).setExp(0.3F);
// case2
test.withArgs(1).test();
verify(player).setExp(1.0F);
// Unexpected Cases
assertJSError(() -> test.withArgs().test(), "Incorrect number of arguments for executor SETXP");
assertJSError(() -> test.withArgs("lmao").test(), "Invalid argument for SETXP: lmao");
assertJSError(() -> test.withArgs(33).test(), "33 is outside of the allowable range of 0..1 for executor SETXP");
}
Aggregations