All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.robolectric.shadows.SQLiteShadowPicker Maven / Gradle / Ivy

package org.robolectric.shadows;

import com.google.common.collect.ImmutableSet;
import org.robolectric.annotation.SQLiteMode;
import org.robolectric.annotation.SQLiteMode.Mode;
import org.robolectric.config.ConfigurationRegistry;
import org.robolectric.shadow.api.ShadowPicker;

/** A {@link ShadowPicker} that selects between shadows given the SQLite mode */
public class SQLiteShadowPicker implements ShadowPicker {

  private final Class legacyShadowClass;
  private final Class nativeShadowClass;

  private static final ImmutableSet AFFECTED_CLASSES =
      ImmutableSet.of("android.database.CursorWindow", "android.database.sqlite.SQLiteConnection");

  public SQLiteShadowPicker(
      Class legacyShadowClass, Class nativeShadowClass) {
    this.legacyShadowClass = legacyShadowClass;
    this.nativeShadowClass = nativeShadowClass;
  }

  @Override
  public Class pickShadowClass() {
    if (ConfigurationRegistry.get(SQLiteMode.Mode.class) == Mode.NATIVE) {
      return nativeShadowClass;
    } else {
      return legacyShadowClass;
    }
  }

  /**
   * Returns a list of shadow classes that need to be invalidated when the SQLite Mode is switched.
   */
  public static ImmutableSet getAffectedClasses() {
    return AFFECTED_CLASSES;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy