@Test public void startActivity_whenActivityCheckingEnabled_checksPackageManagerResolveInfo() throws Exception { Application application = new DefaultTestLifecycle().createApplication(null, newConfigWith("com.wacka.wa", "")); shadowOf(application).checkActivities(true); String action = "com.does.not.exist.android.app.v2.mobile"; try { application.startActivity(new Intent(action)); fail("Expected startActivity to throw ActivityNotFoundException!"); } catch (ActivityNotFoundException e) { assertThat(e.getMessage()).contains(action); assertThat(shadowOf(application).getNextStartedActivity()).isNull(); } }
@Test public void shouldBeAbleToResetResources() throws Exception { Application application = new DefaultTestLifecycle().createApplication(null, newConfigWith("com.wacka.wa", "")); Resources res = application.getResources(); shadowOf(application).resetResources(); assertFalse(res == application.getResources()); }
@Test public void checkPermission_shouldTrackGrantedAndDeniedPermissions() throws Exception { Application application = new DefaultTestLifecycle().createApplication(null, newConfigWith("com.wacka.wa", "")); shadowOf(application).grantPermissions("foo", "bar"); shadowOf(application).denyPermissions("foo", "qux"); assertThat(application.checkPermission("foo", -1, -1)).isEqualTo(PERMISSION_DENIED); assertThat(application.checkPermission("bar", -1, -1)).isEqualTo(PERMISSION_GRANTED); assertThat(application.checkPermission("baz", -1, -1)).isEqualTo(PERMISSION_DENIED); assertThat(application.checkPermission("qux", -1, -1)).isEqualTo(PERMISSION_DENIED); }
@Test public void shouldRetrievePackageNameFromTheManifest() throws Exception { AndroidManifest appManifest = newConfigWith("com.wacka.wa", ""); Robolectric.application = new DefaultTestLifecycle().createApplication(null, appManifest); shadowOf(application).bind(appManifest, null); assertThat("com.wacka.wa").isEqualTo(new Activity().getPackageName()); }
@Test public void shouldRememberResourcesAfterLazilyLoading() throws Exception { Application application = new DefaultTestLifecycle().createApplication(null, newConfigWith("com.wacka.wa", "")); assertSame(application.getResources(), application.getResources()); }
@Test public void getProvider_shouldNotReturnAnyProviderWhenManifestIsNull() { Robolectric.application = new DefaultTestLifecycle().createApplication(null, null); assertThat(ShadowContentResolver.getProvider(Uri.parse("content://"))).isNull(); }
/** * An instance of the returned class will be created for each test invocation. * * Custom TestRunner subclasses may wish to override this method to provide alternate configuration. * * @return a class which implements {@link TestLifecycle}. This implementation returns a {@link DefaultTestLifecycle}. */ protected Class<? extends TestLifecycle> getTestLifecycleClass() { return DefaultTestLifecycle.class; }