Пример #1
0
  @Test
  public void newValue_object() throws Exception {
    final Object obj = execute("result = {'a':1, 'b':2};");
    final ScriptValue value = this.factory.newValue(obj);

    assertNotNull(value);
    assertEquals(false, value.isArray());
    assertEquals(false, value.isFunction());
    assertEquals(true, value.isObject());
    assertEquals(false, value.isValue());

    assertNonValue(value);
    assertNonArray(value);
    assertNonFunction(value);

    assertNotNull(value.getKeys());
    assertEquals(2, value.getKeys().size());
    assertEquals("a,b", Joiner.on(",").join(value.getKeys()));

    assertNotNull(value.getMap());
    assertEquals(2, value.getMap().size());
    assertNotNull(value.getMember("a"));
    assertEquals(1, value.getMember("a").getValue());
    assertTrue(value.hasMember("a"));
  }
Пример #2
0
  private void assertNonObject(final ScriptValue value) {
    assertNotNull(value.getKeys());
    assertEquals(0, value.getKeys().size());

    assertNotNull(value.getMap());
    assertEquals(0, value.getMap().size());
    assertNull(value.getMember("test"));
    assertFalse(value.hasMember("test"));
  }