Search in sources :

Example 21 with JsTest

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());
}
Also used : Entity(org.bukkit.entity.Entity) EntityEvent(org.bukkit.event.entity.EntityEvent) PlaceholderTest(js.PlaceholderTest) JsTest(js.JsTest) Test(org.junit.Test) PlaceholderTest(js.PlaceholderTest) JsTest(js.JsTest)

Example 22 with JsTest

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");
}
Also used : Player(org.bukkit.entity.Player) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) JsTest(js.JsTest) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 23 with JsTest

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
}
Also used : BlockState(org.bukkit.block.BlockState) Lever(org.bukkit.material.Lever) Block(org.bukkit.block.Block) JsTest(js.JsTest) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 24 with JsTest

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");
}
Also used : Player(org.bukkit.entity.Player) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) JsTest(js.JsTest) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 25 with JsTest

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
}
Also used : JsTest(js.JsTest) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Aggregations

JsTest (js.JsTest)31 Test (org.junit.Test)30 ExecutorTest (js.ExecutorTest)27 Player (org.bukkit.entity.Player)19 IPlayer (io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer)18 Block (org.bukkit.block.Block)6 PlaceholderTest (js.PlaceholderTest)4 Entity (org.bukkit.entity.Entity)4 BlockState (org.bukkit.block.BlockState)3 Lever (org.bukkit.material.Lever)3 ArrayList (java.util.ArrayList)2 Callable (java.util.concurrent.Callable)2 ExecutorService (java.util.concurrent.ExecutorService)2 BukkitTriggerReactorCore (io.github.wysohn.triggerreactor.bukkit.main.BukkitTriggerReactorCore)1 VaultSupport (io.github.wysohn.triggerreactor.bukkit.manager.trigger.share.api.vault.VaultSupport)1 IInventory (io.github.wysohn.triggerreactor.core.bridge.IInventory)1 TriggerReactorCore (io.github.wysohn.triggerreactor.core.main.TriggerReactorCore)1 AbstractInventoryTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.inventory.AbstractInventoryTriggerManager)1 World (org.bukkit.World)1 ItemFrame (org.bukkit.entity.ItemFrame)1