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


Java ReflectionHelpers类代码示例

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


ReflectionHelpers类属于org.robolectric.util包,在下文中一共展示了ReflectionHelpers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPromptOptions_IconDrawable_TintList

import org.robolectric.util.ReflectionHelpers; //导入依赖的package包/类
@Test
public void testPromptOptions_IconDrawable_TintList()
{
    final Drawable drawable = mock(Drawable.class);
    final ColorStateList colourStateList = mock(ColorStateList.class);
    final PromptOptions options = UnitTestUtils.createPromptOptions();
    assertEquals(options, options.setIconDrawable(drawable));
    assertEquals(drawable, options.getIconDrawable());
    assertEquals(options, options.setIconDrawableTintList(colourStateList));
    options.setPrimaryText("Primary Text");
    options.setTarget(mock(View.class));
    options.create();
    ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 16);
    options.create();
    assertEquals(options, options.setIconDrawableTintList(null));
}
 
开发者ID:sjwall,项目名称:MaterialTapTargetPrompt,代码行数:17,代码来源:PromptOptionsUnitTest.java

示例2: shouldNotRequireAuthenticationIfAPI21AndLockScreenDisabled

import org.robolectric.util.ReflectionHelpers; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Test
@Config(constants = com.auth0.android.auth0.BuildConfig.class, sdk = 21, manifest = Config.NONE)
public void shouldNotRequireAuthenticationIfAPI21AndLockScreenDisabled() throws Exception {
    ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 21);
    Activity activity = spy(Robolectric.buildActivity(Activity.class).create().start().resume().get());

    //Set LockScreen as Disabled
    KeyguardManager kService = mock(KeyguardManager.class);
    when(activity.getSystemService(Context.KEYGUARD_SERVICE)).thenReturn(kService);
    when(kService.isKeyguardSecure()).thenReturn(false);
    when(kService.createConfirmDeviceCredentialIntent("title", "description")).thenReturn(null);

    boolean willAskAuthentication = manager.requireAuthentication(activity, 123, "title", "description");

    assertThat(willAskAuthentication, is(false));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:18,代码来源:SecureCredentialsManagerTest.java

示例3: shouldNotRequireAuthenticationIfAPI23AndLockScreenDisabled

import org.robolectric.util.ReflectionHelpers; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.M)
@Test
@Config(constants = com.auth0.android.auth0.BuildConfig.class, sdk = 23, manifest = Config.NONE)
public void shouldNotRequireAuthenticationIfAPI23AndLockScreenDisabled() throws Exception {
    ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 23);
    Activity activity = spy(Robolectric.buildActivity(Activity.class).create().start().resume().get());

    //Set LockScreen as Disabled
    KeyguardManager kService = mock(KeyguardManager.class);
    when(activity.getSystemService(Context.KEYGUARD_SERVICE)).thenReturn(kService);
    when(kService.isDeviceSecure()).thenReturn(false);
    when(kService.createConfirmDeviceCredentialIntent("title", "description")).thenReturn(null);

    boolean willAskAuthentication = manager.requireAuthentication(activity, 123, "title", "description");

    assertThat(willAskAuthentication, is(false));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:18,代码来源:SecureCredentialsManagerTest.java

示例4: shouldRequireAuthenticationIfAPI21AndLockScreenEnabled

import org.robolectric.util.ReflectionHelpers; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Test
@Config(constants = com.auth0.android.auth0.BuildConfig.class, sdk = 21, manifest = Config.NONE)
public void shouldRequireAuthenticationIfAPI21AndLockScreenEnabled() throws Exception {
    ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 21);
    Activity activity = spy(Robolectric.buildActivity(Activity.class).create().start().resume().get());

    //Set LockScreen as Enabled
    KeyguardManager kService = mock(KeyguardManager.class);
    when(activity.getSystemService(Context.KEYGUARD_SERVICE)).thenReturn(kService);
    when(kService.isKeyguardSecure()).thenReturn(true);
    when(kService.createConfirmDeviceCredentialIntent("title", "description")).thenReturn(new Intent());

    boolean willAskAuthentication = manager.requireAuthentication(activity, 123, "title", "description");

    assertThat(willAskAuthentication, is(true));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:18,代码来源:SecureCredentialsManagerTest.java

示例5: shouldRequireAuthenticationIfAPI23AndLockScreenEnabled

import org.robolectric.util.ReflectionHelpers; //导入依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.M)
@Test
@Config(constants = com.auth0.android.auth0.BuildConfig.class, sdk = 23, manifest = Config.NONE)
public void shouldRequireAuthenticationIfAPI23AndLockScreenEnabled() throws Exception {
    ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 23);
    Activity activity = spy(Robolectric.buildActivity(Activity.class).create().start().resume().get());

    //Set LockScreen as Enabled
    KeyguardManager kService = mock(KeyguardManager.class);
    when(activity.getSystemService(Context.KEYGUARD_SERVICE)).thenReturn(kService);
    when(kService.isDeviceSecure()).thenReturn(true);
    when(kService.createConfirmDeviceCredentialIntent("title", "description")).thenReturn(new Intent());

    boolean willAskAuthentication = manager.requireAuthentication(activity, 123, "title", "description");

    assertThat(willAskAuthentication, is(true));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:18,代码来源:SecureCredentialsManagerTest.java

示例6: shouldThrowOnNoSuchProviderErrorWhenTryingToObtainRSAKeys

import org.robolectric.util.ReflectionHelpers; //导入依赖的package包/类
@Test
public void shouldThrowOnNoSuchProviderErrorWhenTryingToObtainRSAKeys() throws Exception {
    ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 19);
    exception.expect(KeyException.class);
    exception.expectMessage("An error occurred while trying to obtain the RSA KeyPair Entry from the Android KeyStore.");

    PowerMockito.when(keyStore.containsAlias(KEY_ALIAS)).thenReturn(false);
    KeyPairGeneratorSpec spec = PowerMockito.mock(KeyPairGeneratorSpec.class);
    KeyPairGeneratorSpec.Builder builder = newKeyPairGeneratorSpecBuilder(spec);
    PowerMockito.whenNew(KeyPairGeneratorSpec.Builder.class).withAnyArguments().thenReturn(builder);

    PowerMockito.mockStatic(KeyPairGenerator.class);
    PowerMockito.when(KeyPairGenerator.getInstance(ALGORITHM_RSA, ANDROID_KEY_STORE))
            .thenThrow(new NoSuchProviderException());

    cryptoUtil.getRSAKeyEntry();
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:18,代码来源:CryptoUtilTest.java

示例7: shouldThrowOnNoSuchAlgorithmErrorWhenTryingToObtainRSAKeys

import org.robolectric.util.ReflectionHelpers; //导入依赖的package包/类
@Test
public void shouldThrowOnNoSuchAlgorithmErrorWhenTryingToObtainRSAKeys() throws Exception {
    ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 19);
    exception.expect(KeyException.class);
    exception.expectMessage("An error occurred while trying to obtain the RSA KeyPair Entry from the Android KeyStore.");

    PowerMockito.when(keyStore.containsAlias(KEY_ALIAS)).thenReturn(false);
    KeyPairGeneratorSpec spec = PowerMockito.mock(KeyPairGeneratorSpec.class);
    KeyPairGeneratorSpec.Builder builder = newKeyPairGeneratorSpecBuilder(spec);
    PowerMockito.whenNew(KeyPairGeneratorSpec.Builder.class).withAnyArguments().thenReturn(builder);

    PowerMockito.mockStatic(KeyPairGenerator.class);
    PowerMockito.when(KeyPairGenerator.getInstance(ALGORITHM_RSA, ANDROID_KEY_STORE))
            .thenThrow(new NoSuchAlgorithmException());

    cryptoUtil.getRSAKeyEntry();
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:18,代码来源:CryptoUtilTest.java

示例8: 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

示例9: setup

import org.robolectric.util.ReflectionHelpers; //导入依赖的package包/类
@Before
public void setup() {
    today = Calendar.getInstance();
    now = new DayTime(60 * 60 * 10 - 1); // 1 second to 10:00
    Context context = RuntimeEnvironment.application;
    synchronized (ScheduleDatabase.class) {
        db = Room
                .inMemoryDatabaseBuilder(context, ScheduleDatabase.class)
                .allowMainThreadQueries()
                .build();
        ReflectionHelpers.setStaticField(ScheduleDatabase.class, "instance", db);
    }

    ScheduleDatabase dd = ScheduleDatabase.get(context);
    assertThat((Boolean) ReflectionHelpers.getField(dd, "mAllowMainThreadQueries")).isTrue();

    // Even app would load it, we load again here to wait for result
    ScheduleLoader.load(context, db);
}
 
开发者ID:ranmocy,项目名称:rCaltrain,代码行数:20,代码来源:ScheduleDatabaseTest.java

示例10: shouldThrowIfNoQueryOrRawQueryIsSet

import org.robolectric.util.ReflectionHelpers; //导入依赖的package包/类
@Test
public void shouldThrowIfNoQueryOrRawQueryIsSet() {
    try {
        final GetCursorStub getStub = GetCursorStub.newInstance();

        final PreparedGetCursor operation = getStub.storIOSQLite
                .get()
                .cursor()
                .withQuery(getStub.query) // will be removed
                .withGetResolver(getStub.getResolverForCursor)
                .prepare();

        ReflectionHelpers.setField(operation, "query", null);
        ReflectionHelpers.setField(operation, "rawQuery", null);
        operation.getData();

        failBecauseExceptionWasNotThrown(IllegalStateException.class);
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("Either rawQuery or query should be set!");
    }
}
 
开发者ID:pushtorefresh,项目名称:storio,代码行数:22,代码来源:PreparedGetCursorTest.java

示例11: 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

示例12: startActivityTestForPriorJellyBean

import org.robolectric.util.ReflectionHelpers; //导入依赖的package包/类
@Test
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
public void startActivityTestForPriorJellyBean() {
    ReflectionHelpers.setStaticField(Build.VERSION.class, SDK_INT, Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1);

    VersionUtilities.startActivity(activityMock, intentMock, optionsMock);

    verify(activityMock, times(1)).startActivity(intentMock);
    verifyNoMoreInteractions(activityMock);
}
 
开发者ID:ParaskP7,项目名称:sample-code-posts,代码行数:11,代码来源:VersionUtilitiesTest.java

示例13: setBackgroundTestForPriorJellyBean

import org.robolectric.util.ReflectionHelpers; //导入依赖的package包/类
@Test
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
@Ignore("android.content.res.Resources$NotFoundException: Unable to find resource ID #0x0 in packages")
public void setBackgroundTestForPriorJellyBean() {
    ReflectionHelpers.setStaticField(Build.VERSION.class, SDK_INT, Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1);

    DeprecationUtilities.setBackground(viewMock, R.drawable.snackbar__design_snackbar_background);

    verify(viewMock, times(1)).setBackgroundDrawable(any(Drawable.class));
    verifyNoMoreInteractions(connectivityManagerMock);
}
 
开发者ID:ParaskP7,项目名称:sample-code-posts,代码行数:12,代码来源:DeprecationUtilitiesTest.java

示例14: beforeTest

import org.robolectric.util.ReflectionHelpers; //导入依赖的package包/类
protected void beforeTest(Sandbox sandbox, Spec spec) throws Throwable {
    SdkEnvironment sdkEnvironment = (SdkEnvironment) sandbox;
    RoboSpec roboSpec = (RoboSpec) spec;

    roboSpec.parallelUniverseInterface = getHooksInterface(sdkEnvironment);
    Class<TestLifecycle> cl = sdkEnvironment.bootstrappedClass(getTestLifecycleClass());
    roboSpec.testLifecycle = ReflectionHelpers.newInstance(cl);

    final Config config = roboSpec.config;
    final AndroidManifest appManifest = roboSpec.getAppManifest();

    roboSpec.parallelUniverseInterface.setSdkConfig((sdkEnvironment).getSdkConfig());
    roboSpec.parallelUniverseInterface.resetStaticState(config);

    SdkConfig sdkConfig = roboSpec.sdkConfig;
    Class<?> androidBuildVersionClass = (sdkEnvironment).bootstrappedClass(Build.VERSION.class);
    ReflectionHelpers.setStaticField(androidBuildVersionClass, "SDK_INT", sdkConfig.getApiLevel());
    ReflectionHelpers.setStaticField(androidBuildVersionClass, "RELEASE", sdkConfig.getAndroidVersion());
    ReflectionHelpers.setStaticField(androidBuildVersionClass, "CODENAME", sdkConfig.getAndroidCodeName());

    PackageResourceTable systemResourceTable = sdkEnvironment.getSystemResourceTable(getJarResolver());
    PackageResourceTable appResourceTable = getAppResourceTable(appManifest);

    // This will always be non empty since every class has basic methods like toString.
    Method randomMethod = getTestClass().getJavaClass().getMethods()[0];
    roboSpec.parallelUniverseInterface.setUpApplicationState(
            randomMethod,
            roboSpec.testLifecycle,
            appManifest,
            config,
            new RoutingResourceTable(getCompiletimeSdkResourceTable(), appResourceTable),
            new RoutingResourceTable(systemResourceTable, appResourceTable),
            new RoutingResourceTable(systemResourceTable));
    roboSpec.testLifecycle.beforeTest(null);
}
 
开发者ID:bangarharshit,项目名称:Oleaster,代码行数:36,代码来源:OleasterRobolectricRunner.java

示例15: 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);
}
 
开发者ID:braintree,项目名称:popup-bridge-android,代码行数:11,代码来源:PopupBridgeTest.java


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