Search in sources :

Example 11 with JsTest

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
}
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 12 with JsTest

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");
}
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 13 with JsTest

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");
}
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 14 with JsTest

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");
}
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 15 with JsTest

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