1 /* 2 * Copyright (C) 2010 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 package com.android.contacts.test.mocks; 17 18 import android.accounts.Account; 19 20 import com.android.contacts.model.AccountTypeManager; 21 import com.android.contacts.model.account.AccountInfo; 22 import com.android.contacts.model.account.AccountType; 23 import com.android.contacts.model.account.AccountTypeWithDataSet; 24 import com.android.contacts.model.account.AccountWithDataSet; 25 import com.android.contacts.model.account.BaseAccountType; 26 import com.google.common.base.Objects; 27 import com.google.common.base.Predicate; 28 import com.google.common.util.concurrent.ListenableFuture; 29 30 import java.util.Arrays; 31 import java.util.List; 32 33 /** 34 * A mock {@link AccountTypeManager} class. 35 */ 36 public class MockAccountTypeManager extends AccountTypeManager { 37 38 public AccountType[] mTypes; 39 public AccountWithDataSet[] mAccounts; 40 41 public MockAccountTypeManager(AccountType[] types, AccountWithDataSet[] accounts) { 42 this.mTypes = types; 43 this.mAccounts = accounts; 44 } 45 46 @Override 47 public AccountType getAccountType(AccountTypeWithDataSet accountTypeWithDataSet) { 48 // Add fallback accountType to mimic the behavior of AccountTypeManagerImpl 49 AccountType mFallbackAccountType = new BaseAccountType() { 50 @Override 51 public boolean areContactsWritable() { 52 return false; 53 } 54 }; 55 mFallbackAccountType.accountType = "fallback"; 56 for (AccountType type : mTypes) { 57 if (Objects.equal(accountTypeWithDataSet.accountType, type.accountType) 58 && Objects.equal(accountTypeWithDataSet.dataSet, type.dataSet)) { 59 return type; 60 } 61 } 62 return mFallbackAccountType; 63 } 64 65 @Override 66 public List<AccountWithDataSet> blockForWritableAccounts() { 67 return Arrays.asList(mAccounts); 68 } 69 70 @Override 71 public ListenableFuture<List<AccountInfo>> getAccountsAsync() { 72 throw new UnsupportedOperationException("not implemented"); 73 } 74 75 @Override 76 public ListenableFuture<List<AccountInfo>> filterAccountsAsync(Predicate<AccountInfo> filter) { 77 throw new UnsupportedOperationException("not implemented"); 78 } 79 80 @Override 81 public AccountInfo getAccountInfoForAccount(AccountWithDataSet account) { 82 throw new UnsupportedOperationException("not implemented"); 83 } 84 85 @Override 86 public Account getDefaultGoogleAccount() { 87 return null; 88 } 89 } 90