Java 类org.robolectric.manifest.AndroidManifest 实例源码

项目:JobSchedulerCompat    文件:JobGcReceiverTest.java   
@Test
public void testBootReceiverRegistered() {
    Intent intent = new Intent(Intent.ACTION_BOOT_COMPLETED);
    AndroidManifest manifest = ShadowApplication.getInstance().getAppManifest();
    List<BroadcastReceiver> receivers = ShadowApplication.getInstance().getReceiversForIntent(intent);
    assertThat(receivers, hasItem(isA(JobGcReceiver.class)));
}
项目:lex    文件:LexTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
    String appRoot = "src/main/";
    String manifestPath = appRoot + "AndroidManifest.xml";
    String resDir = appRoot + "res";
    String assetsDir = appRoot + "assets";

    //return new AndroidManifest(Fs.fileFromPath("src/main/AndroidManifest.xml"), Fs.fileFromPath(resDir), Fs.fileFromPath(assetsDir)) {
    return new AndroidManifest(Fs.fileFromPath(manifestPath), Fs.fileFromPath(resDir), Fs.fileFromPath(assetsDir)) {

        @Override
        public List<ResourcePath> getIncludedResourcePaths() {
            List<ResourcePath> paths = super.getIncludedResourcePaths();
            paths.add(new ResourcePath(getRClass(), Fs.fileFromPath("src/main/res"), getAssetsDirectory()));
            paths.add(new ResourcePath(getRClass(), Fs.fileFromPath("src/test/res"), getAssetsDirectory()));
            return paths;
        }
    };
}
项目:Oleaster    文件:RoboOleaster.java   
public RoboOleaster(Class testClass) throws InitializationError {
    super(testClass);
    Config config = getConfig(testClass);
    AndroidManifest androidManifest = getAppManifest(config);
    interceptors = new Interceptors(findInterceptors());
    SdkEnvironment sdkEnvironment = getSandbox(config, androidManifest);

    // Configure shadows *BEFORE* setting the ClassLoader. This is necessary because
    // creating the ShadowMap loads all ShadowProviders via ServiceLoader and this is
    // not available once we install the Robolectric class loader.
    configureShadows(sdkEnvironment);

    Class bootstrappedTestClass = sdkEnvironment.bootstrappedClass(testClass);
    try {

        this.oleasterRobolectricRunner = sdkEnvironment
                .bootstrappedClass(OleasterRobolectricRunner.class)
                .getConstructor(Class.class, SdkEnvironment.class, Config.class, AndroidManifest.class)
                .newInstance(bootstrappedTestClass, sdkEnvironment, config, androidManifest);

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:RxAndroidOrm    文件:CustomRobolectricTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
    String path = PATH_MANIFEST;

    // android studio has a different execution root for tests than pure gradle
    // so we avoid here manual effort to get them running inside android studio
    if (!new File(path).exists()) {
        path = PATH_PREFIX + path;
    }

    config = overwriteConfig(config, CONFIG_MANIFEST, path);
    config = overwriteConfig(config, CONFIG_ASSET_DIR, PATH_ASSET);
    config = overwriteConfig(config, CONFIG_RESOURCE_DIR, PATH_RESOURCE);
    config = overwriteConfig(config, CONFIG_PACKAGE_NAME, PACKAGE_NAME);

    return super.getAppManifest(config);
}
项目:schulcloud-mobile-android    文件:ApplicationRobolectricTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {

    final String manifestPath = PathResolver.resolveAndroidManifestPath();
    final String resourcesPath = PathResolver.resolveResPath();
    final String assetsPath = PathResolver.resolveAssetsPath();

    AndroidManifest manifest = new AndroidManifest(
            Fs.fileFromPath(manifestPath),
            Fs.fileFromPath(resourcesPath),
            Fs.fileFromPath(assetsPath)) {
        @Override
        public int getTargetSdkVersion() {
            return TARGET_SDK_VERSION;
        }

        @Override
        public int getMinSdkVersion() {
            return MIN_SDK_VERSION;
        }
    };

    return manifest;
}
项目:MVP-Boilerplate    文件:PermissionsTest.java   
@Test
public void shouldMatchPermissions() {
    // Initialize: configure test for current app configuration
    FsFile mergedManifestFile;
    Object[] expectedPermissions;
    if (BuildConfig.DEBUG) {
        mergedManifestFile = Fs.fileFromPath(MERGED_DEBUG_MANIFEST_FILE);
        expectedPermissions = EXPECTED_DEBUG_PERMISSIONS;
    } else {
        mergedManifestFile = Fs.fileFromPath(MERGED_RELEASE_MANIFEST_FILE);
        expectedPermissions = EXPECTED_RELEASE_PERMISSIONS;
    }

    // Run: Creates a Robolectric configuration using specified manifest file
    AndroidManifest manifest = new AndroidManifest(mergedManifestFile, null, null);

    // Check: manifest file should contain only expected permissions
    assertThat(manifest.getUsedPermissions())
            .containsExactly(expectedPermissions);
}
项目:AndroidUnitTest    文件:AndroidUnitTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
    String path = getPathManifest();

    // android studio has a different execution root for tests than pure gradle
    // so we avoid here manual effort to get them running inside android studio
    if (!new File(path).exists()) {
        path = PATH_PREFIX + path;
    }

    config = overwriteConfig(config, CONFIG_MANIFEST, path);
    config = overwriteConfig(config, CONFIG_ASSET_DIR, getPathAssets());
    config = overwriteConfig(config, CONFIG_RESOURCE_DIR, getPathResources());
    if (packageName != null) {
        config = overwriteConfig(config, CONFIG_PACKAGE_NAME, packageName);
    }
    if (applicationClass != null) {
        config = overwriteConfig(config, CONFIG_APPLICATION, applicationClass.getCanonicalName());
    }
    return super.getAppManifest(config);
}
项目:Freezer    文件:CustomRobolectricTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
    String path = PATH_MANIFEST;

    // android studio has a different execution root for tests than pure gradle
    // so we avoid here manual effort to get them running inside android studio
    if (!new File(path).exists()) {
        path = PATH_PREFIX + path;
    }

    config = overwriteConfig(config, CONFIG_MANIFEST, path);
    config = overwriteConfig(config, CONFIG_ASSET_DIR, PATH_ASSET);
    config = overwriteConfig(config, CONFIG_RESOURCE_DIR, PATH_RESOURCE);
    config = overwriteConfig(config, CONFIG_PACKAGE_NAME, PACKAGE_NAME);

    return super.getAppManifest(config);
}
项目:Zen    文件:RobolectricLauncherGradleTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
    String manifestProperty = System.getProperty("android.manifest");
    if (config.manifest().equals(Config.DEFAULT) && manifestProperty != null) {
        String resProperty = System.getProperty("android.resources");
        String assetsProperty = System.getProperty("android.assets");
        AndroidManifest androidManifest = new AndroidManifest(
                Fs.fileFromPath(manifestProperty),
                Fs.fileFromPath(resProperty),
                Fs.fileFromPath(assetsProperty)) {
            @Override
            public int getTargetSdkVersion() {
                return MAX_SDK_SUPPORTED_BY_ROBOLECTRIC;
            }
        };
        androidManifest.setPackageName("zenproject.meditation.android");
        return androidManifest;
    }
    return super.getAppManifest(config);
}
项目:stack-overflow-android    文件:MyRobolectricTestRunner.java   
@Override
protected AndroidManifest createAppManifest(FsFile manifestFile, FsFile resDir, FsFile assetsDir) {
    return new AndroidManifest(
            Fs.fileFromPath("src/main/AndroidManifest.xml"),
            Fs.fileFromPath("src/main/res"),
            Fs.fileFromPath("src/main/assets")) {

        @Override
        public int getTargetSdkVersion() {
            return 18;
        }

        @Override
        public String getThemeRef(Class<? extends Activity> activityClass) {
            return "@android:style/Theme.Holo.Light.NoActionBar";
        }
    };
}
项目:Bakery    文件:AppRobolectricTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {

    final String manifestPath = PathResolver.resolveAndroidManifestPath();
    final String resourcesPath = PathResolver.resolveResPath();
    final String assetsPath = PathResolver.resolveAssetsPath();

    AndroidManifest manifest = new AndroidManifest(
            Fs.fileFromPath(manifestPath),
            Fs.fileFromPath(resourcesPath),
            Fs.fileFromPath(assetsPath)) {
        @Override
        public int getTargetSdkVersion() {
            return TARGET_SDK_VERSION;
        }

        @Override
        public int getMinSdkVersion() {
            return MIN_SDK_VERSION;
        }
    };

    manifest.setPackageName("pl.dawidgdanski.bakery");

    return manifest;
}
项目:unitTestingWithAndroidStudio    文件:RobolectricGradleTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {

    String manifestPath = APP_ROOT_DIRECTORY + ANDROID_MANIFEST_FILE_NAME;
    String resDir = APP_ROOT_DIRECTORY + RES_DIR;
    String assetsDir = APP_ROOT_DIRECTORY + ASSETS_DIR;
    AndroidManifest manifest = new AndroidManifest(Fs.fileFromPath(manifestPath),
            Fs.fileFromPath(resDir),
            Fs.fileFromPath(assetsDir)) {
        @Override
        public int getTargetSdkVersion() {
            return MAX_SDK_SUPPORTED_BY_ROBOLECTRIC;
        }
    };

    return manifest;
}
项目:Oleaster    文件:RoboOleaster.java   
private AndroidManifest getAppManifest(Config config) {
    ManifestFactory manifestFactory = getManifestFactory(config);
    ManifestIdentifier identifier = manifestFactory.identify(config);

    synchronized (appManifestsCache) {
        AndroidManifest appManifest;
        appManifest = appManifestsCache.get(identifier);
        if (appManifest == null) {
            appManifest = manifestFactory.create(identifier);
            appManifestsCache.put(identifier, appManifest);
        }

        return appManifest;
    }
}
项目:Oleaster    文件:RoboOleaster.java   
private int pickSdkVersion(Config config, AndroidManifest manifest) {
    if (config != null && config.sdk().length > 1) {
        throw new IllegalArgumentException("Robospock does not support multiple values for @Config.sdk");
    } else if (config != null && config.sdk().length == 1) {
        return config.sdk()[0];
    } else if (manifest != null) {
        return manifest.getTargetSdkVersion();
    } else {
        return SdkConfig.FALLBACK_SDK_VERSION;
    }
}
项目:Oleaster    文件:OleasterRobolectricRunner.java   
public OleasterRobolectricRunner(
        Class<?> testClass,
        SdkEnvironment sandbox,
        Config config,
        AndroidManifest androidManifest)
        throws
        InitializationError {
    super(testClass);
    this.sandbox = sandbox;

    this.config = config;
    this.androidManifest = androidManifest;
}
项目:Oleaster    文件:OleasterRobolectricRunner.java   
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);
}
项目:Oleaster    文件:OleasterRobolectricRunner.java   
private PackageResourceTable getAppResourceTable(final AndroidManifest appManifest) {
    PackageResourceTable resourceTable = appResourceTableCache.get(appManifest);
    if (resourceTable == null) {
        resourceTable = new ResourceMerger().buildResourceTable(appManifest);

        appResourceTableCache.put(appManifest, resourceTable);
    }
    return resourceTable;
}
项目:Oleaster    文件:OleasterRobolectricRunner.java   
RoboSpec(
        Spec spec,
        AndroidManifest appManifest,
        SdkConfig sdkConfig,
        Config config) {
    super(spec);
    this.appManifest = appManifest;
    this.sdkConfig = sdkConfig;
    this.config = config;
}
项目:mobsoft-lab    文件:RobolectricDaggerTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
    if (config.constants() == Void.class) {
        Logger.error("Field 'constants' not specified in @Config annotation");
        Logger.error("This is required when using RobolectricGradleTestRunner!");
        throw new RuntimeException("No 'constants' field in @Config annotation!");
    }

    final String type = getType(config);
    final String flavor = getFlavor(config);
    final String applicationId = getApplicationId(config);

    final FileFsFile res;
    if (FileFsFile.from(BUILD_OUTPUT, "res", flavor, type).exists()) {
        res = FileFsFile.from(BUILD_OUTPUT, "res", flavor, type);
    } else {
        // Use res/merged if the output directory doesn't exist for Data Binding compatibility
        res = FileFsFile.from(BUILD_OUTPUT, "res/merged", flavor, type);
    }
    final FileFsFile assets = FileFsFile.from(BUILD_OUTPUT, "assets", flavor, type);

    final FileFsFile manifest;
    if (FileFsFile.from(BUILD_OUTPUT, "manifests").exists()) {
        manifest = FileFsFile.from(BUILD_OUTPUT, "manifests", "full", flavor, type, "AndroidManifest.xml");
    } else {
        // Fallback to the location for library manifests
        manifest = FileFsFile.from(BUILD_OUTPUT, "bundles", flavor, type, "AndroidManifest.xml");
    }

    Logger.debug("Robolectric assets directory: " + assets.getPath());
    Logger.debug("   Robolectric res directory: " + res.getPath());
    Logger.debug("   Robolectric manifest path: " + manifest.getPath());
    Logger.debug("    Robolectric package name: " + applicationId);
    return new AndroidManifest(manifest, res, assets, applicationId);
}
项目:Forage    文件:PermissionsTest.java   
/**
 * Test to check if libraries are adding extra permissions to the app manifest.
 */
@Test
public void shouldMatchPermissions() {
    AndroidManifest manifest = new AndroidManifest(
            Fs.fileFromPath(MERGED_MANIFEST),
            null,
            null
    );

    assertThat(new HashSet<>(manifest.getUsedPermissions())).
            containsExactly((Object[]) EXPECTED_PERMISSIONS);
}
项目:MediaMonkey    文件:MyRobolectricGradleTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
    String basePath = new File(".").getAbsolutePath();
    String manifest = basePath + "/src/main/AndroidManifest.xml";
    String res = basePath + String.format("/build/intermediates/res/merged/%1$s/%2$s", BuildConfig.FLAVOR,
            BuildConfig.BUILD_TYPE);
    String asset = basePath + "/src/test/assets";
    return new AndroidManifest(Fs.fileFromPath(manifest), Fs.fileFromPath(res), Fs.fileFromPath(asset));
}
项目:materialandroid    文件:LibraryRobolectricTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
  AndroidManifest appManifest = super.getAppManifest(config);
  FsFile androidManifestFile = appManifest.getAndroidManifestFile();

  if (androidManifestFile.exists()) {
    return appManifest;
  } else {
    androidManifestFile = FileFsFile.from(appManifest.getAndroidManifestFile().getPath()
        .replace("manifests/full", "manifests/aapt"));
    return new AndroidManifest(androidManifestFile, appManifest.getResDirectory(), appManifest.getAssetsDirectory());
  }
}
项目:markdown-to-spanned    文件:ManifestedRobolectricGradeTestRunner.java   
protected AndroidManifest getAppManifest(Config config) {
    AndroidManifest appManifest = super.getAppManifest(config);
    FsFile androidManifestFile = appManifest.getAndroidManifestFile();

    if (androidManifestFile.exists()) {
        return appManifest;
    } else {
        String moduleRoot = getModuleRootPath(config);
        androidManifestFile = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath().replace("bundles", "manifests/full"));
        FsFile resDirectory = FileFsFile.from(moduleRoot, appManifest.getResDirectory().getPath());
        FsFile assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAssetsDirectory().getPath());
        return new AndroidManifest(androidManifestFile, resDirectory, assetsDirectory);
    }
}
项目:BaseUtil    文件:TestClient.java   
@Test
public void testPermissions() {
    String MERGED_MANIFEST = "build/intermediates/manifests/full/debug/AndroidManifest.xml";
    String EXPECTED_PERMISSIONS = "android.permission.INTERNET";

    AndroidManifest manifest = new AndroidManifest(Fs.fileFromPath(MERGED_MANIFEST), null, null);
    LogUtil.print(manifest.getUsedPermissions().toString());
    assertThat(manifest.getUsedPermissions()).contains(EXPECTED_PERMISSIONS);
}
项目:MVPAndroidBootstrap    文件:AppRobolectricRunner.java   
protected AndroidManifest getAppManifest(Config config) {
    AndroidManifest appManifest = super.getAppManifest(config);
    FsFile androidManifestFile = appManifest.getAndroidManifestFile();

    if (androidManifestFile.exists()) {
        return appManifest;
    } else {
        String moduleRoot = getModuleRootPath(config);
        androidManifestFile = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath().replace("bundles", "manifests/full"));
        FsFile resDirectory = FileFsFile.from(moduleRoot, appManifest.getResDirectory().getPath());
        FsFile assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAssetsDirectory().getPath());
        return new AndroidManifest(androidManifestFile, resDirectory, assetsDirectory);
    }
}
项目:Groover    文件:CustomRobolectricGradleTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
    String buildVariant = (BuildConfig.FLAVOR.isEmpty() ? "" : BuildConfig.FLAVOR + "/")
            + BuildConfig.BUILD_TYPE;
    return new AndroidManifest(
            Fs.fileFromPath("src/test/AndroidManifest.xml"),
            Fs.fileFromPath("build/intermediates/res/" + buildVariant),
            Fs.fileFromPath("src/test/assets")
    );
}
项目:MyConference    文件:RobolectricManifestTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
    String appRoot = "./app/src/main/";
    String manifestPath = appRoot + "AndroidManifest.xml";
    String resDir = appRoot + "res";
    String assetsDir = appRoot + "assets";
    AndroidManifest manifest = createAppManifest(Fs.fileFromPath(manifestPath),
            Fs.fileFromPath(resDir),
            Fs.fileFromPath(assetsDir));

    manifest.setPackageName("com.nhpatt.myconference");
    return manifest;
}
项目:hoko-android    文件:HokoGradleTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
    if (config.constants() == Void.class) {
        Logger.error("Field 'constants' not specified in @Config annotation");
        Logger.error("This is required when using RobolectricGradleTestRunner!");
        throw new RuntimeException("No 'constants' field in @Config annotation!");
    }

    final String type = getType(config);
    final String flavor = getFlavor(config);
    final String packageName = getPackageName(config);

    final FileFsFile res;
    final FileFsFile assets;
    final FileFsFile manifest;

    if (FileFsFile.from(BUILD_OUTPUT, "res").exists()) {
        res = FileFsFile.from(BUILD_OUTPUT, "res", flavor, type);
    } else {
        res = FileFsFile.from(BUILD_OUTPUT, "bundles", flavor, type, "res");
    }

    if (FileFsFile.from(BUILD_OUTPUT, "assets").exists()) {
        assets = FileFsFile.from(BUILD_OUTPUT, "assets", flavor, type);
    } else {
        assets = FileFsFile.from(BUILD_OUTPUT, "bundles", flavor, type, "assets");
    }

    if (FileFsFile.from(BUILD_OUTPUT, "manifests").exists()) {
        manifest = FileFsFile.from(BUILD_OUTPUT, "manifests", "androidTest", flavor, type, "AndroidManifest.xml");
    } else {
        manifest = FileFsFile.from(BUILD_OUTPUT, "bundles", flavor, type, "AndroidManifest.xml");
    }

    Logger.debug("Robolectric assets directory: " + assets.getPath());
    Logger.debug("   Robolectric res directory: " + res.getPath());
    Logger.debug("   Robolectric manifest path: " + manifest.getPath());
    Logger.debug("    Robolectric package name: " + packageName);
    return new AndroidManifest(manifest, res, assets, packageName);
}
项目:SnackbarBuilder    文件:LibraryRobolectricTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
  AndroidManifest appManifest = super.getAppManifest(config);
  FsFile androidManifestFile = appManifest.getAndroidManifestFile();

  if (androidManifestFile.exists()) {
    return appManifest;
  } else {
    androidManifestFile = FileFsFile.from(appManifest.getAndroidManifestFile().getPath()
        .replace("manifests/full", "manifests/aapt"));
    return new AndroidManifest(androidManifestFile, appManifest.getResDirectory(), appManifest.getAssetsDirectory());
  }
}
项目:tarcle-tdd    文件:TarcleRobolectricTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
    String path = "src/main/AndroidManifest.xml";

    // android studio has a different execution root for tests than pure gradle
    // so we avoid here manual effort to get them running inside android studio
    if (!new File(path).exists()) {
        path = "app/" + path;
    }

    config = overwriteConfig(config, "manifest", path);
    return super.getAppManifest(config);
}
项目:lasso    文件:CustomRobolectricRunner.java   
protected AndroidManifest getAppManifest(Config config) {
    AndroidManifest appManifest = super.getAppManifest(config);
    FsFile androidManifestFile = appManifest.getAndroidManifestFile();

    if (androidManifestFile.exists()) {
        return appManifest;
    } else {
        String moduleRoot = getModuleRootPath(config);
        androidManifestFile = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath().replace("bundles", "manifests/full"));
        FsFile resDirectory = FileFsFile.from(moduleRoot, appManifest.getResDirectory().getPath().replace("/res", "").replace("bundles", "res"));
        FsFile assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAssetsDirectory().getPath().replace("/assets", "").replace("bundles", "assets"));
        return new AndroidManifest(androidManifestFile, resDirectory, assetsDirectory);
    }
}
项目:okbuck    文件:BuckRobolectricTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
    String buckManifest = System.getProperty(ROBOLECTRIC_MANIFEST);
    String buckResourcesProperty = System.getProperty(ROBOLECTRIC_RESOURCE_DIRECTORIES);

    if (buckManifest != null && buckResourcesProperty != null) {
        final List<String> buckResources = Arrays.asList(buckResourcesProperty.split(File.pathSeparator));

        final FsFile res = Fs.fileFromPath(buckResources.get(buckResources.size() - 1));
        final FsFile assets = Fs.fileFromPath(buckResources.get(buckResources.size() - 1));
        final FsFile manifest = Fs.fileFromPath(buckManifest);

        return new AndroidManifest(manifest, res, assets, config.packageName()) {

            @Override
            public List<ResourcePath> getIncludedResourcePaths() {
                Collection<ResourcePath> resourcePaths = new LinkedHashSet<>();
                resourcePaths.add(super.getResourcePath());

                ListIterator<String> it = buckResources.listIterator(buckResources.size());
                while (it.hasPrevious()) {
                    resourcePaths.add(new ResourcePath(
                            getRClass(),
                            getPackageName(),
                            Fs.fileFromPath(it.previous()),
                            getAssetsDirectory()));
                }
                return new ArrayList<>(resourcePaths);
            }
        };
    } else {
        return null;
    }
}
项目:tickmate    文件:TickmateTestRunner.java   
protected AndroidManifest getAppManifest(Config config) {
    AndroidManifest appManifest = super.getAppManifest(config);
    FsFile androidManifestFile = appManifest.getAndroidManifestFile();

    if (androidManifestFile.exists()) {
        return appManifest;
    } else {
        androidManifestFile = FileFsFile.from(MODULE_ROOT, "src/main/AndroidManifest.xml");
        FsFile resDirectory = FileFsFile.from(MODULE_ROOT, "src/main/res");
        FsFile assetsDirectory = FileFsFile.from(MODULE_ROOT, "src/main/assets");

        return new AndroidManifest(androidManifestFile, resDirectory, assetsDirectory);
    }
}
项目:crom    文件:CustomRobolectricRunner.java   
protected AndroidManifest getAppManifest(Config config) {
    AndroidManifest appManifest = super.getAppManifest(config);
    FsFile androidManifestFile = appManifest.getAndroidManifestFile();

    if (androidManifestFile.exists()) {
        return appManifest;
    } else {
        String moduleRoot = getModuleRootPath(config);
        androidManifestFile = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath());
        FsFile resDirectory = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath().replace("AndroidManifest.xml", "res"));
        FsFile assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath().replace("AndroidManifest.xml", "assets"));
        return new AndroidManifest(androidManifestFile, resDirectory, assetsDirectory);
    }
}
项目:Awwl    文件:NBAbstractTest.java   
/**
 * Seems Robolectric didn't map the implicit intent, so mock them by myself.
 */
private void addImplicitIntentToPM() {
    RobolectricPackageManager rpm =
            (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();

    AndroidManifest appManifest = ShadowApplication.getInstance().getAppManifest();
    for (Map.Entry<String, ActivityData> activity : appManifest.getActivityDatas().entrySet()) {
        String activityName = activity.getKey();
        ActivityData activityData = activity.getValue();
        if (activityData.getTargetActivity() != null) {
            activityName = activityData.getTargetActivityName();
        }

        ApplicationInfo applicationInfo = new ApplicationInfo();
        applicationInfo.packageName = RuntimeEnvironment.application.getPackageName();
        ResolveInfo resolveInfo = new ResolveInfo();
        resolveInfo.resolvePackageName = RuntimeEnvironment.application.getPackageName();
        resolveInfo.activityInfo = new ActivityInfo();
        resolveInfo.activityInfo.applicationInfo = applicationInfo;
        resolveInfo.activityInfo.name = activityName;

        for (IntentFilterData intentFilterData : activityData.getIntentFilters()) {
            for (String intentFilterAction : intentFilterData.getActions()) {
                Intent i = new Intent(intentFilterAction);
                i.setPackage(RuntimeEnvironment.application.getPackageName());
                rpm.addResolveInfoForIntent(i, resolveInfo);
            }
        }
    }
}
项目:droidxing    文件:TestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {
    return new AndroidManifest(
            Fs.fileFromPath("src/main/AndroidManifest.xml"),
            Fs.fileFromPath("src/main/res"),
            Fs.fileFromPath("src/main/assets")) {
        @Override
        public int getTargetSdkVersion() {
            return 18;
        }
    };
}
项目:akvo-caddisfly    文件:AppTest.java   
@Test
public void shouldMatchPermissions() {
    AndroidManifest manifest = new AndroidManifest(
            Fs.fileFromPath(MERGED_MANIFEST),
            null,
            null
    );

    assertThat(new HashSet<>(manifest.getUsedPermissions())).
            containsOnly(EXPECTED_PERMISSIONS);
}
项目:osmdroid    文件:CustomTestRunner.java   
@Override
protected AndroidManifest getAppManifest(Config config) {

    String manifestPath = "AndroidManifest.xml";
    String resPath = "src/main/res/";
    String assets = "src/main/assets/";
    return new AndroidManifest(Fs.fileFromPath(manifestPath), Fs.fileFromPath(resPath), Fs.fileFromPath(assets)) {
        @Override
        public int getTargetSdkVersion() {
            return 18;
        }
    };
}
项目:mobile-sdk-android    文件:RoboelectricTestRunnerWithResources.java   
protected AndroidManifest getAppManifest(Config config) {
    AndroidManifest appManifest = super.getAppManifest(config);
    FsFile androidManifestFile = appManifest.getAndroidManifestFile();
    FsFile resDirectory;
    FsFile assetsDirectory;


    String moduleRoot = getModuleRootPath(config);
    androidManifestFile = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath().replace("bundles", "manifests/aapt"));

    if(appManifest.getResDirectory().getPath().contains("release")) {
        resDirectory = FileFsFile.from(moduleRoot, appManifest.getResDirectory().getPath().replace("release", "default"));
        assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAssetsDirectory().getPath().replace("release", "default"));
    }else{
        resDirectory = FileFsFile.from(moduleRoot, appManifest.getResDirectory().getPath().replace("bundles/debug/res", "res/merged/debug"));
        assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAssetsDirectory().getPath());
    }


    System.out.print(androidManifestFile.getPath() + '\n');
    System.out.print(resDirectory.getPath() + '\n');
    System.out.print(assetsDirectory.getPath() + '\n');


    return new AndroidManifest(androidManifestFile, resDirectory, assetsDirectory);

}
项目:mobile-sdk-android    文件:RoboelectricTestRunnerWithResources.java   
protected AndroidManifest getAppManifest(Config config) {
    AndroidManifest appManifest = super.getAppManifest(config);
    FsFile androidManifestFile = appManifest.getAndroidManifestFile();
    FsFile resDirectory;
    FsFile assetsDirectory;


        String moduleRoot = getModuleRootPath(config);
        androidManifestFile = FileFsFile.from(moduleRoot, appManifest.getAndroidManifestFile().getPath().replace("bundles", "manifests/aapt"));

        if(appManifest.getResDirectory().getPath().contains("release")) {
            resDirectory = FileFsFile.from(moduleRoot, appManifest.getResDirectory().getPath().replace("release", "default"));
            assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAssetsDirectory().getPath().replace("release", "default"));
        }else{
            resDirectory = FileFsFile.from(moduleRoot, appManifest.getResDirectory().getPath());
            assetsDirectory = FileFsFile.from(moduleRoot, appManifest.getAssetsDirectory().getPath());
        }


        System.out.print(androidManifestFile.getPath() + '\n');
        System.out.print(resDirectory.getPath() + '\n');
        System.out.print(assetsDirectory.getPath() + '\n');


        return new AndroidManifest(androidManifestFile, resDirectory, assetsDirectory);

}