Home | History | Annotate | Download | only in mocks
      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.common.test.mocks;
     17 
     18 import com.android.contacts.common.model.AccountTypeManager;
     19 import com.android.contacts.common.model.account.AccountType;
     20 import com.android.contacts.common.model.account.AccountTypeWithDataSet;
     21 import com.android.contacts.common.model.account.AccountWithDataSet;
     22 import com.google.common.base.Objects;
     23 import com.google.common.collect.Lists;
     24 import com.google.common.collect.Maps;
     25 
     26 import java.util.Arrays;
     27 import java.util.List;
     28 import java.util.Map;
     29 
     30 /**
     31  * A mock {@link AccountTypeManager} class.
     32  */
     33 public class MockAccountTypeManager extends AccountTypeManager {
     34 
     35     public AccountType[] mTypes;
     36     public AccountWithDataSet[] mAccounts;
     37 
     38     public MockAccountTypeManager(AccountType[] types, AccountWithDataSet[] accounts) {
     39         this.mTypes = types;
     40         this.mAccounts = accounts;
     41     }
     42 
     43     @Override
     44     public AccountType getAccountType(AccountTypeWithDataSet accountTypeWithDataSet) {
     45         for (AccountType type : mTypes) {
     46             if (Objects.equal(accountTypeWithDataSet.accountType, type.accountType)
     47                     && Objects.equal(accountTypeWithDataSet.dataSet, type.dataSet)) {
     48                 return type;
     49             }
     50         }
     51         return null;
     52     }
     53 
     54     @Override
     55     public List<AccountWithDataSet> getAccounts(boolean writableOnly) {
     56         return Arrays.asList(mAccounts);
     57     }
     58 
     59     @Override
     60     public List<AccountWithDataSet> getGroupWritableAccounts() {
     61         return Arrays.asList(mAccounts);
     62     }
     63 
     64     @Override
     65     public Map<AccountTypeWithDataSet, AccountType> getUsableInvitableAccountTypes() {
     66         return Maps.newHashMap(); // Always returns empty
     67     }
     68 
     69     @Override
     70     public List<AccountType> getAccountTypes(boolean writableOnly) {
     71         final List<AccountType> ret = Lists.newArrayList();
     72         synchronized (this) {
     73             for (AccountType type : mTypes) {
     74                 if (!writableOnly || type.areContactsWritable()) {
     75                     ret.add(type);
     76                 }
     77             }
     78         }
     79         return ret;
     80     }
     81 }
     82