Search in sources :

Example 6 with MockContext

use of android.test.mock.MockContext in project android_frameworks_base by ResurrectionRemix.

the class ProviderTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mResolver = new MockContentResolver();
    final String filenamePrefix = "test.";
    RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext(// The context that most methods are delegated to
    new MockContext(), // The context that file methods are delegated to
    getInstrumentation().getTargetContext(), filenamePrefix);
    mProviderContext = new IsolatedContext(mResolver, targetContextWrapper);
    mProvider = ProviderTestCase2.createProviderForTest(mProviderContext, mProviderClass, mProviderAuthority);
    mResolver.addProvider(mProviderAuthority, getProvider());
}
Also used : MockContext(android.test.mock.MockContext) MockContentResolver(android.test.mock.MockContentResolver)

Example 7 with MockContext

use of android.test.mock.MockContext in project android_frameworks_base by ResurrectionRemix.

the class ProviderTestCase method newResolverWithContentProviderFromSql.

public static <T extends ContentProvider> ContentResolver newResolverWithContentProviderFromSql(Context targetContext, Class<T> providerClass, String authority, String databaseName, int databaseVersion, String sql) throws IllegalAccessException, InstantiationException {
    final String filenamePrefix = "test.";
    MockContentResolver resolver = new MockContentResolver();
    RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext(// The context that most methods are delegated to
    new MockContext(), // The context that file methods are delegated to
    targetContext, filenamePrefix);
    Context context = new IsolatedContext(resolver, targetContextWrapper);
    DatabaseUtils.createDbFromSqlStatements(context, databaseName, databaseVersion, sql);
    T provider = ProviderTestCase2.createProviderForTest(context, providerClass, authority);
    resolver.addProvider(authority, provider);
    return resolver;
}
Also used : Context(android.content.Context) MockContext(android.test.mock.MockContext) MockContext(android.test.mock.MockContext) MockContentResolver(android.test.mock.MockContentResolver)

Example 8 with MockContext

use of android.test.mock.MockContext in project android_frameworks_base by ResurrectionRemix.

the class ListViewTest method testNoSelectableItems.

/**
     * The list view should handle the disappearance of the only selected item, even when that item
     * was selected before its disappearance.
     *
     */
@MediumTest
public void testNoSelectableItems() throws Exception {
    MockContext context = new MockContext2();
    ListView listView = new ListView(context);
    // We use a header as the unselectable item to remain after the selectable one is removed.
    listView.addHeaderView(new View(context), null, false);
    List<String> items = Lists.newArrayList("hello");
    Adapter<String> adapter = new Adapter<String>(context, 0, items);
    listView.setAdapter(adapter);
    listView.setSelection(1);
    int measureSpec = View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.EXACTLY);
    adapter.notifyDataSetChanged();
    listView.measure(measureSpec, measureSpec);
    listView.layout(0, 0, 100, 100);
    items.remove(0);
    adapter.notifyDataSetChanged();
    listView.measure(measureSpec, measureSpec);
    listView.layout(0, 0, 100, 100);
}
Also used : MockContext(android.test.mock.MockContext) ListView(android.widget.ListView) ArrayAdapter(android.widget.ArrayAdapter) View(android.view.View) ListView(android.widget.ListView) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 9 with MockContext

use of android.test.mock.MockContext in project android_frameworks_base by DirtyUnicorns.

the class ProviderTestCase method newResolverWithContentProviderFromSql.

public static <T extends ContentProvider> ContentResolver newResolverWithContentProviderFromSql(Context targetContext, Class<T> providerClass, String authority, String databaseName, int databaseVersion, String sql) throws IllegalAccessException, InstantiationException {
    final String filenamePrefix = "test.";
    MockContentResolver resolver = new MockContentResolver();
    RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext(// The context that most methods are delegated to
    new MockContext(), // The context that file methods are delegated to
    targetContext, filenamePrefix);
    Context context = new IsolatedContext(resolver, targetContextWrapper);
    DatabaseUtils.createDbFromSqlStatements(context, databaseName, databaseVersion, sql);
    T provider = ProviderTestCase2.createProviderForTest(context, providerClass, authority);
    resolver.addProvider(authority, provider);
    return resolver;
}
Also used : Context(android.content.Context) MockContext(android.test.mock.MockContext) MockContext(android.test.mock.MockContext) MockContentResolver(android.test.mock.MockContentResolver)

Example 10 with MockContext

use of android.test.mock.MockContext in project android_frameworks_base by DirtyUnicorns.

the class ProviderTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mResolver = new MockContentResolver();
    final String filenamePrefix = "test.";
    RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext(// The context that most methods are delegated to
    new MockContext(), // The context that file methods are delegated to
    getInstrumentation().getTargetContext(), filenamePrefix);
    mProviderContext = new IsolatedContext(mResolver, targetContextWrapper);
    mProvider = ProviderTestCase2.createProviderForTest(mProviderContext, mProviderClass, mProviderAuthority);
    mResolver.addProvider(mProviderAuthority, getProvider());
}
Also used : MockContext(android.test.mock.MockContext) MockContentResolver(android.test.mock.MockContentResolver)

Aggregations

MockContext (android.test.mock.MockContext)32 MockContentResolver (android.test.mock.MockContentResolver)16 Context (android.content.Context)14 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 ArrayAdapter (android.widget.ArrayAdapter)12 ListView (android.widget.ListView)12 View (android.view.View)6 ContentProvider (android.content.ContentProvider)1 Intent (android.content.Intent)1 IsolatedContext (android.test.IsolatedContext)1 RenamingDelegatingContext (android.test.RenamingDelegatingContext)1