Get a JSObject or JSContext to run an applet

放肆的年华 提交于 2019-12-06 20:38:31

There is a sneaky trick, first create an interface that extends AppletContext and JSContext

private interface JSAwareAppletContext extends AppletContext, JSContext {
}

Then mock that somehow so you have an instance

final JSAwareAppletContext myAppletContext = //mock

Now you can mock the live connect stuff on the JSAwareAppletContext and return if from your AppletStub.

For example with Mockito:

final JSAwareAppletContext appletContext = mock(JSAwareAppletContext.class);
final JSObject jsObject = mock(JSObject.class);
when(appletContext.getJSObject()).thenReturn(jsObject);
final AppletStub appletStub = mock(AppletStub.class);
when(appletStub.getAppletContext()).thenReturn(appletContext);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!