Search in sources :

Example 1 with JsTest

use of js.JsTest in project TriggerReactor by wysohn.

the class TestExecutors method testSetBlockSetData.

public void testSetBlockSetData() throws Exception {
    World mockWorld = Mockito.mock(World.class);
    Block mockBlock = mock(Block.class);
    JsTest test = new ExecutorTest(engine, "SETBLOCK");
    test.addVariable("block", mockBlock);
    when(server.getWorld("world")).thenReturn(mockWorld);
    test.withArgs(1).test();
    verify(mockBlock).setType(eq(Material.STONE));
    verify(mockBlock).setData(eq((byte) 0));
}
Also used : Block(org.bukkit.block.Block) JsTest(js.JsTest) World(org.bukkit.World) ExecutorTest(js.ExecutorTest)

Example 2 with JsTest

use of js.JsTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testBurn.

@Test
public void testBurn() throws Exception {
    // happy cases
    Player mockPlayer = mock(Player.class);
    Entity mockEntity = mock(Entity.class);
    JsTest test = new ExecutorTest(engine, "BURN").addVariable("player", mockPlayer);
    test.withArgs(3).test();
    verify(mockPlayer).setFireTicks(60);
    test.withArgs(0.101).test();
    verify(mockPlayer).setFireTicks(2);
    test.withArgs(mockEntity, 1).test();
    verify(mockEntity).setFireTicks(20);
    when(server.getPlayer("merp")).thenReturn(mockPlayer);
    test.withArgs("merp", 5).test();
    verify(mockPlayer).setFireTicks(100);
    // sad cases
    when(server.getPlayer("merp")).thenReturn(null);
    assertJSError(() -> test.withArgs(-1).test(), "The number of seconds to burn should be positive");
    assertJSError(() -> test.withArgs().test(), "Invalid number of parameters. Need [Number] or [Entity<entity or string>, Number]");
    assertJSError(() -> test.withArgs(1, 1, 1).test(), "Invalid number of parameters. Need [Number] or [Entity<entity or string>, Number]");
    assertJSError(() -> test.withArgs(true).test(), "Invalid number for seconds to burn: true");
    assertJSError(() -> test.withArgs(null, 4).test(), "player to burn should not be null");
    assertJSError(() -> test.withArgs("merp", 3).test(), "player to burn does not exist");
    assertJSError(() -> test.withArgs(3, 3).test(), "invalid entity to burn: 3");
    assertJSError(() -> test.withArgs(mockEntity, "merp").test(), "The number of seconds to burn should be a number");
    assertJSError(() -> test.withArgs(mockEntity, -1).test(), "The number of seconds to burn should be positive");
}
Also used : Entity(org.bukkit.entity.Entity) 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 3 with JsTest

use of js.JsTest 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 4 with JsTest

use of js.JsTest 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)

Example 5 with JsTest

use of js.JsTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testGive.

@Test
public void testGive() throws Exception {
    Player player = mock(Player.class);
    PlayerInventory playerInv = mock(PlayerInventory.class);
    ItemStack vItem = mock(ItemStack.class);
    JsTest test = new ExecutorTest(engine, "GIVE").addVariable("player", player);
    when(player.getInventory()).thenReturn(playerInv);
    when(playerInv.firstEmpty()).thenReturn(4);
    test.withArgs(vItem).test();
    verify(playerInv).addItem(vItem);
    assertJSError(() -> test.withArgs().test(), "Invalid parameters. Need [ItemStack]");
    when(playerInv.firstEmpty()).thenReturn(-1);
    assertJSError(() -> test.withArgs(vItem).test(), "Player has no empty slot.");
    when(playerInv.firstEmpty()).thenReturn(7);
    assertJSError(() -> test.withArgs("hi").test(), "Invalid ItemStack: hi");
}
Also used : Player(org.bukkit.entity.Player) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) JsTest(js.JsTest) PlayerInventory(org.bukkit.inventory.PlayerInventory) ItemStack(org.bukkit.inventory.ItemStack) 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