本文整理汇总了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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
示例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!");
}
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}