MockAccountTypeManager.java revision 9aa9e846dec6c2958be6ce120e138e484fdba330
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 */ 16package com.android.contacts.tests.mocks; 17 18import com.android.contacts.model.AccountType; 19import com.android.contacts.model.AccountTypeManager; 20import com.google.android.collect.Maps; 21 22import android.accounts.Account; 23 24import java.util.ArrayList; 25import java.util.Arrays; 26import java.util.HashMap; 27import java.util.Map; 28 29/** 30 * A mock {@link AccountTypeManager} class. 31 */ 32public class MockAccountTypeManager extends AccountTypeManager { 33 34 private final AccountType[] mTypes; 35 private Account[] mAccounts; 36 37 public MockAccountTypeManager(AccountType[] types, Account[] accounts) { 38 this.mTypes = types; 39 this.mAccounts = accounts; 40 } 41 42 @Override 43 public AccountType getAccountType(String accountType) { 44 for (AccountType type : mTypes) { 45 if (accountType.equals(type.accountType)) { 46 return type; 47 } 48 } 49 return null; 50 } 51 52 @Override 53 public ArrayList<Account> getAccounts(boolean writableOnly) { 54 return new ArrayList<Account>(Arrays.asList(mAccounts)); 55 } 56 57 @Override 58 public Map<String, AccountType> getInvitableAccountTypes() { 59 return Maps.newHashMap(); // Always returns empty 60 } 61} 62