本文整理汇总了Java中android.test.mock.MockContentProvider类的典型用法代码示例。如果您正苦于以下问题:Java MockContentProvider类的具体用法?Java MockContentProvider怎么用?Java MockContentProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MockContentProvider类属于android.test.mock包,在下文中一共展示了MockContentProvider类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testClearAllFails
import android.test.mock.MockContentProvider; //导入依赖的package包/类
public void testClearAllFails() throws Exception {
final MockContentProvider mockContentProvider = new MockContentProvider(
getProviderMockContext()) {
@Override
public int delete(final Uri uri, final String selection, final String[] selectionArgs) {
throw new IllegalStateException("something serious is wrong");
}
};
getProviderMockContext().addProvider(MockProvider.AUTHORITY, mockContentProvider);
getProviderMockContext().enableMockResolver(true);
final Tray tray = new Tray(getProviderMockContext());
final TestTrayModulePreferences module2 =
new TestTrayModulePreferences(getProviderMockContext(), "module2");
module2.put("blubb", "hello");
mTrayModulePref.put("test", "test");
assertUserDatabaseSize(2);
assertFalse(tray.clear());
assertUserDatabaseSize(2);
}
示例2: testSimpleOperationSucceeds
import android.test.mock.MockContentProvider; //导入依赖的package包/类
public void testSimpleOperationSucceeds() {
final AssertionLatch latch = new AssertionLatch(1);
final TestSimpleOperation operation = new TestSimpleOperation(URI);
operation.setRequestExecutor(new RequestExecutor.SerialRequestExecutor());
operation.setContext(new MockContextWithProvider(new MockContentProvider() {
@Override
public int bulkInsert(Uri uri, ContentValues[] values) {
return 0;
}
}));
operation.setOperationObserver(new OperationObserver() {
@Override
public void onOperationComplete(final Operation o) {
latch.countDown();
assertNull(o.getError());
}
});
operation.execute();
latch.assertComplete();
}
示例3: testClearButFails
import android.test.mock.MockContentProvider; //导入依赖的package包/类
public void testClearButFails() throws Exception {
final MockContentProvider mockContentProvider = new MockContentProvider(
getProviderMockContext()) {
@Override
public int delete(final Uri uri, final String selection, final String[] selectionArgs) {
throw new IllegalStateException("something serious is wrong");
}
};
getProviderMockContext().addProvider(MockProvider.AUTHORITY, mockContentProvider);
getProviderMockContext().enableMockResolver(true);
final Tray tray = new Tray(getProviderMockContext());
tray.clearBut(new AppPreferences(getProviderMockContext()));
}
示例4: testWipeFails
import android.test.mock.MockContentProvider; //导入依赖的package包/类
public void testWipeFails() throws Exception {
final MockContentProvider mockContentProvider = new MockContentProvider(
getProviderMockContext()) {
@Override
public int delete(final Uri uri, final String selection, final String[] selectionArgs) {
throw new IllegalStateException("something serious is wrong");
}
};
getProviderMockContext().addProvider(MockProvider.AUTHORITY, mockContentProvider);
final Tray tray = new Tray(getProviderMockContext());
getProviderMockContext().enableMockResolver(true);
assertFalse(tray.wipe());
}
示例5: testSimpleOperationInsertsDataOnSuccess
import android.test.mock.MockContentProvider; //导入依赖的package包/类
public void testSimpleOperationInsertsDataOnSuccess() throws Exception {
final AssertionLatch latch = new AssertionLatch(1);
final MockContext context = new MockContextWithProvider(new MockContentProvider() {
@Override
public int bulkInsert(Uri u, ContentValues[] v) {
latch.countDown();
assertEquals(URI, u);
return 0;
}
});
final TestSimpleOperation operation = new TestSimpleOperation(URI);
operation.onPostExecute(context, new ContentValues[0]);
latch.assertComplete();
}
示例6: MockContextWithProvider
import android.test.mock.MockContentProvider; //导入依赖的package包/类
public MockContextWithProvider(final MockContentProvider provider) {
mProvider = provider;
}