Search in sources :

Example 36 with Config

use of org.robolectric.annotation.Config in project robolectric by robolectric.

the class DefaultPackageManagerTest method getServiceInfo_shouldReturnServiceInfoWithoutMetaDataWhenFlagsNotSet.

@Test
@Config(manifest = "src/test/resources/TestPackageManagerGetServiceInfo.xml")
public void getServiceInfo_shouldReturnServiceInfoWithoutMetaDataWhenFlagsNotSet() throws Exception {
    ServiceInfo serviceInfo = rpm.getServiceInfo(new ComponentName("org.robolectric", "com.foo.Service"), PackageManager.GET_SERVICES);
    assertNull(serviceInfo.metaData);
}
Also used : ComponentName(android.content.ComponentName) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 37 with Config

use of org.robolectric.annotation.Config in project robolectric by robolectric.

the class DefaultPackageManagerTest method getActivityMetaData_configChanges.

@Test
@Config(manifest = "src/test/resources/TestAndroidManifest.xml")
public void getActivityMetaData_configChanges() throws Exception {
    Activity activity = setupActivity(ActivityWithConfigChanges.class);
    ActivityInfo activityInfo = activity.getPackageManager().getActivityInfo(activity.getComponentName(), 0);
    int configChanges = activityInfo.configChanges;
    assertThat(configChanges & ActivityInfo.CONFIG_MCC).isEqualTo(ActivityInfo.CONFIG_MCC);
    assertThat(configChanges & ActivityInfo.CONFIG_SCREEN_LAYOUT).isEqualTo(ActivityInfo.CONFIG_SCREEN_LAYOUT);
    assertThat(configChanges & ActivityInfo.CONFIG_ORIENTATION).isEqualTo(ActivityInfo.CONFIG_ORIENTATION);
    // Spot check a few other possible values that shouldn't be in the flags.
    assertThat(configChanges & ActivityInfo.CONFIG_MNC).isZero();
    assertThat(configChanges & ActivityInfo.CONFIG_FONT_SCALE).isZero();
    assertThat(configChanges & ActivityInfo.CONFIG_SCREEN_SIZE).isZero();
}
Also used : Robolectric.setupActivity(org.robolectric.Robolectric.setupActivity) Activity(android.app.Activity) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 38 with Config

use of org.robolectric.annotation.Config in project robolectric by robolectric.

the class DefaultPackageManagerTest method queryIntentActivities_MatchWithImplicitIntents.

@Test
@Config(manifest = "src/test/resources/TestAndroidManifestForActivitiesWithIntentFilterWithData.xml")
public void queryIntentActivities_MatchWithImplicitIntents() throws Exception {
    Uri uri = Uri.parse("content://testhost1.com:1/testPath/test.jpeg");
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.addCategory(Intent.CATEGORY_DEFAULT);
    i.setDataAndType(uri, "image/jpeg");
    rpm.setQueryIntentImplicitly(true);
    List<ResolveInfo> activities = rpm.queryIntentActivities(i, 0);
    assertThat(activities).isNotNull();
    assertThat(activities).hasSize(1);
    assertThat(activities.get(0).resolvePackageName.toString()).isEqualTo("org.robolectric");
    assertThat(activities.get(0).activityInfo.targetActivity.toString()).isEqualTo("org.robolectric.shadows.TestActivity");
}
Also used : Intent(android.content.Intent) Uri(android.net.Uri) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 39 with Config

use of org.robolectric.annotation.Config in project robolectric by robolectric.

the class AndroidTranslatorClassInstrumentedTest method testNativeMethodsAreDelegated.

@Test
@Config(shadows = ShadowPaintForTests.class)
public void testNativeMethodsAreDelegated() throws Exception {
    Paint paint = new Paint();
    paint.setColor(1234);
    assertThat(paint.getColor()).isEqualTo(1234);
}
Also used : Paint(android.graphics.Paint) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 40 with Config

use of org.robolectric.annotation.Config in project robolectric by robolectric.

the class DefaultPackageManagerTest method getProviderInfo_shouldPopulatePermissionsInProviderInfos.

@Test
@Config(manifest = "src/test/resources/TestAndroidManifestWithContentProviders.xml")
public void getProviderInfo_shouldPopulatePermissionsInProviderInfos() throws Exception {
    ProviderInfo providerInfo = packageManager.getProviderInfo(new ComponentName(RuntimeEnvironment.application, "org.robolectric.android.controller.ContentProviderControllerTest$MyContentProvider"), 0);
    assertThat(providerInfo.authority).isEqualTo("org.robolectric.authority2");
    assertThat(providerInfo.readPermission).isEqualTo("READ_PERMISSION");
    assertThat(providerInfo.writePermission).isEqualTo("WRITE_PERMISSION");
    assertThat(providerInfo.pathPermissions).hasSize(1);
    assertThat(providerInfo.pathPermissions[0].getPath()).isEqualTo("/path/*");
    assertThat(providerInfo.pathPermissions[0].getType()).isEqualTo(PathPermission.PATTERN_SIMPLE_GLOB);
    assertThat(providerInfo.pathPermissions[0].getReadPermission()).isEqualTo("PATH_READ_PERMISSION");
    assertThat(providerInfo.pathPermissions[0].getWritePermission()).isEqualTo("PATH_WRITE_PERMISSION");
}
Also used : ComponentName(android.content.ComponentName) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

Config (org.robolectric.annotation.Config)158 Test (org.junit.Test)153 Intent (android.content.Intent)21 ComponentName (android.content.ComponentName)16 Bundle (android.os.Bundle)10 Activity (android.app.Activity)7 Bitmap (android.graphics.Bitmap)7 Notification (android.app.Notification)6 Button (android.widget.Button)6 TextView (android.widget.TextView)6 BuildConfig (com.firebase.ui.auth.BuildConfig)6 BuildConfig (com.onesignal.BuildConfig)6 ShadowRecyclerView (io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView)6 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)6 Properties (java.util.Properties)6 Account (android.accounts.Account)5 Network (android.net.Network)5 NetworkInfo (android.net.NetworkInfo)5 RecyclerView (android.support.v7.widget.RecyclerView)5 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4