Home | History | Annotate | Download | only in testutil
      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 
     24 /**
     25  * Common methods used for testing.
     26  */
     27 public 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(RawContacts.ACCOUNT_NAME, account.name)
     50                 .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type)
     51                 .build();
     52     }
     53 
     54     public static Uri maybeAddAccountWithDataSetQueryParameters(Uri uri,
     55             String accountName, String accountType, String dataSet) {
     56         if (accountName == null && accountType == null) {
     57             return uri;
     58         }
     59         return uri.buildUpon()
     60                 .appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName)
     61                 .appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType)
     62                 .appendQueryParameter(RawContacts.DATA_SET, dataSet)
     63                 .build();
     64     }
     65 }
     66