• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 
17 package com.android.providers.contacts;
18 
19 import com.google.common.collect.Maps;
20 
21 import android.content.res.Resources.NotFoundException;
22 import android.test.mock.MockResources;
23 
24 import java.util.Map;
25 
26 final class ContactsMockResources extends MockResources {
27     private Map<Integer, String> mPackages = Maps.newHashMap();
28     private Map<Integer, String> mTypes = Maps.newHashMap();
29     private Map<Integer, String> mEntries = Maps.newHashMap();
30 
addResource(int resId, String packageName, String typeName, String entryName)31     public void addResource(int resId, String packageName, String typeName, String entryName) {
32         mPackages.put(resId, packageName);
33         mTypes.put(resId, typeName);
34         mEntries.put(resId, entryName);
35     }
36 
37     @Override
getResourceName(int resId)38     public String getResourceName(int resId) throws NotFoundException {
39         if (!mPackages.containsKey(resId)) {
40             throw new NotFoundException("Resource " + resId + " not found");
41         }
42         return mPackages.get(resId) + ":" + mTypes.get(resId) + "/" + mEntries.get(resId);
43     }
44 
45     @Override
getResourcePackageName(int resId)46     public String getResourcePackageName(int resId) throws NotFoundException {
47         if (!mPackages.containsKey(resId)) {
48             throw new NotFoundException("Resource " + resId + " not found");
49         }
50         return mPackages.get(resId);
51     }
52 
53     @Override
getResourceTypeName(int resId)54     public String getResourceTypeName(int resId) throws NotFoundException {
55         if (!mPackages.containsKey(resId)) {
56             throw new NotFoundException("Resource " + resId + " not found");
57         }
58         return mTypes.get(resId);
59     }
60 
61     @Override
getResourceEntryName(int resId)62     public String getResourceEntryName(int resId) throws NotFoundException {
63         if (!mPackages.containsKey(resId)) {
64             throw new NotFoundException("Resource " + resId + " not found");
65         }
66         return mEntries.get(resId);
67     }
68 }