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