Search in sources :

Example 71 with Config

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

the class RobolectricTestRunner method getChildren.

@Override
protected List<FrameworkMethod> getChildren() {
    List<FrameworkMethod> children = new ArrayList<>();
    for (FrameworkMethod frameworkMethod : super.getChildren()) {
        try {
            Config config = getConfig(frameworkMethod.getMethod());
            AndroidManifest appManifest = getAppManifest(config);
            List<SdkConfig> sdksToRun = sdkPicker.selectSdks(config, appManifest);
            RobolectricFrameworkMethod last = null;
            for (SdkConfig sdkConfig : sdksToRun) {
                last = new RobolectricFrameworkMethod(frameworkMethod.getMethod(), appManifest, sdkConfig, config);
                children.add(last);
            }
            if (last != null) {
                last.dontIncludeApiLevelInName();
            }
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("failed to configure " + getTestClass().getName() + "." + frameworkMethod.getMethod().getName() + ": " + e.getMessage(), e);
        }
    }
    return children;
}
Also used : Config(org.robolectric.annotation.Config) AndroidManifest(org.robolectric.manifest.AndroidManifest) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 72 with Config

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

the class ConfigMerger method cachedPackageConfig.

@Nullable
private Config cachedPackageConfig(String packageName) {
    synchronized (packageConfigCache) {
        Config config = packageConfigCache.get(packageName);
        if (config == null && !packageConfigCache.containsKey(packageName)) {
            config = buildPackageConfig(packageName);
            packageConfigCache.put(packageName, config);
        }
        return config;
    }
}
Also used : Config(org.robolectric.annotation.Config) Nullable(org.jetbrains.annotations.Nullable)

Example 73 with Config

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

the class ConfigMerger method getConfig.

/**
   * Calculate the {@link Config} for the given test.
   *
   * @param testClass the class containing the test
   * @param method the test method
   * @param globalConfig global configuration values
   * @return the effective configuration
   * @since 3.2
   */
public Config getConfig(Class<?> testClass, Method method, Config globalConfig) {
    Config config = Config.Builder.defaults().build();
    config = override(config, globalConfig);
    for (String packageName : reverse(packageHierarchyOf(testClass))) {
        Config packageConfig = cachedPackageConfig(packageName);
        config = override(config, packageConfig);
    }
    for (Class clazz : reverse(parentClassesFor(testClass))) {
        Config classConfig = (Config) clazz.getAnnotation(Config.class);
        config = override(config, classConfig);
    }
    Config methodConfig = method.getAnnotation(Config.class);
    config = override(config, methodConfig);
    return config;
}
Also used : Config(org.robolectric.annotation.Config)

Example 74 with Config

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

the class ShadowStatFsTest method withApi18_shouldResetStateBetweenTests.

@Test
@Config(minSdk = JELLY_BEAN_MR2)
public void withApi18_shouldResetStateBetweenTests() {
    StatFs statsFs = new StatFs("/tmp");
    assertThat(statsFs.getBlockCountLong()).isEqualTo(0);
    assertThat(statsFs.getAvailableBlocksLong()).isEqualTo(0);
    assertThat(statsFs.getBlockSizeLong()).isEqualTo(ShadowStatFs.BLOCK_SIZE);
}
Also used : StatFs(android.os.StatFs) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 75 with Config

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

the class ShadowStatFsTest method withApi18_shouldRegisterStatsWithFile.

@Test
@Config(minSdk = JELLY_BEAN_MR2)
public void withApi18_shouldRegisterStatsWithFile() {
    ShadowStatFs.registerStats(new File("/tmp"), 100, 20, 10);
    StatFs statsFs = new StatFs(new File("/tmp").getAbsolutePath());
    assertThat(statsFs.getBlockCountLong()).isEqualTo(100);
    assertThat(statsFs.getAvailableBlocksLong()).isEqualTo(10L);
    assertThat(statsFs.getBlockSizeLong()).isEqualTo(ShadowStatFs.BLOCK_SIZE);
}
Also used : StatFs(android.os.StatFs) File(java.io.File) 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