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