本文整理汇总了Java中org.robolectric.util.ReflectionHelpers.callInstanceMethod方法的典型用法代码示例。如果您正苦于以下问题:Java ReflectionHelpers.callInstanceMethod方法的具体用法?Java ReflectionHelpers.callInstanceMethod怎么用?Java ReflectionHelpers.callInstanceMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.robolectric.util.ReflectionHelpers
的用法示例。
在下文中一共展示了ReflectionHelpers.callInstanceMethod方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resetWindowManager
import org.robolectric.util.ReflectionHelpers; //导入方法依赖的package包/类
private void resetWindowManager() {
Class clazz = ReflectionHelpers.loadClass(getClass().getClassLoader(), "android.view.WindowManagerGlobal");
Object instance = ReflectionHelpers.callStaticMethod(clazz, "getInstance");
// We essentially duplicate what's in {@link WindowManagerGlobal#closeAll} with what's below.
// The closeAll method has a bit of a bug where it's iterating through the "roots" but
// bases the number of objects to iterate through by the number of "views." This can result in
// an {@link java.lang.IndexOutOfBoundsException} being thrown.
Object lock = ReflectionHelpers.getField(instance, "mLock");
ArrayList<Object> roots = ReflectionHelpers.getField(instance, "mRoots");
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (lock) {
for (int i = 0; i < roots.size(); i++) {
ReflectionHelpers.callInstanceMethod(instance, "removeViewLocked",
ReflectionHelpers.ClassParameter.from(int.class, i),
ReflectionHelpers.ClassParameter.from(boolean.class, false));
}
}
// Views will still be held by this array. We need to clear it out to ensure
// everything is released.
Collection<View> dyingViews = ReflectionHelpers.getField(instance, "mDyingViews");
dyingViews.clear();
}
示例2: onBrowserSwitchResult_whenResultIsError_reportsError
import org.robolectric.util.ReflectionHelpers; //导入方法依赖的package包/类
@Test
public void onBrowserSwitchResult_whenResultIsError_reportsError() {
BrowserSwitchResult result = BrowserSwitchResult.ERROR;
ReflectionHelpers.callInstanceMethod(result, "setErrorMessage",
new ReflectionHelpers.ClassParameter<>(String.class, "Browser switch error"));
mPopupBridge.onBrowserSwitchResult(1, result, null);
assertEquals("new Error('Browser switch error')", mWebView.mError);
}
示例3: resetWindowManager
import org.robolectric.util.ReflectionHelpers; //导入方法依赖的package包/类
@SuppressLint("NewApi")
@After
public void resetWindowManager() throws Exception {
// https://github.com/robolectric/robolectric/pull/1741
final Class<?> btclass = Class.forName("com.android.internal.os.BackgroundThread");
Object backgroundThreadSingleton = ReflectionHelpers.getStaticField(btclass,"sInstance");
if (backgroundThreadSingleton!=null) {
btclass.getMethod("quit").invoke(backgroundThreadSingleton);
ReflectionHelpers.setStaticField(btclass, "sInstance", null);
ReflectionHelpers.setStaticField(btclass, "sHandler", null);
}
// https://github.com/robolectric/robolectric/issues/2068
Class clazz = ReflectionHelpers.loadClass(getClass().getClassLoader(), "android.view.WindowManagerGlobal");
Object instance = ReflectionHelpers.callStaticMethod(clazz, "getInstance");
// We essentially duplicate what's in {@link WindowManagerGlobal#closeAll} with what's below.
// The closeAll method has a bit of a bug where it's iterating through the "roots" but
// bases the number of objects to iterate through by the number of "views." This can result in
// an {@link java.lang.IndexOutOfBoundsException} being thrown.
Object lock = ReflectionHelpers.getField(instance, "mLock");
ArrayList<Object> roots = ReflectionHelpers.getField(instance, "mRoots");
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (lock) {
for (int i = 0; i < roots.size(); i++) {
ReflectionHelpers.callInstanceMethod(instance, "removeViewLocked",
ReflectionHelpers.ClassParameter.from(int.class, i),
ReflectionHelpers.ClassParameter.from(boolean.class, false));
}
}
// Views will still be held by this array. We need to clear it out to ensure
// everything is released.
ArraySet<View> dyingViews = ReflectionHelpers.getField(instance, "mDyingViews");
dyingViews.clear();
}
示例4: globalTearDown
import org.robolectric.util.ReflectionHelpers; //导入方法依赖的package包/类
/**
* Try and avoid Robolectric OOM errors
* Probably this: https://github.com/robolectric/robolectric/issues/2068
* Based on code from https://github.com/robolectric/robolectric/issues/1700#issuecomment-163943815
*/
@After
public void globalTearDown() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
// https://github.com/robolectric/robolectric/pull/1741
final Class<?> btclass = Class.forName("com.android.internal.os.BackgroundThread");
Object backgroundThreadSingleton = ReflectionHelpers.getStaticField(btclass,"sInstance");
if (backgroundThreadSingleton!=null) {
btclass.getMethod("quit").invoke(backgroundThreadSingleton);
ReflectionHelpers.setStaticField(btclass, "sInstance", null);
ReflectionHelpers.setStaticField(btclass, "sHandler", null);
}
// https://github.com/robolectric/robolectric/issues/2068
Class clazz = ReflectionHelpers.loadClass(getClass().getClassLoader(), "android.view.WindowManagerGlobal");
Object instance = ReflectionHelpers.callStaticMethod(clazz, "getInstance");
// We essentially duplicate what's in {@link WindowManagerGlobal#closeAll} with what's below.
// The closeAll method has a bit of a bug where it's iterating through the "roots" but
// bases the number of objects to iterate through by the number of "views." This can result in
// an {@link java.lang.IndexOutOfBoundsException} being thrown.
Object lock = ReflectionHelpers.getField(instance, "mLock");
ArrayList<Object> roots = ReflectionHelpers.getField(instance, "mRoots");
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (lock) {
for (int i = 0; i < roots.size(); i++) {
ReflectionHelpers.callInstanceMethod(instance, "removeViewLocked",
ReflectionHelpers.ClassParameter.from(int.class, i),
ReflectionHelpers.ClassParameter.from(boolean.class, false));
}
}
// Views will still be held by this array. We need to clear it out to ensure
// everything is released.
Collection<View> dyingViews = ReflectionHelpers.getField(instance, "mDyingViews");
dyingViews.clear();
}
示例5: getAttachStateListeners
import org.robolectric.util.ReflectionHelpers; //导入方法依赖的package包/类
private static List<OnAttachStateChangeListener> getAttachStateListeners(View view) {
Object listenerInfo = ReflectionHelpers.callInstanceMethod(view, "getListenerInfo");
return ReflectionHelpers.getField(listenerInfo, "mOnAttachStateChangeListeners");
}
示例6: exitLayout
import org.robolectric.util.ReflectionHelpers; //导入方法依赖的package包/类
private void exitLayout() {
if (recyclerView != null && recyclerView.isComputingLayout()) {
ReflectionHelpers.callInstanceMethod(recyclerView, "onExitLayoutOrScroll");
}
}
示例7: getAttachStateChangeListeners
import org.robolectric.util.ReflectionHelpers; //导入方法依赖的package包/类
/**
* Manually retrieve the view's attach state change listeners of an event. Robolectric
* doesn't currently support manually firing these, and it would seem the events are not called
* in normal Robolectric usage either.
*
* @param view View with listeners to notify
*/
static CopyOnWriteArrayList<View.OnAttachStateChangeListener> getAttachStateChangeListeners(View view) {
Object listenerInfo = ReflectionHelpers.callInstanceMethod(view, "getListenerInfo");
return ReflectionHelpers.getField(listenerInfo, "mOnAttachStateChangeListeners");
}