@Test public void testUnwrapDateError() throws ScriptException, NoSuchMethodException { engine.eval("function test() { return []; };"); ScriptObjectMirror object = (ScriptObjectMirror) ((Invocable) engine).invokeFunction("test"); try { ScriptObjectMirrors.unwrapDate(object); fail("unwrapDate should throw an exception."); } catch (IllegalArgumentException e) { assertEquals("JavaScript input is not a Date!", e.getMessage()); } }
public static Calendar unwrapDate(ScriptObjectMirror jso) { if (!JAVASCRIPT_DATE_CLASS_TYPE.equals(jso.getClassName())) { throw new IllegalArgumentException("JavaScript input is not a Date!"); } Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(((Double) jso.callMember("getTime")).longValue()); return cal; }
ScriptObjectMirrors { public static Calendar unwrapDate(ScriptObjectMirror jso) { if (!JAVASCRIPT_DATE_CLASS_TYPE.equals(jso.getClassName())) { throw new IllegalArgumentException("JavaScript input is not a Date!"); } Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(((Double) jso.callMember("getTime")).longValue()); return cal; } }
ScriptObjectMirrors { public static Calendar unwrapDate(ScriptObjectMirror jso) { if (!JAVASCRIPT_DATE_CLASS_TYPE.equals(jso.getClassName())) { throw new IllegalArgumentException("JavaScript input is not a Date!"); } Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(((Double) jso.callMember("getTime")).longValue()); return cal; } private  ScriptObjectMirrors(); }
ScriptObjectMirrors { public static Calendar unwrapDate(ScriptObjectMirror jso) { if (!JAVASCRIPT_DATE_CLASS_TYPE.equals(jso.getClassName())) { throw new IllegalArgumentException("JavaScript input is not a Date!"); } Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(((Double) jso.callMember("getTime")).longValue()); return cal; } private  ScriptObjectMirrors(); static Object unwrap(ScriptObjectMirror jso); static List<Object> unwrapList(ScriptObjectMirror jso); static Map<String, Object> unwrapMap(ScriptObjectMirror jso); static Calendar unwrapDate(ScriptObjectMirror jso); static Object wrap(Map<String, Object> map); }
ScriptObjectMirrors { public static Calendar unwrapDate(ScriptObjectMirror jso) { if (!JAVASCRIPT_DATE_CLASS_TYPE.equals(jso.getClassName())) { throw new IllegalArgumentException("JavaScript input is not a Date!"); } Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(((Double) jso.callMember("getTime")).longValue()); return cal; } private  ScriptObjectMirrors(); static Object unwrap(ScriptObjectMirror jso); static List<Object> unwrapList(ScriptObjectMirror jso); static Map<String, Object> unwrapMap(ScriptObjectMirror jso); static Calendar unwrapDate(ScriptObjectMirror jso); static Object wrap(Map<String, Object> map);  }