17a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank/*
27a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank * Copyright (C) 2010 The Android Open Source Project
37a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *
47a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank * Licensed under the Apache License, Version 2.0 (the "License");
57a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank * you may not use this file except in compliance with the License.
67a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank * You may obtain a copy of the License at
77a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *
87a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *      http://www.apache.org/licenses/LICENSE-2.0
97a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *
107a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank * Unless required by applicable law or agreed to in writing, software
117a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank * distributed under the License is distributed on an "AS IS" BASIS,
127a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank * See the License for the specific language governing permissions and
147a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank * limitations under the License.
157a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank */
167a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank
177a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blankpackage com.android.exchange.provider;
187a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank
197a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blankimport android.content.ContentProvider;
207a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blankimport android.content.ContentValues;
21bd8ccb0148ec0a4e91741535e255bd1e4d2ea1e4Marc Blankimport android.content.Context;
227a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blankimport android.content.UriMatcher;
237a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blankimport android.database.Cursor;
247a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blankimport android.database.MatrixCursor;
257a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blankimport android.net.Uri;
267a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank
277a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blankimport java.util.ArrayList;
287a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blankimport java.util.HashMap;
297a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blankimport java.util.Set;
307a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blankimport java.util.Map.Entry;
317a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank
327a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank/**
337a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank * MockProvider is a ContentProvider that can be used to simulate the storage and retrieval of
347a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank * records from any ContentProvider, even if that ContentProvider does not exist in the caller's
357a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank * package.  It is specifically designed to enable testing of sync adapters that create
367a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank * ContentProviderOperations (CPOs) that are then executed using ContentResolver.applyBatch()
377a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *
387a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank * Why is this useful?  Because we can't instantiate CalendarProvider or ContactsProvider from our
397a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank * package, as required by MockContentResolver.addProvider()
407a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *
417a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank * Usage:
427a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *     ContentResolver.applyBatch(MockProvider.AUTHORITY, batch) will cause the CPOs to be executed,
437a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *     returning an array of ContentProviderResult; in the case of inserts, the result will include
447a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *     a Uri that can be used via query().  Note that the CPOs in the batch can contain references
457a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *     to any authority.
467a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *
477a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *     query() does not allow non-null selection, selectionArgs, or sortOrder arguments; the
487a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *     presence of these will result in an UnsupportedOperationException
497a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *
507a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *     insert() acts as expected, returning a Uri that can be directly used in a query
517a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *
527a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *     delete() and update() do not allow non-null selection or selectionArgs arguments; the
537a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *     presence of these will result in an UnsupportedOperationException
547a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *
557a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *     NOTE: When using any operation other than applyBatch, the Uri to be used must be created
567a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *     with MockProvider.uri(yourUri).  This guarantees that the operation is sent to MockProvider
577a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *
587a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *     NOTE: MockProvider only simulates direct storage/retrieval of rows; it does not (and can not)
597a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *     simulate other actions (e.g. creation of ancillary data) that the actual provider might
607a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *     perform
617a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *
627a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank *     NOTE: See MockProviderTests for usage examples
637a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank **/
647a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blankpublic class MockProvider extends ContentProvider {
657a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    public static final String AUTHORITY = "com.android.exchange.mock.provider";
667a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    /*package*/ static final UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH);
677a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank
687a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    /*package*/ static final int TABLE = 100;
697a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    /*package*/ static final int RECORD = 101;
707a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank
717a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    public static final String ID_COLUMN = "_id";
727a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank
73bd8ccb0148ec0a4e91741535e255bd1e4d2ea1e4Marc Blank    public MockProvider(Context context) {
74bd8ccb0148ec0a4e91741535e255bd1e4d2ea1e4Marc Blank        super(context, null, null, null);
75bd8ccb0148ec0a4e91741535e255bd1e4d2ea1e4Marc Blank    }
76bd8ccb0148ec0a4e91741535e255bd1e4d2ea1e4Marc Blank
77a94550c7a6b9cbee78165503232736b64f694cadMarc Blank    public MockProvider() {
78a94550c7a6b9cbee78165503232736b64f694cadMarc Blank        super();
79a94550c7a6b9cbee78165503232736b64f694cadMarc Blank    }
80a94550c7a6b9cbee78165503232736b64f694cadMarc Blank
817a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    // We'll store our values here
827a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    private HashMap<String, ContentValues> mMockStore = new HashMap<String, ContentValues>();
837a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    // And we'll generate new id's from here
847a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    long mMockId = 1;
857a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank
867a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    /**
877a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank     * Create a Uri for MockProvider from a given Uri
887a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank     * @param uri the Uri from which the MockProvider Uri will be created
897a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank     * @return a Uri that can be used with MockProvider
907a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank     */
917a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    public static Uri uri(Uri uri) {
927a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        return new Uri.Builder().scheme("content").authority(AUTHORITY)
937a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            .path(uri.getPath().substring(1)).build();
947a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    }
957a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank
967a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    @Override
977a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    public int delete(Uri uri, String selection, String[] selectionArgs) {
987a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        if (selection != null || selectionArgs != null) {
997a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            throw new UnsupportedOperationException();
1007a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        }
1017a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        String path = uri.getPath();
1027a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        if (mMockStore.containsKey(path)) {
1037a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            mMockStore.remove(path);
1047a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            return 1;
1057a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        } else {
1067a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            return 0;
1077a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        }
1087a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    }
1097a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank
1107a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    @Override
1117a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    public String getType(Uri uri) {
1127a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        throw new UnsupportedOperationException();
1137a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    }
1147a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank
1157a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    @Override
1167a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    public Uri insert(Uri uri, ContentValues values) {
1177a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        // Remove the leading slash
1187a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        String table = uri.getPath().substring(1);
1197a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        long id = mMockId++;
1207a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        Uri newUri = new Uri.Builder().scheme("content").authority(AUTHORITY).path(table)
1217a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            .appendPath(Long.toString(id)).build();
1227a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        // Remember to store the _id
1237a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        values.put(ID_COLUMN, id);
1247a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        mMockStore.put(newUri.getPath(), values);
1257a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        int match = sURIMatcher.match(uri);
1267a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        if (match == UriMatcher.NO_MATCH) {
1277a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            sURIMatcher.addURI(AUTHORITY, table, TABLE);
1287a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            sURIMatcher.addURI(AUTHORITY, table + "/#", RECORD);
1297a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        }
1307a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        return newUri;
1317a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    }
1327a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank
1337a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    @Override
1347a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    public boolean onCreate() {
1357a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        return false;
1367a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    }
1377a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank
1387a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    @Override
1397a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
1407a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            String sortOrder) {
1417a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        if (selection != null || selectionArgs != null || sortOrder != null || projection == null) {
1427a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            throw new UnsupportedOperationException();
1437a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        }
1447a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        final int match = sURIMatcher.match(uri(uri));
1457a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        ArrayList<ContentValues> valuesList = new ArrayList<ContentValues>();
1467a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        switch(match) {
1477a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            case TABLE:
1487a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                Set<Entry<String, ContentValues>> entrySet = mMockStore.entrySet();
1497a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                String prefix = uri.getPath() + "/";
1507a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                for (Entry<String, ContentValues> entry: entrySet) {
1517a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                    if (entry.getKey().startsWith(prefix)) {
1527a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                        valuesList.add(entry.getValue());
1537a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                    }
1547a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                }
1557a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                break;
1567a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            case RECORD:
1577a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                ContentValues values = mMockStore.get(uri.getPath());
1587a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                if (values != null) {
1597a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                    valuesList.add(values);
1607a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                }
1617a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                break;
1627a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            default:
1637a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                throw new IllegalArgumentException("Unknown URI " + uri);
1647a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        }
1657a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        MatrixCursor cursor = new MatrixCursor(projection, 1);
1667a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        for (ContentValues cv: valuesList) {
1677a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            Object[] rowValues = new Object[projection.length];
1687a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            int i = 0;
1697a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            for (String column: projection) {
1707a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                rowValues[i++] = cv.get(column);
1717a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            }
1727a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            cursor.addRow(rowValues);
1737a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        }
1747a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        return cursor;
1757a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    }
1767a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank
1777a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    @Override
1787a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    public int update(Uri uri, ContentValues newValues, String selection, String[] selectionArgs) {
1797a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        if (selection != null || selectionArgs != null) {
1807a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            throw new UnsupportedOperationException();
1817a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        }
1827a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        final int match = sURIMatcher.match(uri(uri));
1837a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        ArrayList<ContentValues> updateValuesList = new ArrayList<ContentValues>();
1847a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        String path = uri.getPath();
1857a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        switch(match) {
1867a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            case TABLE:
1877a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                Set<Entry<String, ContentValues>> entrySet = mMockStore.entrySet();
1887a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                String prefix = path + "/";
1897a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                for (Entry<String, ContentValues> entry: entrySet) {
1907a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                    if (entry.getKey().startsWith(prefix)) {
1917a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                        updateValuesList.add(entry.getValue());
1927a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                    }
1937a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                }
1947a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                break;
1957a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            case RECORD:
1967a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                ContentValues cv = mMockStore.get(path);
1977a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                if (cv != null) {
1987a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                    updateValuesList.add(cv);
1997a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                }
2007a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                break;
2017a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            default:
2027a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                throw new IllegalArgumentException("Unknown URI " + uri);
2037a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        }
2047a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        Set<Entry<String, Object>> newValuesSet = newValues.valueSet();
2057a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        for (Entry<String, Object> entry: newValuesSet) {
2067a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            String key = entry.getKey();
2077a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            Object value = entry.getValue();
2087a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            for (ContentValues targetValues: updateValuesList) {
2097a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                if (value instanceof Integer) {
2107a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                    targetValues.put(key, (Integer)value);
2117a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                } else if (value instanceof Long) {
2127a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                    targetValues.put(key, (Long)value);
2137a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                } else if (value instanceof String) {
2147a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                    targetValues.put(key, (String)value);
2157a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                } else if (value instanceof Boolean) {
2167a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                    targetValues.put(key, (Boolean)value);
2177a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                } else {
2187a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                    throw new IllegalArgumentException();
2197a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank                }
2207a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            }
2217a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        }
2227a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        for (ContentValues targetValues: updateValuesList) {
2237a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank            mMockStore.put(path + "/" + targetValues.getAsLong(ID_COLUMN), targetValues);
2247a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        }
2257a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank        return updateValuesList.size();
2267a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank    }
2277a882dc9d2ecded51759ad2b8a5f40f0a4545c18Marc Blank}
228