### Question:
JavascriptObject { protected <T> T invokeJavascriptReturnValue(String function, Class<T> returnType) { Object returnObject = invokeJavascript(function); if (returnObject instanceof JSObject) { try { Constructor<T> constructor = returnType.getConstructor(JSObject.class); return constructor.newInstance((JSObject) returnObject); } catch (Exception ex) { throw new IllegalStateException(ex); } } else { return (T) returnObject; } } protected  JavascriptObject(); protected  JavascriptObject(String type); protected  JavascriptObject( String type, String stringRepresentation ); protected  JavascriptObject(String type, Object... args); protected  JavascriptObject(String type, Object[] ary, boolean isArray); protected  JavascriptObject(String type, JSObject jsObject); JSObject getJSObject(); String getVariableName();  }### Answer:
@Test public void testInvokeJavascriptReturnValue() { String arg = "myArg"; Object[] argArray = new Object[] {arg}; String function = "myFunction"; String result = "result"; when(mockJsObject.call(function, argArray)).thenReturn(result); String returnValue = testJavascriptObject.invokeJavascriptReturnValue(function, String.class, arg); assertEquals( result, returnValue ); }
@Test public void testInvokeJavascriptReturnValue_Null() { String arg = "myArg"; Object[] argArray = new Object[] {arg}; String function = "myFunction"; when(mockJsObject.call(function, argArray)).thenReturn(null); String returnValue = testJavascriptObject.invokeJavascriptReturnValue(function, String.class, arg); assertNull( returnValue ); }