Search in sources :

Example 31 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.

the class ShadowContentResolverTest method getProvider_shouldCreateProviderFromManifest.

@Test
public void getProvider_shouldCreateProviderFromManifest() {
    AndroidManifest manifest = ShadowApplication.getInstance().getAppManifest();
    ContentProviderData testProviderData = new ContentProviderData("org.robolectric.shadows.ShadowContentResolverTest$TestContentProvider", null, AUTHORITY, null, null, null);
    try {
        manifest.getContentProviders().add(testProviderData);
        assertThat(ShadowContentResolver.getProvider(Uri.parse("content://" + AUTHORITY + "/shadows"))).isNotNull();
    } finally {
        manifest.getContentProviders().remove(testProviderData);
    }
}
Also used : ContentProviderData(org.robolectric.manifest.ContentProviderData) AndroidManifest(org.robolectric.manifest.AndroidManifest) Test(org.junit.Test)

Example 32 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.

the class RobolectricTestRunner method beforeTest.

@Override
protected void beforeTest(Sandbox sandbox, FrameworkMethod method, Method bootstrappedMethod) throws Throwable {
    SdkEnvironment sdkEnvironment = (SdkEnvironment) sandbox;
    RobolectricFrameworkMethod roboMethod = (RobolectricFrameworkMethod) method;
    roboMethod.parallelUniverseInterface = getHooksInterface(sdkEnvironment);
    Class<TestLifecycle> cl = sdkEnvironment.bootstrappedClass(getTestLifecycleClass());
    roboMethod.testLifecycle = ReflectionHelpers.newInstance(cl);
    final Config config = roboMethod.config;
    final AndroidManifest appManifest = roboMethod.getAppManifest();
    roboMethod.parallelUniverseInterface.setSdkConfig((sdkEnvironment).getSdkConfig());
    roboMethod.parallelUniverseInterface.resetStaticState(config);
    SdkConfig sdkConfig = roboMethod.sdkConfig;
    Class<?> androidBuildVersionClass = (sdkEnvironment).bootstrappedClass(Build.VERSION.class);
    ReflectionHelpers.setStaticField(androidBuildVersionClass, "SDK_INT", sdkConfig.getApiLevel());
    ReflectionHelpers.setStaticField(androidBuildVersionClass, "RELEASE", sdkConfig.getAndroidVersion());
    PackageResourceTable systemResourceTable = sdkEnvironment.getSystemResourceTable(getJarResolver());
    PackageResourceTable appResourceTable = getAppResourceTable(appManifest);
    roboMethod.parallelUniverseInterface.setUpApplicationState(bootstrappedMethod, roboMethod.testLifecycle, appManifest, config, new RoutingResourceTable(getCompiletimeSdkResourceTable(), appResourceTable), new RoutingResourceTable(systemResourceTable, appResourceTable), new RoutingResourceTable(systemResourceTable));
    roboMethod.testLifecycle.beforeTest(bootstrappedMethod);
}
Also used : PackageResourceTable(org.robolectric.res.PackageResourceTable) Config(org.robolectric.annotation.Config) Build(android.os.Build) RoutingResourceTable(org.robolectric.res.RoutingResourceTable) AndroidManifest(org.robolectric.manifest.AndroidManifest)

Example 33 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.

the class ResourceMergerTest method libraryConfigShouldOverrideProjectProperties.

@Test
@Config(manifest = "src/test/resources/TestAndroidManifest.xml", libraries = "lib1")
public void libraryConfigShouldOverrideProjectProperties() throws Exception {
    AndroidManifest manifest = Shadows.shadowOf(RuntimeEnvironment.application).getAppManifest();
    List<AndroidManifest> libraryManifests = manifest.getLibraryManifests();
    assertEquals(1, libraryManifests.size());
    assertEquals("org.robolectric.lib1", libraryManifests.get(0).getPackageName());
}
Also used : AndroidManifest(org.robolectric.manifest.AndroidManifest) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 34 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.

the class DefaultPackageManager method getProviderInfo.

@Override
public ProviderInfo getProviderInfo(ComponentName className, int flags) throws NameNotFoundException {
    String packageName = className.getPackageName();
    AndroidManifest androidManifest = androidManifests.get(packageName);
    String classString = resolvePackageName(packageName, className);
    for (ContentProviderData contentProviderData : androidManifest.getContentProviders()) {
        if (contentProviderData.getClassName().equals(classString)) {
            ProviderInfo providerInfo = new ProviderInfo();
            providerInfo.packageName = packageName;
            providerInfo.name = contentProviderData.getClassName();
            // todo: support multiple authorities
            providerInfo.authority = contentProviderData.getAuthorities();
            providerInfo.readPermission = contentProviderData.getReadPermission();
            providerInfo.writePermission = contentProviderData.getWritePermission();
            providerInfo.pathPermissions = createPathPermissions(contentProviderData.getPathPermissionDatas());
            if ((flags & GET_META_DATA) != 0) {
                providerInfo.metaData = metaDataToBundle(contentProviderData.getMetaData().getValueMap());
            }
            return providerInfo;
        }
    }
    return null;
}
Also used : ContentProviderData(org.robolectric.manifest.ContentProviderData) ProviderInfo(android.content.pm.ProviderInfo) AndroidManifest(org.robolectric.manifest.AndroidManifest)

Example 35 with AndroidManifest

use of org.robolectric.manifest.AndroidManifest in project robolectric by robolectric.

the class DefaultPackageManager method getServiceInfo.

@Override
public ServiceInfo getServiceInfo(ComponentName className, int flags) throws NameNotFoundException {
    String packageName = className.getPackageName();
    AndroidManifest androidManifest = androidManifests.get(packageName);
    String serviceName = className.getClassName();
    ServiceData serviceData = androidManifest.getServiceData(serviceName);
    if (serviceData == null) {
        throw new NameNotFoundException(serviceName);
    }
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.packageName = packageName;
    serviceInfo.name = serviceName;
    serviceInfo.applicationInfo = getApplicationInfo(packageName, flags);
    serviceInfo.permission = serviceData.getPermission();
    if ((flags & GET_META_DATA) != 0) {
        serviceInfo.metaData = metaDataToBundle(serviceData.getMetaData().getValueMap());
    }
    return serviceInfo;
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) AndroidManifest(org.robolectric.manifest.AndroidManifest) ServiceData(org.robolectric.manifest.ServiceData)

Aggregations

AndroidManifest (org.robolectric.manifest.AndroidManifest)40 Test (org.junit.Test)21 Config (org.robolectric.annotation.Config)6 BuildConfig (org.robolectric.gradleapp.BuildConfig)6 FsFile (org.robolectric.res.FsFile)5 FileFsFile (org.robolectric.res.FileFsFile)4 ActivityInfo (android.content.pm.ActivityInfo)3 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 DefaultManifestFactory (org.robolectric.internal.DefaultManifestFactory)3 ManifestFactory (org.robolectric.internal.ManifestFactory)3 ContentProviderData (org.robolectric.manifest.ContentProviderData)3 File (java.io.File)2 ActivityData (org.robolectric.manifest.ActivityData)2 ResourcePath (org.robolectric.res.ResourcePath)2 Application (android.app.Application)1 ContentProvider (android.content.ContentProvider)1 ProviderInfo (android.content.pm.ProviderInfo)1 ResolveInfo (android.content.pm.ResolveInfo)1 ServiceInfo (android.content.pm.ServiceInfo)1