use of js.JsTest 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.JsTest 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.JsTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testKill.
@Test
public void testKill() throws Exception {
Player player = mock(Player.class);
JsTest test = new ExecutorTest(engine, "KILL").addVariable("player", player);
test.withArgs().test();
verify(player).setHealth(0d);
}
use of js.JsTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testPlayer_SetWalkSpeed.
@Test
public void testPlayer_SetWalkSpeed() throws Exception {
Player player = mock(Player.class);
JsTest test = new ExecutorTest(engine, "SETWALKSPEED").addVariable("player", player);
// case1
test.withArgs(1).test();
verify(player).setWalkSpeed(1.0F);
// case2
test.withArgs(0.7).test();
verify(player).setWalkSpeed(0.7F);
// Unexpected Cases
assertJSError(() -> test.withArgs().test(), "Incorrect Number of arguments for Executor SETWALKSPEED");
assertJSError(() -> test.withArgs("NUU").test(), "Invalid argument for SETWALKSPEED: NUU");
assertJSError(() -> test.withArgs(-3).test(), "Argument for Executor SETWALKSPEED is outside of the allowable range -1..1");
}
use of js.JsTest 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");
}
Aggregations