Search in sources :

Example 6 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testScoreboard.

@Test
public void testScoreboard() throws Exception {
    Player player = mock(Player.class);
    Scoreboard scoreboard = mock(Scoreboard.class);
    Team team = mock(Team.class);
    when(player.getScoreboard()).thenReturn(scoreboard);
    when(scoreboard.getTeam(anyString())).thenReturn(team);
    new ExecutorTest(engine, "SCOREBOARD").withArgs("TEAM", "someteam", "ADD", "wysohn").addVariable("player", player).test();
    verify(team).addEntry("wysohn");
}
Also used : Player(org.bukkit.entity.Player) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) Scoreboard(org.bukkit.scoreboard.Scoreboard) Team(org.bukkit.scoreboard.Team) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 7 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testSetBlock1_1.

@Test
public void testSetBlock1_1() throws Exception {
    // {block id} {x} {y} {z}
    World mockWorld = mock(World.class);
    Player player = mock(Player.class);
    Block block = mock(Block.class);
    when(player.getWorld()).thenReturn(mockWorld);
    when(mockWorld.getBlockAt(any(Location.class))).thenReturn(block);
    when(server.getWorld("world")).thenReturn(mockWorld);
    new ExecutorTest(engine, "SETBLOCK").addVariable("player", player).withArgs("GLASS", 33, 96, -15).test();
    verify(block).setType(eq(Material.GLASS));
}
Also used : Player(org.bukkit.entity.Player) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) Block(org.bukkit.block.Block) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 8 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testSpawn.

@Test
public void testSpawn() throws Exception {
    Player player = mock(Player.class);
    World world = mock(World.class);
    Location location = new Location(world, 3, 4, 5);
    when(player.getWorld()).thenReturn(world);
    new ExecutorTest(engine, "SPAWN").addVariable("player", player).withArgs(location, EntityType.CREEPER.name()).test();
    verify(world).spawnEntity(location, EntityType.CREEPER);
}
Also used : Player(org.bukkit.entity.Player) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 9 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testGUI.

@Test
public void testGUI() throws Exception {
    IPlayer vip = mock(IPlayer.class);
    TriggerReactorCore tr = mock(TriggerReactorCore.class);
    AbstractInventoryTriggerManager invManager = mock(AbstractInventoryTriggerManager.class);
    IInventory iInv = mock(IInventory.class);
    JsTest test = new ExecutorTest(engine, "GUI").addVariable("player", vip).addVariable("plugin", tr);
    when(tr.getInvManager()).thenReturn(invManager);
    when(invManager.openGUI(vip, "Hi")).thenReturn(iInv);
    test.withArgs("Hi").test();
    verify(invManager).openGUI(vip, "Hi");
    assertJSError(() -> test.withArgs().test(), "Invalid parameters. Need [String]");
    when(invManager.openGUI(vip, "hello")).thenReturn(null);
    assertJSError(() -> test.withArgs("hello").test(), "No such Inventory Trigger named hello");
}
Also used : IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) AbstractInventoryTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.AbstractInventoryTriggerManager) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) BukkitTriggerReactorCore(io.github.wysohn.triggerreactor.bukkit.main.BukkitTriggerReactorCore) TriggerReactorCore(io.github.wysohn.triggerreactor.core.main.TriggerReactorCore) JsTest(js.JsTest) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 10 with ExecutorTest

use of js.ExecutorTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testClearEntity.

@Test
public void testClearEntity() throws Exception {
    Player player = mock(Player.class);
    List<Entity> entities = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        entities.add(mock(Entity.class));
    }
    JsTest test = new ExecutorTest(engine, "CLEARENTITY").addVariable("player", player);
    when(player.getNearbyEntities(2d, 2d, 2d)).thenReturn(entities);
    test.withArgs(2).test();
    for (Entity ve : entities) {
        verify(ve).remove();
    }
    assertJSError(() -> test.withArgs().test(), "Invalid parameters! [Number]");
    assertJSError(() -> test.withArgs("NO").test(), "Invalid parameters! [Number]");
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) ArrayList(java.util.ArrayList) JsTest(js.JsTest) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Aggregations

ExecutorTest (js.ExecutorTest)63 JsTest (js.JsTest)61 Test (org.junit.Test)60 Player (org.bukkit.entity.Player)48 IPlayer (io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer)43 Block (org.bukkit.block.Block)16 ItemStack (org.bukkit.inventory.ItemStack)11 Location (org.bukkit.Location)6 World (org.bukkit.World)5 PlayerInventory (org.bukkit.inventory.PlayerInventory)5 BlockState (org.bukkit.block.BlockState)4 ArrayList (java.util.ArrayList)3 Entity (org.bukkit.entity.Entity)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 Lever (org.bukkit.material.Lever)3 BukkitTriggerReactorCore (io.github.wysohn.triggerreactor.bukkit.main.BukkitTriggerReactorCore)2 IInventory (io.github.wysohn.triggerreactor.core.bridge.IInventory)2 AbstractJavaPlugin (io.github.wysohn.triggerreactor.bukkit.main.AbstractJavaPlugin)1 VaultSupport (io.github.wysohn.triggerreactor.bukkit.manager.trigger.share.api.vault.VaultSupport)1 TriggerReactorCore (io.github.wysohn.triggerreactor.core.main.TriggerReactorCore)1