1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.vcard.tests.testutils;
17
18import android.content.ContentProviderOperation;
19import android.content.ContentProviderResult;
20import android.content.ContentValues;
21import android.provider.ContactsContract.RawContacts;
22import android.test.AndroidTestCase;
23import android.test.mock.MockContentResolver;
24
25import java.util.ArrayList;
26
27public class ImportTestResolver extends MockContentResolver {
28    private final ImportTestProvider mProvider;
29
30    public ImportTestResolver(AndroidTestCase androidTestCase) {
31        mProvider = new ImportTestProvider();
32    }
33
34    @Override
35    public ContentProviderResult[] applyBatch(String authority,
36            ArrayList<ContentProviderOperation> operations) {
37        equalsString(authority, RawContacts.CONTENT_URI.toString());
38        return mProvider.applyBatch(operations);
39    }
40
41    public void addExpectedContentValues(ContentValues expectedContentValues) {
42        mProvider.addExpectedContentValues(expectedContentValues);
43    }
44
45    public void verify() {
46        mProvider.verify();
47    }
48
49    private static boolean equalsString(String a, String b) {
50        if (a == null || a.length() == 0) {
51            return b == null || b.length() == 0;
52        } else {
53            return a.equals(b);
54        }
55    }
56}
57