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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations