use of js.JsTest in project TriggerReactor by wysohn.
the class AbstractTestPlaceholder method testEntityname.
@Test
public void testEntityname() throws Exception {
EntityEvent mockEvent = mock(EntityEvent.class);
Entity mockEntity = mock(Entity.class);
JsTest test = new PlaceholderTest(engine, "entityname");
test.addVariable("event", mockEvent);
when(mockEvent.getEntity()).thenReturn(mockEntity);
when(mockEntity.getName()).thenReturn("SomeEntity");
Assert.assertEquals("SomeEntity", test.test());
}
use of js.JsTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testCmd.
@Test
public void testCmd() throws Exception {
Player player = mock(Player.class);
when(player.getServer()).thenReturn(server);
JsTest test = new ExecutorTest(engine, "CMD").addVariable("player", player);
// only happy case
test.withArgs("some command line").test();
verify(server).dispatchCommand(player, "some command line");
}
use of js.JsTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testLeverOff.
@Test
public void testLeverOff() 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, "LEVEROFF");
when(vLoc.getBlock()).thenReturn(vBlock);
when(vBlock.getState()).thenReturn(vBS);
when(vBS.getData()).thenReturn(vLever);
test.withArgs(vLoc).test();
verify(vLever).setPowered(false);
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_SetSaturation.
@Test
public void testPlayer_SetSaturation() throws Exception {
Player player = mock(Player.class);
JsTest test = new ExecutorTest(engine, "SETSATURATION").addVariable("player", player);
// case1
test.withArgs(25).test();
verify(player).setSaturation(25.0F);
// case2
test.withArgs(44.0).test();
verify(player).setSaturation(44.0F);
// Unexpected Cases
assertJSError(() -> test.withArgs().test(), "Incorrect Number of arguments for Executor SETSATURATION");
assertJSError(() -> test.withArgs("Hi").test(), "Invalid argument for SETSATURATION: Hi");
assertJSError(() -> test.withArgs(-45).test(), "Argument for Executor SETSATURATION should not be negative");
}
use of js.JsTest in project TriggerReactor by wysohn.
the class AbstractTestExecutors method testLightning.
@Test
public void testLightning() throws Exception {
Location vLoc = mock(Location.class);
World vWorld = mock(World.class);
JsTest test = new ExecutorTest(engine, "LIGHTNING");
when(vLoc.getWorld()).thenReturn(vWorld);
test.withArgs(vLoc).test();
verify(vWorld).strikeLightning(vLoc);
assertJSError(() -> test.withArgs().test(), "Invalid parameters! [String, Number, Number, Number] or [Location]");
assertJSError(() -> test.withArgs("hff").test(), "Invalid parameters! [String, Number, Number, Number] or [Location]");
// TODO - need test for the situation of args.length == 4
}
Aggregations