1 /* 2 * Copyright (C) 2016 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.tests; 17 18 import com.android.contacts.model.account.AccountType; 19 import com.android.contacts.util.DeviceLocalAccountTypeFactory; 20 21 import java.util.HashMap; 22 import java.util.Map; 23 24 public class FakeDeviceAccountTypeFactory implements DeviceLocalAccountTypeFactory { 25 26 private final Map<String, AccountType> mDeviceAccountTypes = new HashMap<>(); 27 private final Map<String, AccountType> mSimAccountTypes = new HashMap<>(); 28 29 @Override 30 public int classifyAccount(String accountType) { 31 if (mDeviceAccountTypes.containsKey(accountType)) { 32 return TYPE_DEVICE; 33 } else if (mSimAccountTypes.containsKey(accountType)) { 34 return TYPE_SIM; 35 } else { 36 return TYPE_OTHER; 37 } 38 } 39 40 @Override 41 public AccountType getAccountType(String accountType) { 42 final AccountType type = mDeviceAccountTypes.get(accountType); 43 return type == null ? mSimAccountTypes.get(accountType) : type; 44 } 45 46 public FakeDeviceAccountTypeFactory withSimTypes(String... types) { 47 for (String type : types) { 48 mSimAccountTypes.put(type, new FakeAccountType(type)); 49 } 50 return this; 51 } 52 53 public FakeDeviceAccountTypeFactory withSimTypes(AccountType... types) { 54 for (AccountType type : types) { 55 mSimAccountTypes.put(type.accountType, type); 56 } 57 return this; 58 } 59 60 public FakeDeviceAccountTypeFactory withDeviceTypes(String... types) { 61 for (String type : types) { 62 mDeviceAccountTypes.put(type, new FakeAccountType(type)); 63 } 64 return this; 65 } 66 67 public FakeDeviceAccountTypeFactory withDeviceTypes(AccountType... types) { 68 for (AccountType type : types) { 69 mDeviceAccountTypes.put(type.accountType, type); 70 } 71 return this; 72 } 73 } 74