android.test.RenamingDelegatingContext Java Examples

The following examples show how to use android.test.RenamingDelegatingContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocationProviderTestCase.java    From background-geolocation-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();

    mResolver = new MockContentResolver();
    RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext(
            new DelegatedMockContext(getContext()), // The context that most methods are delegated to
            getContext(), // The context that file methods are delegated to
            filenamePrefix);
    mProviderContext = new IsolatedContext(mResolver, targetContextWrapper);

    ProviderInfo providerInfo = new ProviderInfo();
    providerInfo.authority = mProviderAuthority;

    mProvider = mProviderClass.newInstance();
    mProvider.attachInfo(mProviderContext, providerInfo);
    assertNotNull(mProvider);
    mResolver.addProvider(mProviderAuthority, mProvider);
}
 
Example #2
Source File: SearchEngineTest.java    From mytracks with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();

  MockContentResolver mockContentResolver = new MockContentResolver();
  RenamingDelegatingContext targetContext = new RenamingDelegatingContext(
      getContext(), getContext(), "test.");
  MockContext context = new MockContext(mockContentResolver, targetContext);
  MyTracksProvider provider = new MyTracksProvider();
  provider.attachInfo(context, null);
  mockContentResolver.addProvider(MyTracksProviderUtils.AUTHORITY, provider);
  setContext(context);

  providerUtils = MyTracksProviderUtils.Factory.get(context);
  engine = new SearchEngine(providerUtils);
}
 
Example #3
Source File: MyTracksProviderUtilsImplTest.java    From mytracks with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();
  
  MockContentResolver mockContentResolver = new MockContentResolver();
  RenamingDelegatingContext targetContext = new RenamingDelegatingContext(
      getContext(), getContext(), "test.");
  context = new MockContext(mockContentResolver, targetContext);
  MyTracksProvider provider = new MyTracksProvider();
  provider.attachInfo(context, null);
  mockContentResolver.addProvider(MyTracksProviderUtils.AUTHORITY, provider);
  setContext(context);

  providerUtils = MyTracksProviderUtils.Factory.get(context);
  providerUtils.deleteAllTracks(context);
}
 
Example #4
Source File: UniversalSearchContractTest.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
private SQLiteDatabase createTables(final boolean delete, final UniversalSearchContract.Table... tables) {
    SQLiteDatabase db = null;
    final String filenamePrefix = "test.";
    RenamingDelegatingContext targetContextWrapper = new
            RenamingDelegatingContext(
            new MockContext2(), // The context that most methods are
            //delegated to
            getContext(), // The context that file methods are delegated to
            filenamePrefix);
    final Context context = new IsolatedContext(super.getContext().getContentResolver(), targetContextWrapper);
    try {
        db = context.openOrCreateDatabase(DATABASE, 1, null);
        for (final UniversalSearchContract.Table table : tables) {
            table.onCreate(db);
            log("Table " + table + " onCreate successful");
        }
        return db;
    } finally {
        if (null != db && delete) {
            db.close();
            context.deleteDatabase(DATABASE);
        }
    }
}
 
Example #5
Source File: LocationContentProviderTest.java    From background-geolocation-android with Apache License 2.0 5 votes vote down vote up
public void deleteDatabase() {
    // TODO: investigate why prefix is not automatically used when deleteDatabase
    RenamingDelegatingContext context = ((RenamingDelegatingContext) getMockContext().getBaseContext());

    SQLiteOpenHelper dbHelper = new SQLiteOpenHelper(context);
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    dbHelper.execAndLogSql(db, SQL_DROP_LOCATION_TABLE);
    dbHelper.onCreate(db);
}
 
Example #6
Source File: TrackDataHubTest.java    From mytracks with Apache License 2.0 5 votes vote down vote up
@UsesMocks({ MyTracksProviderUtils.class, DataSource.class, TrackDataListener.class })
@Override
protected void setUp() throws Exception {
  super.setUp();
  context = new MockContext(new MockContentResolver(), new RenamingDelegatingContext(
      getContext(), getContext(), "test."));
  sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
  myTracksProviderUtils = AndroidMock.createMock(MyTracksProviderUtils.class);
  dataSource = AndroidMock.createMock(DataSource.class, context);
  trackDataManager = new TrackDataManager();
  trackDataHub = new TrackDataHub(
      context, trackDataManager, myTracksProviderUtils, TARGET_POINTS) {
      @Override
    protected DataSource newDataSource() {
      return dataSource;
    }

      @Override
    protected void runInHanderThread(Runnable runnable) {
      // Run everything in the same thread
      runnable.run();
    }
  };

  trackDataListener1 = AndroidMock.createStrictMock(
      "trackDataListener1", TrackDataListener.class);
  trackDataListener2 = AndroidMock.createStrictMock(
      "trackDataListener2", TrackDataListener.class);
  PreferencesUtils.setLong(context, R.string.recording_track_id_key, TRACK_ID);
}
 
Example #7
Source File: FileTrackExporterTest.java    From mytracks with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();

  MockContentResolver mockContentResolver = new MockContentResolver();
  RenamingDelegatingContext targetContext = new RenamingDelegatingContext(
      getContext(), getContext(), "test.");
  Context context = new MockContext(mockContentResolver, targetContext);
  MyTracksProvider myTracksProvider = new MyTracksProvider();
  myTracksProvider.attachInfo(context, null);
  mockContentResolver.addProvider(MyTracksProviderUtils.AUTHORITY, myTracksProvider);
  setContext(context);
  myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
  oldProviderUtilsFactory = TestingProviderUtilsFactory.installWithInstance(
      myTracksProviderUtils);

  mocksControl = EasyMock.createStrictControl();
  trackWriter = mocksControl.createMock(TrackWriter.class);

  Track track = new Track();
  track.setName(TRACK_NAME);
  track.setId(TRACK_ID);

  tracks = new Track[] {track};
  
  outputStream = new ByteArrayOutputStream();
  TrackExporterListener trackExporterListener = new TrackExporterListener() {
    
      @Override
    public void onProgressUpdate(int number, int max) {
      // Safe to ignore

    }
  };
  fileTrackExporter = new FileTrackExporter(
      myTracksProviderUtils, tracks, trackWriter, trackExporterListener);
}
 
Example #8
Source File: CalculatorProviderTest.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setup()
{
    mockContext = new RenamingDelegatingContext(InstrumentationRegistry.getTargetContext(), "test_");
    sunCalculator = getCalculator("");
    moonCalculator = getCalculator("moon");

    TEST_DATE0 = Calendar.getInstance(moonCalculator.getTimeZone());
    TEST_DATE0.set(2018, 0, 1, 0, 0, 0);

    TEST_DATE1 = Calendar.getInstance(moonCalculator.getTimeZone());
    TEST_DATE1.set(2019, 0, 1, 0, 0, 0);
}
 
Example #9
Source File: GetFixDatabaseAdapterTest.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setup()
{
    mockContext = new RenamingDelegatingContext(InstrumentationRegistry.getTargetContext(), "test_");
    db = new GetFixDatabaseAdapter(mockContext.getApplicationContext());
    db.open();
    db.clearPlaces();
    db.close();
}
 
Example #10
Source File: SuntimesUtilsTest.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setup()
{
    mockContext = new RenamingDelegatingContext(InstrumentationRegistry.getTargetContext(), "test_");
    warningDrawable = mockContext.getResources().getDrawable(warningDrawableID);

    SuntimesUtils.initDisplayStrings(mockContext);
    utils = new SuntimesUtils();
}
 
Example #11
Source File: SuntimesThemeProviderTest.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
@Before
public void setup() {
    mockContext = new RenamingDelegatingContext(InstrumentationRegistry.getTargetContext(), "test_");
    WidgetThemes.initThemes(mockContext);
}
 
Example #12
Source File: SuntimesCalculatorTest.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
@Before
public void setup()
{
    mockContext = new RenamingDelegatingContext(InstrumentationRegistry.getTargetContext(), "test_");
}