use of js.JsTest 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.JsTest 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");
}
use of js.JsTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testPlayer_SetFlySpeed.
@Test
public void testPlayer_SetFlySpeed() throws Exception {
Player player = mock(Player.class);
JsTest test = new ExecutorTest(engine, "SETFLYSPEED").addVariable("player", player);
// only case
test.withArgs(0.5).test();
verify(player).setFlySpeed(0.5F);
// Unexpected cases
assertJSError(() -> test.withArgs().test(), "Incorrect Number of arguments for Executor SETFLYSPEED");
assertJSError(() -> test.withArgs(0.5, 13).test(), "Incorrect Number of arguments for Executor SETFLYSPEED");
assertJSError(() -> test.withArgs("HI").test(), "Invalid argument for SETFLYSPEED: HI");
assertJSError(() -> test.withArgs(4).test(), "Argument for Executor SETFLYSPEED is outside of range -1..1");
assertJSError(() -> test.withArgs(-4).test(), "Argument for Executor SETFLYSPEED is outside of range -1..1");
}
use of js.JsTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testPlayer_SetGameMode.
@Test
public void testPlayer_SetGameMode() throws Exception {
Player player = mock(Player.class);
JsTest test = new ExecutorTest(engine, "SETGAMEMODE").addVariable("player", player);
// only case
test.withArgs("creative").test();
verify(player).setGameMode(GameMode.valueOf("CREATIVE"));
// case2
test.withArgs(2).test();
verify(player).setGameMode(GameMode.valueOf("ADVENTURE"));
// Unexpected Cases
assertJSError(() -> test.withArgs().test(), "Incorrect number of arguments for executor SETGAMEMODE");
assertJSError(() -> test.withArgs(34).test(), "Invalid argument for Executor SETGAMEMODE: 34");
assertJSError(() -> test.withArgs("hElLo").test(), "Unknown GAEMMODE value hElLo");
}
use of js.JsTest in project TriggerReactor by wysohn.
the class AbstractTestPlaceholder method testCmdline.
@Test
public void testCmdline() throws Exception {
PlayerCommandPreprocessEvent mockEvent = mock(PlayerCommandPreprocessEvent.class);
JsTest test = new PlaceholderTest(engine, "cmdline");
test.addVariable("event", mockEvent);
when(mockEvent.getMessage()).thenReturn("/mycommand");
String line = (String) test.test();
Mockito.verify(mockEvent).getMessage();
Assert.assertEquals("mycommand", line);
line = (String) test.withArgs(0).test();
Assert.assertEquals("mycommand", line);
line = (String) test.withArgs(0, 2).test();
Assert.assertEquals("mycommand", line);
when(mockEvent.getMessage()).thenReturn("/mycommand arg1 arg2");
line = (String) test.test();
Assert.assertEquals("mycommand arg1 arg2", line);
line = (String) test.withArgs(1).test();
Assert.assertEquals("arg1 arg2", line);
line = (String) test.withArgs(0, 1).test();
Assert.assertEquals("mycommand arg1", line);
line = (String) test.withArgs(0, 99).test();
Assert.assertEquals("mycommand arg1 arg2", line);
line = (String) test.withArgs(8, 99).test();
Assert.assertNull(line);
}
Aggregations