@Test public void newValue_scalar() { final ScriptValue value = this.factory.newValue("2"); assertNotNull(value); assertEquals(false, value.isArray()); assertEquals(false, value.isFunction()); assertEquals(false, value.isObject()); assertEquals(true, value.isValue()); assertEquals("2", value.getValue()); assertEquals(new Integer(2), value.getValue(Integer.class)); assertNonArray(value); assertNonObject(value); assertNonFunction(value); }
@Test public void newValue_function() { final JSObject obj = Mockito.mock(JSObject.class); Mockito.when(obj.isFunction()).thenReturn(true); final ScriptValue value = this.factory.newValue(obj); assertNotNull(value); assertEquals(false, value.isArray()); assertEquals(true, value.isFunction()); assertEquals(false, value.isObject()); assertEquals(false, value.isValue()); assertNonValue(value); assertNonArray(value); assertNonObject(value); Mockito.when(this.invoker.invoke(Mockito.same(obj), Mockito.any())).thenReturn("a+b"); final ScriptValue result = value.call("a", "b"); assertNotNull(result); assertEquals(true, result.isValue()); assertEquals("a+b", result.getValue()); }
private void assertNonValue(final ScriptValue value) { assertNull(value.getValue()); assertNull(value.getValue(Integer.class)); }