1/*
2 * Copyright (C) 2013 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 */
16
17package com.android.providers.contacts.testutil;
18
19import android.accounts.Account;
20import android.net.Uri;
21import android.provider.ContactsContract;
22import android.util.Log;
23
24/**
25 * Common methods used for testing.
26 */
27public class TestUtil {
28    private static String TAG = TestUtil.class.getSimpleName();
29
30    public static final Account ACCOUNT_1 = new Account("account_name_1", "account_type_1");
31    public static final Account ACCOUNT_2 = new Account("account_name_2", "account_type_2");
32
33    /**
34     * Sleep for 1ms.
35     */
36    public static void sleep() {
37        try {
38            Thread.sleep(1);
39        } catch (InterruptedException e) {
40            Log.w(TAG, "Sleep interrupted.");
41        }
42    }
43
44    public static Uri maybeAddAccountQueryParameters(Uri uri, Account account) {
45        if (account == null) {
46            return uri;
47        }
48        return uri.buildUpon()
49                .appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_NAME, account.name)
50                .appendQueryParameter(ContactsContract.RawContacts.ACCOUNT_TYPE, account.type)
51                .build();
52    }
53}
54