当前位置: 首页>>代码示例>>Java>>正文


Java ReflectionHelpers.getField方法代码示例

本文整理汇总了Java中org.robolectric.util.ReflectionHelpers.getField方法的典型用法代码示例。如果您正苦于以下问题:Java ReflectionHelpers.getField方法的具体用法?Java ReflectionHelpers.getField怎么用?Java ReflectionHelpers.getField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.robolectric.util.ReflectionHelpers的用法示例。


在下文中一共展示了ReflectionHelpers.getField方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();

}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:27,代码来源:TestApplication.java

示例2: shouldUseCustomHandlerForContentObservers

import org.robolectric.util.ReflectionHelpers; //导入方法依赖的package包/类
@Test
public void shouldUseCustomHandlerForContentObservers() {
    ContentResolver contentResolver = mock(ContentResolver.class);
    ArgumentCaptor<ContentObserver> observerArgumentCaptor = ArgumentCaptor.forClass(ContentObserver.class);
    doNothing().when(contentResolver)
            .registerContentObserver(any(Uri.class), anyBoolean(), observerArgumentCaptor.capture());
    Handler handler = mock(Handler.class);

    StorIOContentResolver storIOContentResolver = DefaultStorIOContentResolver.builder()
            .contentResolver(contentResolver)
            .contentObserverHandler(handler)
            .defaultRxScheduler(null)
            .build();

    Disposable disposable = storIOContentResolver.observeChangesOfUri(mock(Uri.class), LATEST).subscribe();

    assertThat(observerArgumentCaptor.getAllValues()).hasSize(1);
    ContentObserver contentObserver = observerArgumentCaptor.getValue();
    Object actualHandler = ReflectionHelpers.getField(contentObserver, "mHandler");
    assertThat(actualHandler).isEqualTo(handler);

    disposable.dispose();
}
 
开发者ID:pushtorefresh,项目名称:storio,代码行数:24,代码来源:DefaultStorIOContentResolverTest.java

示例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();
}
 
开发者ID:sourceallies,项目名称:zonebeacon,代码行数:38,代码来源:ZoneBeaconRobolectricSuite.java

示例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();
}
 
开发者ID:the-blue-alliance,项目名称:the-blue-alliance-android,代码行数:42,代码来源:BaseFragmentTest.java

示例5: testClearPassword

import org.robolectric.util.ReflectionHelpers; //导入方法依赖的package包/类
@Test
public void testClearPassword() {
    LoginPageActivity activity = Robolectric.setupActivity(LoginPageActivity.class);
    TextView psdTextView = ReflectionHelpers.getField(activity, "mInputLoginPsd");
    // set fake data
    psdTextView.setText("passwordStr");
    // execute test
    activity.clearPassword();
    // verify
    assertEquals("", psdTextView.getText().toString());
}
 
开发者ID:HunkD,项目名称:Awwl,代码行数:12,代码来源:LoginPageActivityTest.java

示例6: 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");
}
 
开发者ID:seven332,项目名称:conductor-attacher,代码行数:5,代码来源:ViewUtils.java

示例7: getShadowAlertDialog

import org.robolectric.util.ReflectionHelpers; //导入方法依赖的package包/类
public static ShadowAlertDialogSupport getShadowAlertDialog(){
    ShadowDialog dialog = shadowOf(RuntimeEnvironment.application).getLatestDialog();
    AlertDialog alertDialog = getPrivateField(dialog, "realDialog", AlertDialog.class);
    AlertController alert = ReflectionHelpers.getField(alertDialog, "mAlert");
    return new ShadowAlertDialogSupport(alert);
}
 
开发者ID:openwebnet,项目名称:openwebnet-android,代码行数:7,代码来源:ShadowAlertDialogSupport.java

示例8: 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");
}
 
开发者ID:xufreshman,项目名称:RxLifeCycle,代码行数:12,代码来源:TestUtil.java


注:本文中的org.robolectric.util.ReflectionHelpers.getField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。