blob: 956f775b4d4c2583b29a5c72b07941bd75a77288 [file] [log] [blame]
Yorke Lee2644d942013-10-28 11:05:43 -07001/*
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 Mai0a49afa2016-12-05 15:53:58 -080016package com.android.contacts.test.mocks;
Yorke Lee2644d942013-10-28 11:05:43 -070017
Wenyi Wang56c8a0c2016-09-30 11:11:10 -070018import android.accounts.Account;
19
Gary Mai69c182a2016-12-05 13:07:03 -080020import com.android.contacts.model.AccountTypeManager;
Marcus Hagerott75895e72016-12-12 17:21:57 -080021import com.android.contacts.model.account.AccountInfo;
Gary Mai69c182a2016-12-05 13:07:03 -080022import com.android.contacts.model.account.AccountType;
23import com.android.contacts.model.account.AccountTypeWithDataSet;
24import com.android.contacts.model.account.AccountWithDataSet;
25import com.android.contacts.model.account.BaseAccountType;
Yorke Lee2644d942013-10-28 11:05:43 -070026import com.google.common.base.Objects;
Marcus Hagerott67a06392016-10-13 15:16:58 -070027import com.google.common.base.Predicate;
28import com.google.common.collect.Collections2;
Yorke Lee2644d942013-10-28 11:05:43 -070029import com.google.common.collect.Lists;
Marcus Hagerott04be88c2016-12-07 09:55:03 -080030import com.google.common.util.concurrent.Futures;
31import com.google.common.util.concurrent.ListenableFuture;
Yorke Lee2644d942013-10-28 11:05:43 -070032
33import java.util.Arrays;
34import java.util.List;
Yorke Lee2644d942013-10-28 11:05:43 -070035
36/**
37 * A mock {@link AccountTypeManager} class.
38 */
39public 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 Fu7958e582014-08-29 16:02:44 -070051 // 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 Lee2644d942013-10-28 11:05:43 -070059 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 Fu7958e582014-08-29 16:02:44 -070065 return mFallbackAccountType;
Yorke Lee2644d942013-10-28 11:05:43 -070066 }
67
68 @Override
69 public List<AccountWithDataSet> getAccounts(boolean writableOnly) {
70 return Arrays.asList(mAccounts);
71 }
72
73 @Override
Marcus Hagerott75895e72016-12-12 17:21:57 -080074 public ListenableFuture<List<AccountInfo>> getAccountsAsync() {
75 throw new UnsupportedOperationException("not implemented");
Marcus Hagerott67a06392016-10-13 15:16:58 -070076 }
77
78 @Override
Marcus Hagerott75895e72016-12-12 17:21:57 -080079 public ListenableFuture<List<AccountInfo>> filterAccountsAsync(Predicate<AccountInfo> filter) {
80 throw new UnsupportedOperationException("not implemented");
Marcus Hagerott04be88c2016-12-07 09:55:03 -080081 }
82
83 @Override
Marcus Hagerott75895e72016-12-12 17:21:57 -080084 public AccountInfo getAccountInfoForAccount(AccountWithDataSet account) {
85 throw new UnsupportedOperationException("not implemented");
Marcus Hagerotte7a71cb2016-12-09 16:26:14 -080086 }
87
88 @Override
Yorke Lee2644d942013-10-28 11:05:43 -070089 public List<AccountWithDataSet> getGroupWritableAccounts() {
90 return Arrays.asList(mAccounts);
91 }
92
93 @Override
Wenyi Wang56c8a0c2016-09-30 11:11:10 -070094 public Account getDefaultGoogleAccount() {
95 return null;
96 }
Yorke Lee2644d942013-10-28 11:05:43 -070097}