@Override public void process(final NeedleContext context) { final List<Field> fields = context.getAnnotatedTestcaseFields(Mock.class); for (Field field : fields) { Object mock = mockProvider.createMockComponent(field.getType()); try { ReflectionUtil.setField(field, context.getTest(), mock); } catch (Exception e) { LOG.warn("could not assign mock obejct " + mock, e); } } }
/* * {@inheritDoc} */ @SuppressWarnings("unused") @Override public void onPerformSync( Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) throws SecurityException { if (D) Log.d(TAG, "onPerformSync(..."); if (!Application.ACCOUNT_WITH_SYNC) return; final ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(10); final MockProvider driver = MockProviderService._binder; Cursor cursor = null; try { syncResult.stats.numDeletes = _resolver.delete( RawContacts.CONTENT_URI, VolatileRawContact.MUST_DELETED + "=1 and " + RawContacts.ACCOUNT_NAME + "=" + DatabaseUtils.sqlEscapeString(account.name) + " and " + RawContacts.ACCOUNT_TYPE + "='" + account.type + "'" + " and " + RawContacts.DELETED + "=0", null); int numEntries = 0; int numUpdates = 0; cursor = _resolver.query( RawContacts.CONTENT_URI, COLS_RAW, RawContacts.ACCOUNT_NAME + "=" + DatabaseUtils.sqlEscapeString(account.name) + " and " + RawContacts.ACCOUNT_TYPE + "='" + account.type + "'" + " and " + RawContacts.DELETED + "=0" + " and " + VolatileRawContact.MUST_DELETED + "=0", null, null); while (cursor.moveToNext()) { final long id = cursor.getLong(0 /*_ID*/); try { final String lookup = cursor.getString(1 /*LOOKUP*/); if (I) Log.i(TAG, "Sync." + lookup); ++numEntries; VolatileRawContact volatileContact = driver.getContact(account.name, lookup).getRawContact(); volatileContact.updateInAndroid( _resolver, ContentUris.withAppendedId(RawContacts.CONTENT_URI, id), operationList); ++numUpdates; } catch (Exception e) // $codepro.audit.disable caughtExceptions { if (W) Log.w(TAG, "onPerformSync", e); operationList.add( ContentProviderOperation.newUpdate( ContentUris.withAppendedId(RawContacts.CONTENT_URI, id)) .withValue(RawContacts.DIRTY, 1) .build()); syncResult.fullSyncRequested = true; // ++syncResult.stats.numAuthExceptions; } } _resolver.applyBatch(ContactsContract.AUTHORITY, operationList); syncResult.stats.numEntries = numEntries; syncResult.stats.numUpdates = numUpdates; } catch (RemoteException e) { syncResult.databaseError = true; if (W) Log.w(TAG, "onPerformSync", e); } catch (OperationApplicationException e) { if (W) Log.w(TAG, "onPerformSync", e); syncResult.databaseError = true; } finally { if (cursor != null) cursor.close(); } }