Class SingleValueConfigurer<A extends Annotation,T extends Enum<T>>

java.lang.Object
org.robolectric.plugins.config.SingleValueConfigurer<A,T>
All Implemented Interfaces:
Configurer<T>
Direct Known Subclasses:
ConscryptModeConfigurer, GraphicsModeConfigurer, LazyApplicationConfigurer, LooperModeConfigurer, SQLiteModeConfigurer, TextLayoutModeConfigurer

public abstract class SingleValueConfigurer<A extends Annotation,T extends Enum<T>> extends Object implements Configurer<T>
The base class for all enumeration based single value robolectric configuration annotations. Simply extending and providing a constructor is sufficient to allow for robolectric.properties reading, reading system properties, and providing a default value.

The property name in system properties is the simple name of annotation being read, with the first letter lower cased, unless propertyName() is overridden, prefixed with "robolectric."

The property name in robolectric is the simple name of annotation being read, with the first letter lower cased, unless propertyName() is overridden, note that there is no prefix.

All values are eagerly cached at construction of an instance.

  • Constructor Details

  • Method Details

    • propertyName

      protected String propertyName()
      Computes the property name that will be used to look for values in a property file, or in System properties
    • getConfigClass

      public Class<T> getConfigClass()
      Description copied from interface: Configurer
      Retrieve the class type for this Configurer
      Specified by:
      getConfigClass in interface Configurer<A extends Annotation>
    • defaultConfig

      @Nonnull public T defaultConfig()
      Description copied from interface: Configurer
      Returns the default configuration for tests that do not specify a configuration of this type.
      Specified by:
      defaultConfig in interface Configurer<A extends Annotation>
    • getConfigFor

      public T getConfigFor(@Nonnull String packageName)
      Description copied from interface: Configurer
      Returns the configuration for a given package.

      This method will be called once for package in the hierarchy leading to the test class being configured. For example, for com.example.FooTest, this method will be called three times with "com.example", "@com", and "" (representing the top level package).

      Specified by:
      getConfigFor in interface Configurer<A extends Annotation>
      Parameters:
      packageName - the name of the package, or the empty string representing the top level unnamed package
      Returns:
      a configuration object, or null if the given properties has no relevant data for this configuration
    • getConfigFor

      public T getConfigFor(@Nonnull Class<?> testClass)
      Description copied from interface: Configurer
      Returns the configuration for the given class.

      This method will be called for each class in the test's class inheritance hierarchy.

      Specified by:
      getConfigFor in interface Configurer<A extends Annotation>
      Returns:
      a configuration object, or null if the given class has no relevant data for this configuration
    • getConfigFor

      public T getConfigFor(@Nonnull Method method)
      Description copied from interface: Configurer
      Returns the configuration for the given method.
      Specified by:
      getConfigFor in interface Configurer<A extends Annotation>
      Returns:
      a configuration object, or null if the given method has no relevant data for this configuration
    • getProperty

      protected final String getProperty(String property)
    • merge

      @Nonnull public T merge(@Nonnull T parentConfig, @Nonnull T childConfig)
      Description copied from interface: Configurer
      Merges two configurations. This method will called whenever Configurer.getConfigFor(java.lang.String) returns a non-null configuration object.
      Specified by:
      merge in interface Configurer<A extends Annotation>
      Parameters:
      parentConfig - a less specific configuration object
      childConfig - a more specific configuration object
      Returns:
      the new configuration with merged parent and child data.
    • valueFrom

      protected T valueFrom(A annotation)
    • valueFrom

      protected T valueFrom(String value)