Yorke Lee | 2644d94 | 2013-10-28 11:05:43 -0700 | [diff] [blame] | 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 | */ |
Gary Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 16 | package com.android.contacts.test.mocks; |
Yorke Lee | 2644d94 | 2013-10-28 11:05:43 -0700 | [diff] [blame] | 17 | |
Wenyi Wang | 56c8a0c | 2016-09-30 11:11:10 -0700 | [diff] [blame] | 18 | import android.accounts.Account; |
| 19 | |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 20 | import com.android.contacts.model.AccountTypeManager; |
Marcus Hagerott | 75895e7 | 2016-12-12 17:21:57 -0800 | [diff] [blame] | 21 | import com.android.contacts.model.account.AccountInfo; |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 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; |
Yorke Lee | 2644d94 | 2013-10-28 11:05:43 -0700 | [diff] [blame] | 26 | import com.google.common.base.Objects; |
Marcus Hagerott | 67a0639 | 2016-10-13 15:16:58 -0700 | [diff] [blame] | 27 | import com.google.common.base.Predicate; |
| 28 | import com.google.common.collect.Collections2; |
Yorke Lee | 2644d94 | 2013-10-28 11:05:43 -0700 | [diff] [blame] | 29 | import com.google.common.collect.Lists; |
Marcus Hagerott | 04be88c | 2016-12-07 09:55:03 -0800 | [diff] [blame] | 30 | import com.google.common.util.concurrent.Futures; |
| 31 | import com.google.common.util.concurrent.ListenableFuture; |
Yorke Lee | 2644d94 | 2013-10-28 11:05:43 -0700 | [diff] [blame] | 32 | |
| 33 | import java.util.Arrays; |
| 34 | import java.util.List; |
Yorke Lee | 2644d94 | 2013-10-28 11:05:43 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * A mock {@link AccountTypeManager} class. |
| 38 | */ |
| 39 | public class MockAccountTypeManager extends AccountTypeManager { |
| 40 | |
| 41 | public AccountType[] mTypes; |
| 42 | public AccountWithDataSet[] mAccounts; |
| 43 | |
| 44 | public MockAccountTypeManager(AccountType[] types, AccountWithDataSet[] accounts) { |
| 45 | this.mTypes = types; |
| 46 | this.mAccounts = accounts; |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public AccountType getAccountType(AccountTypeWithDataSet accountTypeWithDataSet) { |
Zheng Fu | 7958e58 | 2014-08-29 16:02:44 -0700 | [diff] [blame] | 51 | // Add fallback accountType to mimic the behavior of AccountTypeManagerImpl |
| 52 | AccountType mFallbackAccountType = new BaseAccountType() { |
| 53 | @Override |
| 54 | public boolean areContactsWritable() { |
| 55 | return false; |
| 56 | } |
| 57 | }; |
| 58 | mFallbackAccountType.accountType = "fallback"; |
Yorke Lee | 2644d94 | 2013-10-28 11:05:43 -0700 | [diff] [blame] | 59 | for (AccountType type : mTypes) { |
| 60 | if (Objects.equal(accountTypeWithDataSet.accountType, type.accountType) |
| 61 | && Objects.equal(accountTypeWithDataSet.dataSet, type.dataSet)) { |
| 62 | return type; |
| 63 | } |
| 64 | } |
Zheng Fu | 7958e58 | 2014-08-29 16:02:44 -0700 | [diff] [blame] | 65 | return mFallbackAccountType; |
Yorke Lee | 2644d94 | 2013-10-28 11:05:43 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public List<AccountWithDataSet> getAccounts(boolean writableOnly) { |
| 70 | return Arrays.asList(mAccounts); |
| 71 | } |
| 72 | |
| 73 | @Override |
Marcus Hagerott | 75895e7 | 2016-12-12 17:21:57 -0800 | [diff] [blame] | 74 | public ListenableFuture<List<AccountInfo>> getAccountsAsync() { |
| 75 | throw new UnsupportedOperationException("not implemented"); |
Marcus Hagerott | 67a0639 | 2016-10-13 15:16:58 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
Marcus Hagerott | 75895e7 | 2016-12-12 17:21:57 -0800 | [diff] [blame] | 79 | public ListenableFuture<List<AccountInfo>> filterAccountsAsync(Predicate<AccountInfo> filter) { |
| 80 | throw new UnsupportedOperationException("not implemented"); |
Marcus Hagerott | 04be88c | 2016-12-07 09:55:03 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | @Override |
Marcus Hagerott | 75895e7 | 2016-12-12 17:21:57 -0800 | [diff] [blame] | 84 | public AccountInfo getAccountInfoForAccount(AccountWithDataSet account) { |
| 85 | throw new UnsupportedOperationException("not implemented"); |
Marcus Hagerott | e7a71cb | 2016-12-09 16:26:14 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | @Override |
Yorke Lee | 2644d94 | 2013-10-28 11:05:43 -0700 | [diff] [blame] | 89 | public List<AccountWithDataSet> getGroupWritableAccounts() { |
| 90 | return Arrays.asList(mAccounts); |
| 91 | } |
| 92 | |
| 93 | @Override |
Wenyi Wang | 56c8a0c | 2016-09-30 11:11:10 -0700 | [diff] [blame] | 94 | public Account getDefaultGoogleAccount() { |
| 95 | return null; |
| 96 | } |
Yorke Lee | 2644d94 | 2013-10-28 11:05:43 -0700 | [diff] [blame] | 97 | } |