Search in sources :

Example 1 with ConfigurationStrategy

use of org.robolectric.pluginapi.config.ConfigurationStrategy in project robolectric by robolectric.

the class HierarchicalConfigurationStrategyTest method testBigOAndCaching.

@Test
public void testBigOAndCaching() throws Exception {
    SpyConfigurer spyConfigurer = new SpyConfigurer();
    ConfigurationStrategy configStrategy = new HierarchicalConfigurationStrategy(spyConfigurer);
    computeConfig(configStrategy, Test1A.class, "withoutAnnotation");
    assertThat(spyConfigurer.log).containsExactly("default", "withoutAnnotation", Test1A.class.getName(), Test1.class.getName(), "org.robolectric.plugins", "org.robolectric", "org", "(top)").inOrder();
    spyConfigurer.log.clear();
    computeConfig(configStrategy, Test1.class, "withoutAnnotation");
    assertThat(spyConfigurer.log).containsExactly("withoutAnnotation").inOrder();
    spyConfigurer.log.clear();
    computeConfig(configStrategy, Test2A.class, "withOverrideAnnotation");
    assertThat(spyConfigurer.log).containsExactly("withOverrideAnnotation", Test2A.class.getName(), Test2.class.getName()).inOrder();
}
Also used : ConfigurationStrategy(org.robolectric.pluginapi.config.ConfigurationStrategy) Test(org.junit.Test)

Example 2 with ConfigurationStrategy

use of org.robolectric.pluginapi.config.ConfigurationStrategy in project robolectric by robolectric.

the class HierarchicalConfigurationStrategyTest method testTestClassMatters.

@Test
public void testTestClassMatters() throws Exception {
    SpyConfigurer spyConfigurer = new SpyConfigurer();
    ConfigurationStrategy configStrategy = new HierarchicalConfigurationStrategy(spyConfigurer);
    assertThat(computeConfig(configStrategy, Test1.class, "withoutAnnotation")).isEqualTo("default:(top):org:org.robolectric:org.robolectric.plugins" + ":" + Test1.class.getName() + ":withoutAnnotation");
    assertThat(computeConfig(configStrategy, Test1A.class, "withoutAnnotation")).isEqualTo("default:(top):org:org.robolectric:org.robolectric.plugins" + ":" + Test1.class.getName() + ":" + Test1A.class.getName() + ":withoutAnnotation");
}
Also used : ConfigurationStrategy(org.robolectric.pluginapi.config.ConfigurationStrategy) Test(org.junit.Test)

Example 3 with ConfigurationStrategy

use of org.robolectric.pluginapi.config.ConfigurationStrategy in project robolectric by robolectric.

the class HierarchicalConfigurationStrategyTest method testPrecedence.

@Test
public void testPrecedence() throws Exception {
    SpyConfigurer spyConfigurer = new SpyConfigurer();
    ConfigurationStrategy configStrategy = new HierarchicalConfigurationStrategy(spyConfigurer);
    assertThat(computeConfig(configStrategy, Test1.class, "withoutAnnotation")).isEqualTo("default:(top):org:org.robolectric:org.robolectric.plugins" + ":" + Test1.class.getName() + ":withoutAnnotation");
    assertThat(computeConfig(configStrategy, Test1A.class, "withOverrideAnnotation")).isEqualTo("default:(top):org:org.robolectric:org.robolectric.plugins" + ":" + Test1.class.getName() + ":" + Test1A.class.getName() + ":withOverrideAnnotation");
}
Also used : ConfigurationStrategy(org.robolectric.pluginapi.config.ConfigurationStrategy) Test(org.junit.Test)

Example 4 with ConfigurationStrategy

use of org.robolectric.pluginapi.config.ConfigurationStrategy in project robolectric by robolectric.

the class HierarchicalConfigurationStrategyTest method configFor.

private Config configFor(Class<?> testClass, String methodName, final Map<String, String> configProperties, Config.Implementation globalConfig) {
    Method info = getMethod(testClass, methodName);
    PackagePropertiesLoader packagePropertiesLoader = new PackagePropertiesLoader() {

        @Override
        InputStream getResourceAsStream(String resourceName) {
            String properties = configProperties.get(resourceName);
            return properties == null ? null : new ByteArrayInputStream(properties.getBytes(UTF_8));
        }
    };
    ConfigurationStrategy defaultConfigStrategy = new HierarchicalConfigurationStrategy(new ConfigConfigurer(packagePropertiesLoader, () -> globalConfig == null ? Config.Builder.defaults().build() : globalConfig));
    Configuration config = defaultConfigStrategy.getConfig(testClass, info);
    return config.get(Config.class);
}
Also used : ConfigurationStrategy(org.robolectric.pluginapi.config.ConfigurationStrategy) Configuration(org.robolectric.pluginapi.config.ConfigurationStrategy.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) Method(java.lang.reflect.Method)

Aggregations

ConfigurationStrategy (org.robolectric.pluginapi.config.ConfigurationStrategy)4 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Method (java.lang.reflect.Method)1 Configuration (org.robolectric.pluginapi.config.ConfigurationStrategy.Configuration)1