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;
}
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;
}
}
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;
}
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);
}
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);
}
Aggregations