final Crouton crouton = Crouton.makeText(new Activity(), "foo", Style.ALERT) .setConfiguration(new Configuration.Builder().setDuration(Configuration.DURATION_INFINITE).build()); crouton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Crouton.hide(crouton); } }); crouton.show();
@Test public void shouldCallFinishOnFinish() { Activity activity = new Activity(); activity.finish(); assertTrue(activity.isFinishing()); }
@Before public void setUp() throws Exception { mActivity = new Activity(); // Make and set view with some prelim values to test mView = new TestImageView(mActivity); mView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); mView.measure(View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(250, View.MeasureSpec.EXACTLY)); mImageAware = new ImageViewAware(mView); }
@Test @Config(minSdk = JELLY_BEAN) public void shouldCallFinishOnFinishAffinity() { Activity activity = new Activity(); activity.finishAffinity(); assertTrue(activity.isFinishing()); }
@Test @Config(minSdk = LOLLIPOP) public void shouldCallFinishOnFinishAndRemoveTask() { Activity activity = new Activity(); activity.finishAndRemoveTask(); assertTrue(activity.isFinishing()); }
@Test public void getErrorDialog() { assertNotNull(GooglePlayServicesUtil.getErrorDialog( ConnectionResult.SERVICE_MISSING, new Activity(), 0)); assertNull(GooglePlayServicesUtil.getErrorDialog( ConnectionResult.SUCCESS, new Activity(), 0)); assertNotNull(GooglePlayServicesUtil.getErrorDialog( ConnectionResult.SERVICE_MISSING, new Activity(), 0, null)); assertNull(GooglePlayServicesUtil.getErrorDialog( ConnectionResult.SUCCESS, new Activity(), 0, null)); }
@Test public void shouldCallFinishInOnBackPressed() { Activity activity = new Activity(); activity.onBackPressed(); assertTrue(activity.isFinishing()); }
@Test public void testCreateInstance() { assertThat(CookieSyncManager.createInstance(new Activity())).isNotNull(); }
@Test public void extractor() throws Exception { Activity activity = new Activity(); assertThat((ShadowActivity) Shadow.extract(activity)).isSameAs(shadowOf(activity)); }
@Test public void otherDeprecated_extractor() throws Exception { Activity activity = new Activity(); assertThat(Shadow.<Object>extract(activity)).isSameAs(shadowOf(activity)); } }
@Test public void testGetInstance() { CookieSyncManager.createInstance(new Activity()); assertThat(CookieSyncManager.getInstance()).isNotNull(); } }
@Before public void setUp() throws Exception { am = AccountManager.get(ApplicationProvider.getApplicationContext()); scheduler = Robolectric.getForegroundThreadScheduler(); activity = new Activity(); }
@Test public void getAndSetRequestedOrientation_shouldRemember() throws Exception { Activity activity = new Activity(); activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); assertEquals(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, activity.getRequestedOrientation()); }
@Test public void getCurrentActivity_shouldReturnTheProvidedCurrentActivity() throws Exception { ActivityGroup activityGroup = new ActivityGroup(); Activity activity = new Activity(); shadowOf(activityGroup).setCurrentActivity(activity); assertThat(activityGroup.getCurrentActivity()).isSameAs(activity); } }
@Test public void getAndSetRequestedOrientation_shouldDelegateToParentIfPresent() throws Exception { Activity parentActivity = new Activity(); Activity activity = new Activity(); shadowOf(activity).setParent(parentActivity); parentActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); assertEquals(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, activity.getRequestedOrientation()); activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); assertEquals(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE, parentActivity.getRequestedOrientation()); }
@Test public void setDefaultKeyMode_shouldSetKeyMode() { int[] modes = { Activity.DEFAULT_KEYS_DISABLE, Activity.DEFAULT_KEYS_SHORTCUT, Activity.DEFAULT_KEYS_DIALER, Activity.DEFAULT_KEYS_SEARCH_LOCAL, Activity.DEFAULT_KEYS_SEARCH_GLOBAL }; Activity activity = new Activity(); ShadowActivity shadow = shadowOf(activity); for (int mode : modes) { activity.setDefaultKeyMode(mode); assertThat(shadow.getDefaultKeymode()).named("Unexpected key mode").isEqualTo(mode); } }
@Before public void setUp() throws Exception { if (!initCompleted) { r = new Random(); credentialsProvider = new CognitoCachingCredentialsProvider(new Activity(), IDENTITY_POOL_ID, Regions.US_EAST_1); iotClient = new AWSIotClient(credentialsProvider); DescribeEndpointRequest request = new DescribeEndpointRequest(); DescribeEndpointResult result = iotClient.describeEndpoint(request); endpointPrefix = result.getEndpointAddress().split("\\.")[0]; initCompleted = true; } }