Search in sources :

Example 1 with PlaceholderTest

use of js.PlaceholderTest in project TriggerReactor by wysohn.

the class AbstractTestPlaceholder method testId.

@Test
public void testId() throws Exception {
    ItemStack vItem = mock(ItemStack.class);
    Material stone = Material.valueOf("STONE");
    when(vItem.getType()).thenReturn(stone);
    PlaceholderTest test = new PlaceholderTest(engine, "id");
    Object result = test.withArgs(vItem).test();
    Assert.assertEquals(result, stone);
    test.assertInvalid("hi");
    test.assertInvalid(true);
    test.assertInvalid(35);
}
Also used : PlaceholderTest(js.PlaceholderTest) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) Test(org.junit.Test) PlaceholderTest(js.PlaceholderTest) JsTest(js.JsTest)

Example 2 with PlaceholderTest

use of js.PlaceholderTest in project TriggerReactor by wysohn.

the class AbstractTestPlaceholder method testLore.

@Test
public void testLore() throws Exception {
    ItemStack vItem = mock(ItemStack.class);
    ItemMeta vIM = mock(ItemMeta.class);
    List<String> lores = new ArrayList<>();
    lores.add("creeper");
    lores.add("awwman");
    lores.add("sowebackinthemine");
    when(vItem.hasItemMeta()).thenReturn(true);
    when(vItem.getItemMeta()).thenReturn(vIM);
    when(vIM.hasLore()).thenReturn(true);
    when(vIM.getLore()).thenReturn(lores);
    String loreString = "";
    for (int k = 0; k < lores.size(); k++) {
        String lore = lores.get(k);
        if (k == (lores.size() - 1))
            loreString = loreString + lore;
        else
            loreString = loreString + lore + "\n";
    }
    PlaceholderTest test = new PlaceholderTest(engine, "lore");
    Object result = test.withArgs(vItem).test();
    Assert.assertEquals(result, loreString);
    test.assertInvalid("hi");
    test.assertInvalid(true);
    test.assertInvalid(35);
}
Also used : ArrayList(java.util.ArrayList) PlaceholderTest(js.PlaceholderTest) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Test(org.junit.Test) PlaceholderTest(js.PlaceholderTest) JsTest(js.JsTest)

Example 3 with PlaceholderTest

use of js.PlaceholderTest in project TriggerReactor by wysohn.

the class AbstractTestPlaceholder method testCount.

@Test
public void testCount() throws Exception {
    ItemStack vItem = mock(ItemStack.class);
    Material stone = Material.valueOf("STONE");
    PlaceholderTest test = new PlaceholderTest(engine, "count");
    when(vItem.getType()).thenReturn(stone);
    when(vItem.getAmount()).thenReturn(34);
    Object result = test.withArgs(vItem).test();
    Assert.assertEquals(result, 34);
    test.assertValid(vItem);
    test.assertInvalid("hi");
    test.assertInvalid(24);
}
Also used : PlaceholderTest(js.PlaceholderTest) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) Test(org.junit.Test) PlaceholderTest(js.PlaceholderTest) JsTest(js.JsTest)

Example 4 with PlaceholderTest

use of js.PlaceholderTest in project TriggerReactor by wysohn.

the class AbstractTestPlaceholder method testPlayerInv.

@Test
public void testPlayerInv() throws Exception {
    Player vp = mock(Player.class);
    PlayerInventory vInv = mock(PlayerInventory.class);
    ItemStack vItem = mock(ItemStack.class);
    when(vp.getInventory()).thenReturn(vInv);
    when(vInv.getSize()).thenReturn(36);
    when(vInv.getItem(2)).thenReturn(vItem);
    PlaceholderTest test = new PlaceholderTest(engine, "playerinv");
    test.addVariable("player", vp);
    ItemStack result = (ItemStack) test.withArgs(2).test();
    Assert.assertEquals(result, vItem);
    test.assertInvalid("hi");
    test.assertInvalid(true);
}
Also used : Player(org.bukkit.entity.Player) PlaceholderTest(js.PlaceholderTest) PlayerInventory(org.bukkit.inventory.PlayerInventory) ItemStack(org.bukkit.inventory.ItemStack) Test(org.junit.Test) PlaceholderTest(js.PlaceholderTest) JsTest(js.JsTest)

Example 5 with PlaceholderTest

use of js.PlaceholderTest 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)16 PlaceholderTest (js.PlaceholderTest)16 Test (org.junit.Test)16 ItemStack (org.bukkit.inventory.ItemStack)9 Player (org.bukkit.entity.Player)5 PlayerInventory (org.bukkit.inventory.PlayerInventory)4 Material (org.bukkit.Material)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 ExecutorService (java.util.concurrent.ExecutorService)1 World (org.bukkit.World)1 Block (org.bukkit.block.Block)1 Entity (org.bukkit.entity.Entity)1 EntityEvent (org.bukkit.event.entity.EntityEvent)1 InventoryClickEvent (org.bukkit.event.inventory.InventoryClickEvent)1 PlayerCommandPreprocessEvent (org.bukkit.event.player.PlayerCommandPreprocessEvent)1 Inventory (org.bukkit.inventory.Inventory)1 ItemFactory (org.bukkit.inventory.ItemFactory)1