method2testcases
stringlengths
118
3.08k
### Question: WXDomManager { public void removeDomStatement(String instanceId) { if (!WXUtils.isUiThread()) { throw new WXRuntimeException("[WXDomManager] removeDomStatement"); } final DOMActionContextImpl statement = mDomRegistries.remove(instanceId); if (statement != null) { post(new Runnable() { @Override public void run() { statement.destroy(); } }); } } WXDomManager(WXRenderManager renderManager); void sendEmptyMessageDelayed(int what, long delayMillis); void sendMessage(Message msg); void sendMessageDelayed(Message msg, long delay); void removeDomStatement(String instanceId); void post(Runnable task); void destroy(); void executeAction(String instanceId, DOMAction action, boolean createContext); void postAction(String instanceId,DOMAction action, boolean createContext); void postActionDelay(String instanceId,DOMAction action, boolean createContext, long delay); void postRenderTask(@NonNull String instanceId); }### Answer: @Test public void testRemoveDomStatement() throws Exception { dm.removeDomStatement(instance.getInstanceId()); }
### Question: WXBridge implements IWXBridge { public int callNative(String instanceId, byte [] tasks, String callback) { return callNative(instanceId,new String(tasks),callback); } native int initFramework(String framework, WXParams params); native int execJS(String instanceId, String namespace, String function, WXJSObject[] args); native int execJSService(String javascript); native void takeHeapSnapshot(String filename); int callNative(String instanceId, byte [] tasks, String callback); int callNative(String instanceId, String tasks, String callback); int callAddElement(String instanceId, String ref,byte[] dom,String index, String callback); int callCreateBody(String instanceId, byte [] tasks, String callback); int callCreateBody(String instanceId, String tasks, String callback); int callAddElement(String instanceId, String ref,String dom,String index, String callback); void reportJSException(String instanceId, String func, String exception); @Override Object callNativeModule(String instanceId, String module, String method, byte [] arguments, byte [] options); @Override void callNativeComponent(String instanceId, String componentRef, String method, byte [] arguments, byte [] options); void setTimeoutNative(String callbackId, String time); void setJSFrmVersion(String version); int callUpdateFinish(String instanceId, byte [] tasks, String callback); int callCreateFinish(String instanceId, byte [] tasks, String callback); int callRefreshFinish(String instanceId, byte [] tasks, String callback); int callUpdateAttrs(String instanceId, String ref, byte [] tasks, String callback); int callUpdateStyle(String instanceId, String ref, byte [] tasks, String callback); int callRemoveElement(String instanceId, String ref, String callback); int callMoveElement(String instanceId, String ref, String parentref, String index, String callback); int callAddEvent(String instanceId, String ref, String event, String callback); int callRemoveEvent(String instanceId, String ref, String event, String callback); static final String TAG; }### Answer: @Test public void testCallNative() throws Exception { bridge.callNative("1","{}","100"); }
### Question: WXBridge implements IWXBridge { public int callAddElement(String instanceId, String ref,byte[] dom,String index, String callback) { return callAddElement(instanceId,ref, new String(dom),index,callback); } native int initFramework(String framework, WXParams params); native int execJS(String instanceId, String namespace, String function, WXJSObject[] args); native int execJSService(String javascript); native void takeHeapSnapshot(String filename); int callNative(String instanceId, byte [] tasks, String callback); int callNative(String instanceId, String tasks, String callback); int callAddElement(String instanceId, String ref,byte[] dom,String index, String callback); int callCreateBody(String instanceId, byte [] tasks, String callback); int callCreateBody(String instanceId, String tasks, String callback); int callAddElement(String instanceId, String ref,String dom,String index, String callback); void reportJSException(String instanceId, String func, String exception); @Override Object callNativeModule(String instanceId, String module, String method, byte [] arguments, byte [] options); @Override void callNativeComponent(String instanceId, String componentRef, String method, byte [] arguments, byte [] options); void setTimeoutNative(String callbackId, String time); void setJSFrmVersion(String version); int callUpdateFinish(String instanceId, byte [] tasks, String callback); int callCreateFinish(String instanceId, byte [] tasks, String callback); int callRefreshFinish(String instanceId, byte [] tasks, String callback); int callUpdateAttrs(String instanceId, String ref, byte [] tasks, String callback); int callUpdateStyle(String instanceId, String ref, byte [] tasks, String callback); int callRemoveElement(String instanceId, String ref, String callback); int callMoveElement(String instanceId, String ref, String parentref, String index, String callback); int callAddEvent(String instanceId, String ref, String event, String callback); int callRemoveEvent(String instanceId, String ref, String event, String callback); static final String TAG; }### Answer: @Test public void testCallAddElement() throws Exception { bridge.callAddElement("1","1","{}","0","100"); }
### Question: WXBridge implements IWXBridge { public void reportJSException(String instanceId, String func, String exception) { WXBridgeManager.getInstance().reportJSException(instanceId, func, exception); } native int initFramework(String framework, WXParams params); native int execJS(String instanceId, String namespace, String function, WXJSObject[] args); native int execJSService(String javascript); native void takeHeapSnapshot(String filename); int callNative(String instanceId, byte [] tasks, String callback); int callNative(String instanceId, String tasks, String callback); int callAddElement(String instanceId, String ref,byte[] dom,String index, String callback); int callCreateBody(String instanceId, byte [] tasks, String callback); int callCreateBody(String instanceId, String tasks, String callback); int callAddElement(String instanceId, String ref,String dom,String index, String callback); void reportJSException(String instanceId, String func, String exception); @Override Object callNativeModule(String instanceId, String module, String method, byte [] arguments, byte [] options); @Override void callNativeComponent(String instanceId, String componentRef, String method, byte [] arguments, byte [] options); void setTimeoutNative(String callbackId, String time); void setJSFrmVersion(String version); int callUpdateFinish(String instanceId, byte [] tasks, String callback); int callCreateFinish(String instanceId, byte [] tasks, String callback); int callRefreshFinish(String instanceId, byte [] tasks, String callback); int callUpdateAttrs(String instanceId, String ref, byte [] tasks, String callback); int callUpdateStyle(String instanceId, String ref, byte [] tasks, String callback); int callRemoveElement(String instanceId, String ref, String callback); int callMoveElement(String instanceId, String ref, String parentref, String index, String callback); int callAddEvent(String instanceId, String ref, String event, String callback); int callRemoveEvent(String instanceId, String ref, String event, String callback); static final String TAG; }### Answer: @Test public void testReportJSException() throws Exception { bridge.reportJSException("1","test","some exception"); }
### Question: WXBridge implements IWXBridge { public void setTimeoutNative(String callbackId, String time) { WXBridgeManager.getInstance().setTimeout(callbackId, time); } native int initFramework(String framework, WXParams params); native int execJS(String instanceId, String namespace, String function, WXJSObject[] args); native int execJSService(String javascript); native void takeHeapSnapshot(String filename); int callNative(String instanceId, byte [] tasks, String callback); int callNative(String instanceId, String tasks, String callback); int callAddElement(String instanceId, String ref,byte[] dom,String index, String callback); int callCreateBody(String instanceId, byte [] tasks, String callback); int callCreateBody(String instanceId, String tasks, String callback); int callAddElement(String instanceId, String ref,String dom,String index, String callback); void reportJSException(String instanceId, String func, String exception); @Override Object callNativeModule(String instanceId, String module, String method, byte [] arguments, byte [] options); @Override void callNativeComponent(String instanceId, String componentRef, String method, byte [] arguments, byte [] options); void setTimeoutNative(String callbackId, String time); void setJSFrmVersion(String version); int callUpdateFinish(String instanceId, byte [] tasks, String callback); int callCreateFinish(String instanceId, byte [] tasks, String callback); int callRefreshFinish(String instanceId, byte [] tasks, String callback); int callUpdateAttrs(String instanceId, String ref, byte [] tasks, String callback); int callUpdateStyle(String instanceId, String ref, byte [] tasks, String callback); int callRemoveElement(String instanceId, String ref, String callback); int callMoveElement(String instanceId, String ref, String parentref, String index, String callback); int callAddEvent(String instanceId, String ref, String event, String callback); int callRemoveEvent(String instanceId, String ref, String event, String callback); static final String TAG; }### Answer: @Test public void testSetTimeoutNative() throws Exception { bridge.setTimeoutNative("100","1024"); }
### Question: WXBridge implements IWXBridge { public void setJSFrmVersion(String version) { if(!TextUtils.isEmpty(version)) { WXEnvironment.JS_LIB_SDK_VERSION = version; } } native int initFramework(String framework, WXParams params); native int execJS(String instanceId, String namespace, String function, WXJSObject[] args); native int execJSService(String javascript); native void takeHeapSnapshot(String filename); int callNative(String instanceId, byte [] tasks, String callback); int callNative(String instanceId, String tasks, String callback); int callAddElement(String instanceId, String ref,byte[] dom,String index, String callback); int callCreateBody(String instanceId, byte [] tasks, String callback); int callCreateBody(String instanceId, String tasks, String callback); int callAddElement(String instanceId, String ref,String dom,String index, String callback); void reportJSException(String instanceId, String func, String exception); @Override Object callNativeModule(String instanceId, String module, String method, byte [] arguments, byte [] options); @Override void callNativeComponent(String instanceId, String componentRef, String method, byte [] arguments, byte [] options); void setTimeoutNative(String callbackId, String time); void setJSFrmVersion(String version); int callUpdateFinish(String instanceId, byte [] tasks, String callback); int callCreateFinish(String instanceId, byte [] tasks, String callback); int callRefreshFinish(String instanceId, byte [] tasks, String callback); int callUpdateAttrs(String instanceId, String ref, byte [] tasks, String callback); int callUpdateStyle(String instanceId, String ref, byte [] tasks, String callback); int callRemoveElement(String instanceId, String ref, String callback); int callMoveElement(String instanceId, String ref, String parentref, String index, String callback); int callAddEvent(String instanceId, String ref, String event, String callback); int callRemoveEvent(String instanceId, String ref, String event, String callback); static final String TAG; }### Answer: @Test public void testSetJSFrmVersion() throws Exception { bridge.setJSFrmVersion("v0.1"); }
### Question: WXModuleManager { public static void destroyInstanceModules(String instanceId) { sDomModuleMap.remove(instanceId); Map<String, WXModule> moduleMap = sInstanceModuleMap.remove(instanceId); if (moduleMap == null || moduleMap.size() < 1) { return; } Iterator<Entry<String, WXModule>> iterator = moduleMap.entrySet().iterator(); Entry<String, WXModule> entry; while (iterator.hasNext()) { entry = iterator.next(); WXModule module = entry.getValue(); if(module instanceof Destroyable){ ((Destroyable)module).destroy(); } } } static boolean registerModule(final String moduleName, final ModuleFactory factory, final boolean global); static void onActivityCreate(String instanceId); static void onActivityStart(String instanceId); static void onActivityPause(String instanceId); static void onActivityResume(String instanceId); static void onActivityStop(String instanceId); static void onActivityDestroy(String instanceId); static boolean onActivityBack(String instanceId); static void onActivityResult(String instanceId,int requestCode, int resultCode, Intent data); static boolean onCreateOptionsMenu(String instanceId,Menu menu); static void onRequestPermissionsResult(String instanceId ,int requestCode, String[] permissions, int[] grantResults); static void destroyInstanceModules(String instanceId); static void createDomModule(WXSDKInstance instance); static void destoryDomModule(String instanceID); static WXDomModule getDomModule(String instanceId); static void reload(); }### Answer: @Test public void testDestroyInstanceModules() throws Exception { testCallModuleMethod(); WXModuleManager.destroyInstanceModules(instance.getInstanceId()); }
### Question: WXNavigatorModule extends WXModule { @JSMethod(uiThread = true) public void pop(String param, JSCallback callback) { if (WXSDKEngine.getActivityNavBarSetter() != null) { if (WXSDKEngine.getActivityNavBarSetter().pop(param)) { if (callback != null) { callback.invoke(MSG_SUCCESS); } return; } } if (mWXSDKInstance.getContext() instanceof Activity) { if (callback != null) { callback.invoke(MSG_SUCCESS); } ((Activity) mWXSDKInstance.getContext()).finish(); } } @JSMethod(uiThread = true) void open(JSONObject options, JSCallback success, JSCallback failure); @JSMethod(uiThread = true) void close(JSONObject options, JSCallback success, JSCallback failure); @JSMethod(uiThread = true) void push(String param, JSCallback callback); @JSMethod(uiThread = true) void pop(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarRightItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarRightItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarLeftItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarLeftItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarMoreItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarMoreItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarTitle(String param, JSCallback callback); @JSMethod void setNavBarHidden(String param, final String callback); static final String MSG_SUCCESS; static final String MSG_FAILED; static final String MSG_PARAM_ERR; static final String CALLBACK_RESULT; static final String CALLBACK_MESSAGE; }### Answer: @Test public void testPop() throws Exception { mockSetter(); module.pop("{}",callback); }
### Question: WXNavigatorModule extends WXModule { @JSMethod(uiThread = true) public void setNavBarRightItem(String param, JSCallback callback) { if (!TextUtils.isEmpty(param)) { if (WXSDKEngine.getActivityNavBarSetter() != null) { if (WXSDKEngine.getActivityNavBarSetter().setNavBarRightItem(param)) { if (callback != null) { callback.invoke(MSG_SUCCESS); } return; } } } if (callback != null) { callback.invoke(MSG_FAILED); } } @JSMethod(uiThread = true) void open(JSONObject options, JSCallback success, JSCallback failure); @JSMethod(uiThread = true) void close(JSONObject options, JSCallback success, JSCallback failure); @JSMethod(uiThread = true) void push(String param, JSCallback callback); @JSMethod(uiThread = true) void pop(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarRightItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarRightItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarLeftItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarLeftItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarMoreItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarMoreItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarTitle(String param, JSCallback callback); @JSMethod void setNavBarHidden(String param, final String callback); static final String MSG_SUCCESS; static final String MSG_FAILED; static final String MSG_PARAM_ERR; static final String CALLBACK_RESULT; static final String CALLBACK_MESSAGE; }### Answer: @Test public void testSetNavBarRightItem() throws Exception { mockSetter(); module.setNavBarRightItem("{}",callback); }
### Question: WXNavigatorModule extends WXModule { @JSMethod(uiThread = true) public void clearNavBarRightItem(String param, JSCallback callback) { if (WXSDKEngine.getActivityNavBarSetter() != null) { if (WXSDKEngine.getActivityNavBarSetter().clearNavBarRightItem(param)) { if (callback != null) { callback.invoke(MSG_SUCCESS); } return; } } if (callback != null) { callback.invoke(MSG_FAILED); } } @JSMethod(uiThread = true) void open(JSONObject options, JSCallback success, JSCallback failure); @JSMethod(uiThread = true) void close(JSONObject options, JSCallback success, JSCallback failure); @JSMethod(uiThread = true) void push(String param, JSCallback callback); @JSMethod(uiThread = true) void pop(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarRightItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarRightItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarLeftItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarLeftItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarMoreItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarMoreItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarTitle(String param, JSCallback callback); @JSMethod void setNavBarHidden(String param, final String callback); static final String MSG_SUCCESS; static final String MSG_FAILED; static final String MSG_PARAM_ERR; static final String CALLBACK_RESULT; static final String CALLBACK_MESSAGE; }### Answer: @Test public void testClearNavBarRightItem() throws Exception { mockSetter(); module.clearNavBarRightItem("{}",callback); }
### Question: WXNavigatorModule extends WXModule { @JSMethod(uiThread = true) public void setNavBarLeftItem(String param, JSCallback callback) { if (!TextUtils.isEmpty(param)) { if (WXSDKEngine.getActivityNavBarSetter() != null) { if (WXSDKEngine.getActivityNavBarSetter().setNavBarLeftItem(param)) { if (callback != null) { callback.invoke(MSG_SUCCESS); } return; } } } if (callback != null) { callback.invoke(MSG_FAILED); } } @JSMethod(uiThread = true) void open(JSONObject options, JSCallback success, JSCallback failure); @JSMethod(uiThread = true) void close(JSONObject options, JSCallback success, JSCallback failure); @JSMethod(uiThread = true) void push(String param, JSCallback callback); @JSMethod(uiThread = true) void pop(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarRightItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarRightItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarLeftItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarLeftItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarMoreItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarMoreItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarTitle(String param, JSCallback callback); @JSMethod void setNavBarHidden(String param, final String callback); static final String MSG_SUCCESS; static final String MSG_FAILED; static final String MSG_PARAM_ERR; static final String CALLBACK_RESULT; static final String CALLBACK_MESSAGE; }### Answer: @Test public void testSetNavBarLeftItem() throws Exception { mockSetter(); module.setNavBarLeftItem("{}",callback); }
### Question: WXNavigatorModule extends WXModule { @JSMethod(uiThread = true) public void clearNavBarLeftItem(String param, JSCallback callback) { if (WXSDKEngine.getActivityNavBarSetter() != null) { if (WXSDKEngine.getActivityNavBarSetter().clearNavBarLeftItem(param)) { if (callback != null) { callback.invoke(MSG_SUCCESS); } return; } } if (callback != null) { callback.invoke(MSG_FAILED); } } @JSMethod(uiThread = true) void open(JSONObject options, JSCallback success, JSCallback failure); @JSMethod(uiThread = true) void close(JSONObject options, JSCallback success, JSCallback failure); @JSMethod(uiThread = true) void push(String param, JSCallback callback); @JSMethod(uiThread = true) void pop(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarRightItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarRightItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarLeftItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarLeftItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarMoreItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarMoreItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarTitle(String param, JSCallback callback); @JSMethod void setNavBarHidden(String param, final String callback); static final String MSG_SUCCESS; static final String MSG_FAILED; static final String MSG_PARAM_ERR; static final String CALLBACK_RESULT; static final String CALLBACK_MESSAGE; }### Answer: @Test public void testClearNavBarLeftItem() throws Exception { mockSetter(); module.clearNavBarLeftItem("{}",callback); }
### Question: WXNavigatorModule extends WXModule { @JSMethod(uiThread = true) public void setNavBarMoreItem(String param, JSCallback callback) { if (!TextUtils.isEmpty(param)) { if (WXSDKEngine.getActivityNavBarSetter() != null) { if (WXSDKEngine.getActivityNavBarSetter().setNavBarMoreItem(param)) { if (callback != null) { callback.invoke(MSG_SUCCESS); } return; } } } if (callback != null) { callback.invoke(MSG_FAILED); } } @JSMethod(uiThread = true) void open(JSONObject options, JSCallback success, JSCallback failure); @JSMethod(uiThread = true) void close(JSONObject options, JSCallback success, JSCallback failure); @JSMethod(uiThread = true) void push(String param, JSCallback callback); @JSMethod(uiThread = true) void pop(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarRightItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarRightItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarLeftItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarLeftItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarMoreItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarMoreItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarTitle(String param, JSCallback callback); @JSMethod void setNavBarHidden(String param, final String callback); static final String MSG_SUCCESS; static final String MSG_FAILED; static final String MSG_PARAM_ERR; static final String CALLBACK_RESULT; static final String CALLBACK_MESSAGE; }### Answer: @Test public void testSetNavBarMoreItem() throws Exception { mockSetter(); module.setNavBarMoreItem("{}",callback); }
### Question: WXNavigatorModule extends WXModule { @JSMethod(uiThread = true) public void clearNavBarMoreItem(String param, JSCallback callback) { if (WXSDKEngine.getActivityNavBarSetter() != null) { if (WXSDKEngine.getActivityNavBarSetter().clearNavBarMoreItem(param)) { if (callback != null) { callback.invoke(MSG_SUCCESS); } return; } } if (callback != null) { callback.invoke(MSG_FAILED); } } @JSMethod(uiThread = true) void open(JSONObject options, JSCallback success, JSCallback failure); @JSMethod(uiThread = true) void close(JSONObject options, JSCallback success, JSCallback failure); @JSMethod(uiThread = true) void push(String param, JSCallback callback); @JSMethod(uiThread = true) void pop(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarRightItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarRightItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarLeftItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarLeftItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarMoreItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarMoreItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarTitle(String param, JSCallback callback); @JSMethod void setNavBarHidden(String param, final String callback); static final String MSG_SUCCESS; static final String MSG_FAILED; static final String MSG_PARAM_ERR; static final String CALLBACK_RESULT; static final String CALLBACK_MESSAGE; }### Answer: @Test public void testClearNavBarMoreItem() throws Exception { mockSetter(); module.clearNavBarMoreItem("{}",callback); }
### Question: WXNavigatorModule extends WXModule { @JSMethod(uiThread = true) public void setNavBarTitle(String param, JSCallback callback) { if (!TextUtils.isEmpty(param)) { if (WXSDKEngine.getActivityNavBarSetter() != null) { if (WXSDKEngine.getActivityNavBarSetter().setNavBarTitle(param)) { if (callback != null) { callback.invoke(MSG_SUCCESS); } return; } } } if (callback != null) { callback.invoke(MSG_FAILED); } } @JSMethod(uiThread = true) void open(JSONObject options, JSCallback success, JSCallback failure); @JSMethod(uiThread = true) void close(JSONObject options, JSCallback success, JSCallback failure); @JSMethod(uiThread = true) void push(String param, JSCallback callback); @JSMethod(uiThread = true) void pop(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarRightItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarRightItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarLeftItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarLeftItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarMoreItem(String param, JSCallback callback); @JSMethod(uiThread = true) void clearNavBarMoreItem(String param, JSCallback callback); @JSMethod(uiThread = true) void setNavBarTitle(String param, JSCallback callback); @JSMethod void setNavBarHidden(String param, final String callback); static final String MSG_SUCCESS; static final String MSG_FAILED; static final String MSG_PARAM_ERR; static final String CALLBACK_RESULT; static final String CALLBACK_MESSAGE; }### Answer: @Test public void testSetNavBarTitle() throws Exception { mockSetter(); module.setNavBarTitle("{}",callback); }
### Question: WXImage extends WXComponent<ImageView> { @WXComponentProp(name = Constants.Name.RESIZE_MODE) public void setResizeMode(String resizeMode) { (getHostView()).setScaleType(getResizeMode(resizeMode)); } @Deprecated WXImage(WXSDKInstance instance, WXDomObject dom, WXVContainer parent, String instanceId, boolean isLazy); WXImage(WXSDKInstance instance, WXDomObject node, WXVContainer parent); @Override void refreshData(WXComponent component); @WXComponentProp(name = Constants.Name.RESIZE_MODE) void setResizeMode(String resizeMode); @WXComponentProp(name = Constants.Name.RESIZE) void setResize(String resize); @WXComponentProp(name = Constants.Name.SRC) void setSrc(String src); @Override void recycled(); @Override void updateProperties(Map<String, Object> props); @JSMethod(uiThread = false) void save(final JSCallback saveStatuCallback); static final String SUCCEED; static final String ERRORDESC; }### Answer: @Test public void testSetResizeMode() throws Exception { ImageView imageView = mWXImage.initComponentHostView(Robolectric.setupActivity(TestActivity.class)); mWXImage.mHost = imageView; mWXImage.setResizeMode("cover"); ImageView.ScaleType scaleType = mWXImage.getHostView().getScaleType(); assertEquals(scaleType, ImageView.ScaleType.CENTER_CROP); }
### Question: WXImage extends WXComponent<ImageView> { @WXComponentProp(name = Constants.Name.RESIZE) public void setResize(String resize) { (getHostView()).setScaleType(getResizeMode(resize)); } @Deprecated WXImage(WXSDKInstance instance, WXDomObject dom, WXVContainer parent, String instanceId, boolean isLazy); WXImage(WXSDKInstance instance, WXDomObject node, WXVContainer parent); @Override void refreshData(WXComponent component); @WXComponentProp(name = Constants.Name.RESIZE_MODE) void setResizeMode(String resizeMode); @WXComponentProp(name = Constants.Name.RESIZE) void setResize(String resize); @WXComponentProp(name = Constants.Name.SRC) void setSrc(String src); @Override void recycled(); @Override void updateProperties(Map<String, Object> props); @JSMethod(uiThread = false) void save(final JSCallback saveStatuCallback); static final String SUCCEED; static final String ERRORDESC; }### Answer: @Test public void testSetResize() throws Exception { ImageView imageView = mWXImage.initComponentHostView(Robolectric.setupActivity(TestActivity.class)); mWXImage.mHost = imageView; mWXImage.setResize("cover"); ImageView.ScaleType scaleType = mWXImage.getHostView().getScaleType(); assertEquals(scaleType, ImageView.ScaleType.CENTER_CROP); }
### Question: WXImage extends WXComponent<ImageView> { @WXComponentProp(name = Constants.Name.SRC) public void setSrc(String src) { if (src == null) { return; } ImageView image = getHostView(); if("".equals(src) && image != null){ image.setImageDrawable(null); return; } this.mSrc = src; WXSDKInstance instance = getInstance(); Uri rewrited = instance.rewriteUri(Uri.parse(src), URIAdapter.IMAGE); if (Constants.Scheme.LOCAL.equals(rewrited.getScheme())) { setLocalSrc(rewrited); } else { int blur = 0; if(getDomObject() != null) { String blurStr = getDomObject().getStyles().getBlur(); blur = parseBlurRadius(blurStr); } setRemoteSrc(rewrited, blur); } } @Deprecated WXImage(WXSDKInstance instance, WXDomObject dom, WXVContainer parent, String instanceId, boolean isLazy); WXImage(WXSDKInstance instance, WXDomObject node, WXVContainer parent); @Override void refreshData(WXComponent component); @WXComponentProp(name = Constants.Name.RESIZE_MODE) void setResizeMode(String resizeMode); @WXComponentProp(name = Constants.Name.RESIZE) void setResize(String resize); @WXComponentProp(name = Constants.Name.SRC) void setSrc(String src); @Override void recycled(); @Override void updateProperties(Map<String, Object> props); @JSMethod(uiThread = false) void save(final JSCallback saveStatuCallback); static final String SUCCEED; static final String ERRORDESC; }### Answer: @Test public void testSetSrc() throws Exception { TestDomObject.setAttribute((WXDomObject)mWXImage.getDomObject(),PowerMockito.mock(WXAttr.class)); PowerMockito.when(mWXImage.getDomObject().getAttrs().getImageSharpen()).thenReturn(WXImageSharpen.SHARPEN); mWXImage.setSrc(""); }
### Question: DefaultDragHelper implements DragHelper { @Override public void onDragStart(@NonNull WXComponent component, int from) { if (WXEnvironment.isApkDebugable()) { WXLogUtils.d(TAG, "list on drag start : from index " + from); } mEventTrigger.triggerEvent(EVENT_START_DRAG, buildEvent(component.getRef(), from, -1)); } DefaultDragHelper(@NonNull List<WXComponent> dataSource, @NonNull RecyclerView recyclerView, @NonNull EventTrigger trigger); @Override void onDragStart(@NonNull WXComponent component, int from); @Override void onDragEnd(@NonNull WXComponent component, int from, int to); @Override void onDragging(int fromPos, int toPos); @Override boolean isLongPressDragEnabled(); @Override void setLongPressDragEnabled(boolean enabled); @Override void startDrag(@NonNull RecyclerView.ViewHolder viewHolder); @Override boolean isDraggable(); @Override void setDraggable(boolean draggable); @Override void setDragExcluded(@NonNull RecyclerView.ViewHolder viewHolder, boolean isExcluded); @Override boolean isDragExcluded(@NonNull RecyclerView.ViewHolder viewHolder); }### Answer: @Test public void onDragStart() throws Exception { WXComponent c = new WXCell(WXSDKInstanceTest.createInstance(),new TestDomObject(),null,false); mFakeDragHelper.onDragStart(c,3); verify(mockedEventTrigger).triggerEvent(eq("dragstart"),anyMap()); }
### Question: AnnotationSpans { public static AnnotationSpans extractAnnotationSpans(JCas jCas) { BidiMap sentenceBeginIndexToCharacterIndex = new TreeBidiMap(); BidiMap sentenceEndIndexToCharacterIndex = new TreeBidiMap(); List<Sentence> sentences = new ArrayList<>(JCasUtil.select(jCas, Sentence.class)); for (int i = 0; i < sentences.size(); i++) { Sentence sentence = sentences.get(i); sentenceBeginIndexToCharacterIndex.put(i, sentence.getBegin()); sentenceEndIndexToCharacterIndex.put(i, sentence.getEnd()); } AnnotationSpans annotationSpans = new AnnotationSpans( sentenceBeginIndexToCharacterIndex.size()); Collection<ArgumentComponent> components = JCasUtil.select(jCas, ArgumentComponent.class); for (ArgumentComponent component : components) { if (!ArgumentUnitUtils.isImplicit(component)) { int relativeOffset = (int) sentenceBeginIndexToCharacterIndex .getKey(component.getBegin()); int endingSentenceIndex = (int) sentenceEndIndexToCharacterIndex .getKey(component.getEnd()); int length = endingSentenceIndex - relativeOffset + 1; String type = component.getType().getShortName(); SingleAnnotationSpan singleAnnotationSpan = new SingleAnnotationSpan(type, relativeOffset, length); annotationSpans.getAnnotationSpans().add(singleAnnotationSpan); } } return annotationSpans; } AnnotationSpans(int documentLength); static AnnotationSpans extractAnnotationSpans(JCas jCas); int getDocumentLength(); List<SingleAnnotationSpan> getAnnotationSpans(); @Override String toString(); }### Answer: @Test public void extractAnnotationSpans() throws Exception { System.out.println(AnnotationSpans.extractAnnotationSpans(jCas)); }
### Question: NumberResource { @GET @Path("book") @ApiOperation(value = "Generates a book number.", response = String.class) public Response generateBookNumber() throws InterruptedException { final Config config = ConfigProvider.getConfig(); config.getOptionalValue("NUMBER_API_FAKE_TIMEOUT", Integer.class).ifPresent(t -> numberApiFakeTimeout = t); log.info("Waiting for " + numberApiFakeTimeout + " seconds"); TimeUnit.SECONDS.sleep(numberApiFakeTimeout); log.info("Generating a book number"); return Response.ok("BK-" + Math.random()).build(); } @GET @Path("book") @ApiOperation(value = "Generates a book number.", response = String.class) Response generateBookNumber(); @GET @Path("health") @ApiOperation(value = "Health of this REST endpoint", response = String.class) Response health(); }### Answer: @Test public void generateBookNumber() throws Exception { final Response response = webTarget.path("book").request().get(); assertEquals(OK.getStatusCode(), response.getStatus()); assertTrue(response.readEntity(String.class).startsWith("BK-")); }
### Question: NumberResource { @GET @Path("book") @ApiOperation(value = "Generates a book number.", response = String.class) public Response generateBookNumber() { log.info("Generating a book number"); return Response.ok("BK-" + Math.random()).build(); } @GET @Path("book") @ApiOperation(value = "Generates a book number.", response = String.class) Response generateBookNumber(); @GET @Path("health") @ApiOperation(value = "Health of this REST endpoint", response = String.class) Response health(); }### Answer: @Test public void generateBookNumber() throws Exception { final Response response = webTarget.path("book").request().get(); assertEquals(OK.getStatusCode(), response.getStatus()); assertTrue(response.readEntity(String.class).startsWith("BK-")); }
### Question: NumberResource { @GET @Path("book") @ApiOperation(value = "Generates a book number.", response = String.class) public Response generateBookNumber() throws InterruptedException { final Config config = ConfigProvider.getConfig(); config.getOptionalValue("NUMBER_API_FAKE_TIMEOUT", Integer.class).ifPresent(t -> numberApiFakeTimeout = t); log.info("Waiting for " + numberApiFakeTimeout + " seconds"); TimeUnit.SECONDS.sleep(numberApiFakeTimeout); log.info("Generating a book number"); return Response.ok("BK-" + Math.random()).build(); } @GET @Path("book") @ApiOperation(value = "Generates a book number.", response = String.class) Response generateBookNumber(); @GET @Path("health") @ApiOperation(value = "Checks the health of this REST endpoint", response = String.class) Response health(); }### Answer: @Test public void generateBookNumber() throws Exception { final Response response = webTarget.path("book").request().get(); assertEquals(OK.getStatusCode(), response.getStatus()); assertTrue(response.readEntity(String.class).startsWith("BK-")); }
### Question: NumberResource { @GET @Path("book") @ApiOperation(value = "Generates a book number.", response = String.class) public Response generateBookNumber() { log.info("Generating a book number"); return Response.ok("BK-" + Math.random()).build(); } @GET @Path("book") // tag::adocSwagger[] @ApiOperation(value = "Generates a book number.", response = String.class) // end::adocSwagger[] Response generateBookNumber(); }### Answer: @Test public void generateBookNumber() throws Exception { final Response response = webTarget.path("book").request().get(); assertEquals(OK.getStatusCode(), response.getStatus()); assertTrue(response.readEntity(String.class).startsWith("BK-")); }
### Question: NumberResource { @GET @Path("book") @ApiOperation(value = "Generates a book number.", response = String.class) public Response generateBookNumber() { log.info("Generating a book number"); return Response.ok("BK-" + Math.random()).build(); } @GET @Path("book") @ApiOperation(value = "Generates a book number.", response = String.class) Response generateBookNumber(); }### Answer: @Test public void generateBookNumber() throws Exception { final Response response = webTarget.path("book").request().get(); assertEquals(OK.getStatusCode(), response.getStatus()); assertTrue(response.readEntity(String.class).startsWith("BK-")); }
### Question: SpanTemplate implements SpanOperations { @Override public ActiveSpan startActive(String name) { return tracer.buildSpan(name) .startActive(); } SpanTemplate(Tracer tracer); @Override void doInTracer(SpanCallback callback); @Override Span start(String name); @Override ActiveSpan startActive(String name); @Override ActiveSpan startActive(String name, ActiveSpan parent); @Override ActiveSpan startActive(String name, SpanContext parent); @Override void inject(SpanContext ctx, HttpHeaders headers); @Override SpanContext extract(Map<String, Object> map); }### Answer: @Test public void testStartActive() throws InterruptedException { try (ActiveSpan span = spanOps.startActive("hello sematextains")) { span.setTag("app", "console"); } Thread.sleep(2000); } @Test public void testStartActiveWithParent() throws InterruptedException { try (ActiveSpan parent = spanOps.startActive("parent")) { parent.setTag("app", "console"); Thread.sleep(500); try (ActiveSpan child = spanOps.startActive("child", parent)) { child.setTag("encoding", "utf-8"); } } Thread.sleep(2000); }
### Question: SpanTemplate implements SpanOperations { @Override public void inject(SpanContext ctx, HttpHeaders headers) { HttpHeadersInjectAdapter injectAdapter = new HttpHeadersInjectAdapter(headers); tracer.inject(ctx, Format.Builtin.HTTP_HEADERS, injectAdapter); } SpanTemplate(Tracer tracer); @Override void doInTracer(SpanCallback callback); @Override Span start(String name); @Override ActiveSpan startActive(String name); @Override ActiveSpan startActive(String name, ActiveSpan parent); @Override ActiveSpan startActive(String name, SpanContext parent); @Override void inject(SpanContext ctx, HttpHeaders headers); @Override SpanContext extract(Map<String, Object> map); }### Answer: @Test public void testInject() { try (ActiveSpan span = spanOps.startActive("parent")) { Map<String, Object> map = new HashMap<>(); map.put("app", "console"); HttpHeaders headers = new HttpHeaders(); spanOps.inject(span.context(), headers); } }
### Question: FileRecorder extends MetricRecorder<MetricRecorder.RecorderContext> { static boolean isValid(final Metric label) { final String str = label.toString(); return !(str.contains("\n") || str.contains(",") || str.contains(":") || str.contains("=")); } FileRecorder(final String filename); static final FileRecorder withAutoShutdown( final String filename); void shutdown(); }### Answer: @Test public void validation() { final String[] good = { "snake_case_metric", "camelCaseMetric", "hyphenated-metric", "spaced out metric", "digits 0123456789", "G\u00FCnther", "\t!\"#$%&'()*+./;<>?@[\\]^`{|}~" }; for (final String s : good) { assertTrue("valid name [" + s + "]", FileRecorder.isValid(Metric.define(s))); } final String[] bad = { "metric_name, dimension=value", "metric_name:100ms:", "metric_name\nmetric", "metric=metric_name" }; for (final String s : bad) { assertFalse("invalid name [" + s + "]", FileRecorder.isValid(Metric.define(s))); } }
### Question: DoubleFormat { public static void format(Appendable sb, double value) { try { format_exception(sb, value); } catch (IOException e) { throw new IllegalStateException("Appendable must not throw IOException", e); } } private DoubleFormat(); static void format(Appendable sb, double value); }### Answer: @Test public void benchmark() throws Exception { final long iterations = 1000000; long duration_StringFormat = run_benchmark(iterations, (a) -> String.format("%.6f", a)); NumberFormat javaFormatter = NumberFormat.getInstance(); javaFormatter.setMinimumFractionDigits(0); javaFormatter.setMaximumFractionDigits(6); javaFormatter.setGroupingUsed(false); long duration_JavaFormat = run_benchmark(iterations, (a) -> javaFormatter.format(a)); long duration_JavaStringBuilder = run_benchmark(iterations, (a) -> (new StringBuilder()).append(a)); long duration_DoubleFormat = run_benchmark(iterations, (a) -> DoubleFormat.format(new StringBuilder(), a)); System.out.println("DoubleFormat Performance comparison: " + iterations +" iterations"); System.out.println("\tJava String.format: " + duration_StringFormat + " ms"); System.out.println("\tJava NumberFormat: " + duration_JavaFormat + " ms"); System.out.println("\tJava StringBuilder: " + duration_JavaStringBuilder + " ms"); System.out.println("\tDoubleFormat: " + duration_DoubleFormat + " ms"); assertTrue(duration_DoubleFormat < duration_StringFormat); assertTrue(duration_DoubleFormat < duration_JavaFormat); assertTrue(duration_DoubleFormat < duration_JavaStringBuilder); }
### Question: ContextAwareExecutor implements Executor { @Override public void execute(Runnable command) { executor.execute(ThreadContext.current().wrap(command)); } ContextAwareExecutor(Executor executor); @Override void execute(Runnable command); }### Answer: @Test public void currentContextIsPropagatedToTask() throws Exception { ThreadContext context = ThreadContext.emptyContext().with(KEY, "value"); try (ThreadContext.CloseableContext ignored = context.open()) { executor.execute(captureTask); } latch.await(); assertSame(context, contextCapture.get()); } @Test public void withNoContextDefaultIsUsed() throws Exception { executor.execute(captureTask); latch.await(); assertSame(ThreadContext.emptyContext(), contextCapture.get()); }
### Question: ImmutableTypedMap implements TypedMap { @Override public Set<Key> keySet() { return this.dataMap.keySet(); } private ImmutableTypedMap(Map<Key<?>, Entry<?>> dataMap); @Override final T get(Key<T> key); @Override int size(); @Override boolean isEmpty(); @Override Iterator<Entry> iterator(); @Override Iterator<Entry<T>> typedIterator(Class<T> clazz); @Override Set<Key> keySet(); @Override Set<Key<T>> typedKeySet(final Class<T> clazz); @Override boolean containsKey(final Key<?> key); @Override boolean containsValue(final Object value); }### Answer: @Test public void keyset() throws Exception { final TypedMap.Key<Double> ka = TypedMap.key("Alpha", Double.class); final TypedMap.Key<String> kb = TypedMap.key("Beta", String.class); final TypedMap.Key<UUID> kc = TypedMap.key("Gamma", UUID.class); final TypedMap.Key<Object> kd = TypedMap.key("Delta", Object.class); final Double va = Double.valueOf(867.5309); final String vb = "Here is a string, with...\nmultiple lines and stuff."; final UUID vc = UUID.randomUUID(); final Object vd = new Object(); TypedMap data = ImmutableTypedMap.Builder .with(kc, vc) .add(ka, va) .add(kb, vb) .add(kd, vd) .build(); Set<TypedMap.Key> s = data.keySet(); assertEquals("Set of keys has wrong size", 4, s.size()); assertTrue("Set of keys is missing a key", s.contains(ka)); assertTrue("Set of keys is missing a key", s.contains(kb)); assertTrue("Set of keys is missing a key", s.contains(kc)); assertTrue("Set of keys is missing a key", s.contains(kd)); }
### Question: NullContext implements MetricContext { @Override public TypedMap attributes() { return attributes; } NullContext(TypedMap attributes); NullContext(TypedMap attributes, MetricContext parent); static NullContext empty(); @Override TypedMap attributes(); @Override void record(Metric label, Number value, Unit unit, Instant time); @Override void count(Metric label, long delta); @Override void close(); @Override MetricContext newChild(TypedMap attributes); @Override MetricContext parent(); }### Answer: @Test public void nullContextCanHaveAttributes() { TypedMap.Key<String> ID = TypedMap.key("ID", String.class); TypedMap attributes = ImmutableTypedMap.Builder.with(ID, "id").build(); NullContext context = new NullContext(attributes); assertSame(attributes, context.attributes()); }
### Question: Metric { public static Metric define(final String name) { return new Metric(name); } private Metric(final String name); static Metric define(final String name); @Override final String toString(); @Override boolean equals(final Object o); @Override int hashCode(); }### Answer: @Test public void validation() throws Exception { final String[] goods = { "snake_case_metric", "camelCaseMetric", "hyphenated-metric", "spaced out metric", "digits 0123456789", "G\u00FCnther", "\t\n!\"#$%&'()*+,./:;<=>?@[\\]^`{|}~", " " }; for (String s : goods) { Metric.define(s); } final String[] bads = { null, "" }; for (String s : bads) { try { Metric.define(""); } catch (IllegalArgumentException expected) { continue; } fail("Expected exception not thrown for bad name '"+s+"'"); } }
### Question: MultiRecorder extends MetricRecorder<MultiRecorder.MultiRecorderContext> { @Override protected void record(Metric label, Number value, Unit unit, Instant time, MultiRecorderContext context) { context.contexts.parallelStream().forEach(t -> t.record(label, value, unit, time)); } MultiRecorder(List<MetricRecorder<?>> recorders); }### Answer: @Test public void recordIsSentToAllDelegates() { MetricContext context = recorder.context(attributes); context.record(METRIC, 42L, Unit.NONE, timestamp); verify(delegate1).record(eq(METRIC), eq(42L), eq(Unit.NONE), eq(timestamp), argThat(t -> attributes == t.attributes())); verify(delegate2).record(eq(METRIC), eq(42L), eq(Unit.NONE), eq(timestamp), argThat(t -> attributes == t.attributes())); }
### Question: MultiRecorder extends MetricRecorder<MultiRecorder.MultiRecorderContext> { @Override protected void count(Metric label, long delta, MultiRecorderContext context) { context.contexts.parallelStream().forEach(t -> t.count(label, delta)); } MultiRecorder(List<MetricRecorder<?>> recorders); }### Answer: @Test public void countIsSentToAllDelegates() { MetricContext context = recorder.context(attributes); context.count(METRIC, 42L); verify(delegate1).count(eq(METRIC), eq(42L), argThat(t -> attributes == t.attributes())); verify(delegate2).count(eq(METRIC), eq(42L), argThat(t -> attributes == t.attributes())); }
### Question: MultiRecorder extends MetricRecorder<MultiRecorder.MultiRecorderContext> { @Override protected void close(MultiRecorderContext context) { context.contexts.parallelStream().forEach(MetricContext::close); } MultiRecorder(List<MetricRecorder<?>> recorders); }### Answer: @Test public void closeIsSentToAllDelegates() { MetricContext context = recorder.context(attributes); context.close(); verify(delegate1).close(argThat(t -> attributes == t.attributes())); verify(delegate2).close(argThat(t -> attributes == t.attributes())); }