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