Search in sources :

Example 16 with JsTest

use of js.JsTest in project TriggerReactor by wysohn.

the class AbstractTestPlaceholder method testRandom.

/*
    @Test
    public void testIsNumber() throws Exception{
        JsTest output = new PlaceholderTest(engine, "isnumber");

        output.withArgs("3").test();
       // assertEquals(true, output); TODO
    }
    */
@Test
public void testRandom() throws Exception {
    JsTest test = new PlaceholderTest(engine, "random");
    test.withArgs(1).test();
    test.assertValid(0).assertValid(1, 2).assertInvalid().assertInvalid(1, 2, 3).assertInvalid("j").assertInvalid(4, "j");
}
Also used : PlaceholderTest(js.PlaceholderTest) JsTest(js.JsTest) Test(org.junit.Test) PlaceholderTest(js.PlaceholderTest) JsTest(js.JsTest)

Example 17 with JsTest

use of js.JsTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testClearChat.

@Test
public void testClearChat() throws Exception {
    Player player = mock(Player.class);
    Player player2 = mock(Player.class);
    Player nullP = null;
    JsTest test = new ExecutorTest(engine, "CLEARCHAT").addVariable("player", player);
    // case1
    test.withArgs().test();
    verify(player, times(30)).sendMessage("");
    // case2
    test.withArgs(player2).test();
    verify(player2, times(30)).sendMessage("");
    // Unexpected Cases
    assertJSError(() -> test.withArgs(nullP).test(), "Found unexpected parameter - player: null");
    assertJSError(() -> test.withArgs(1, 2).test(), "Too many parameters found! CLEARCHAT accept up to one parameter.");
}
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 18 with JsTest

use of js.JsTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testPlayer_SetMaxHealth.

@SuppressWarnings("deprecation")
@Test
public void testPlayer_SetMaxHealth() throws Exception {
    Player player = mock(Player.class);
    JsTest test = new ExecutorTest(engine, "SETMAXHEALTH").addVariable("player", player);
    // case1
    test.withArgs(30).test();
    verify(player).setMaxHealth(30.0);
    // case2
    test.withArgs(35.4).test();
    verify(player).setMaxHealth(35.4);
    // Unexpected Cases
    assertJSError(() -> test.withArgs(20, 33).test(), "Incorrect Number of arguments for Executor SETMAXHEALTH");
    assertJSError(() -> test.withArgs("NONO").test(), "Invalid argument for SETMAXHEALTH: NONO");
    assertJSError(() -> test.withArgs(-30).test(), "Argument for Executor SETMAXHEALTH should not be negative or zero");
    assertJSError(() -> test.withArgs(2098).test(), "Maximum health cannot be greater than 2048");
}
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 19 with JsTest

use of js.JsTest in project TriggerReactor by wysohn.

the class AbstractTestExecutors method testWeather.

@Test
public void testWeather() throws Exception {
    JsTest test = new ExecutorTest(engine, "WEATHER");
    World mockWorld = mock(World.class);
    when(server.getWorld("merp")).thenReturn(mockWorld);
    test.withArgs("merp", true).test();
    verify(mockWorld).setStorm(true);
    when(server.getWorld("merp")).thenReturn(null);
    assertJSError(() -> test.withArgs("merp", true, true).test(), "Invalid parameters! [String, Boolean]");
    assertJSError(() -> test.withArgs("merp", 1).test(), "Invalid parameters! [String, Boolean]");
    assertJSError(() -> test.withArgs(mockWorld, false).test(), "Invalid parameters! [String, Boolean]");
    assertJSError(() -> test.withArgs("merp", true).test(), "Unknown world named merp");
}
Also used : JsTest(js.JsTest) ExecutorTest(js.ExecutorTest) ExecutorTest(js.ExecutorTest) Test(org.junit.Test) JsTest(js.JsTest)

Example 20 with JsTest

use of js.JsTest in project TriggerReactor by wysohn.

the class AbstractTestPlaceholder method testPlayernameMultiThreaded.

@Test
public void testPlayernameMultiThreaded() throws Exception {
    Player mockPlayer = mock(Player.class);
    ExecutorService pool = Executors.newSingleThreadExecutor();
    when(mockPlayer.getName()).thenReturn("wysohn");
    when(mockMain.isServerThread()).thenReturn(false);
    when(mockMain.callSyncMethod(any(Callable.class))).then(invocation -> {
        Callable call = invocation.getArgument(0);
        return pool.submit(call);
    });
    Runnable run = new Runnable() {

        final JsTest test = new PlaceholderTest(engine, "playername").addVariable("player", mockPlayer);

        @Override
        public void run() {
            for (int i = 0; i < 1000; i++) {
                Object result = null;
                try {
                    result = test.test();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                assertEquals("wysohn", result);
            }
        }
    };
    Thread.UncaughtExceptionHandler handler = mock(Thread.UncaughtExceptionHandler.class);
    Thread thread1 = new Thread(run);
    thread1.setUncaughtExceptionHandler(handler);
    Thread thread2 = new Thread(run);
    thread2.setUncaughtExceptionHandler(handler);
    thread1.start();
    thread2.start();
    thread1.join();
    thread2.join();
    verify(handler, never()).uncaughtException(any(), any());
    verify(mockPlayer, times(2000)).getName();
}
Also used : Player(org.bukkit.entity.Player) ExecutorService(java.util.concurrent.ExecutorService) PlaceholderTest(js.PlaceholderTest) JsTest(js.JsTest) Callable(java.util.concurrent.Callable) 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