1 /* 2 * Copyright (C) 2008 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 android.test.mock; 18 19 import android.content.res.AssetManager; 20 import android.content.res.Resources; 21 import android.content.res.Configuration; 22 import android.content.res.TypedArray; 23 import android.content.res.ColorStateList; 24 import android.content.res.XmlResourceParser; 25 import android.content.res.AssetFileDescriptor; 26 import android.util.DisplayMetrics; 27 import android.util.TypedValue; 28 import android.util.AttributeSet; 29 import android.graphics.drawable.Drawable; 30 import android.graphics.Movie; 31 32 import java.io.InputStream; 33 34 /** 35 * A mock {@link android.content.res.Resources} class. All methods are non-functional and throw 36 * {@link java.lang.UnsupportedOperationException}. Override it to provide the operations that you 37 * need. 38 */ 39 public class MockResources extends Resources { 40 MockResources()41 public MockResources() { 42 super(new AssetManager(), null, null); 43 } 44 45 @Override updateConfiguration(Configuration config, DisplayMetrics metrics)46 public void updateConfiguration(Configuration config, DisplayMetrics metrics) { 47 // this method is called from the constructor, so we just do nothing 48 } 49 50 @Override getText(int id)51 public CharSequence getText(int id) throws NotFoundException { 52 throw new UnsupportedOperationException("mock object, not implemented"); 53 } 54 55 @Override getQuantityText(int id, int quantity)56 public CharSequence getQuantityText(int id, int quantity) throws NotFoundException { 57 throw new UnsupportedOperationException("mock object, not implemented"); 58 } 59 60 @Override getString(int id)61 public String getString(int id) throws NotFoundException { 62 throw new UnsupportedOperationException("mock object, not implemented"); 63 } 64 65 @Override getString(int id, Object... formatArgs)66 public String getString(int id, Object... formatArgs) throws NotFoundException { 67 throw new UnsupportedOperationException("mock object, not implemented"); 68 } 69 70 @Override getQuantityString(int id, int quantity, Object... formatArgs)71 public String getQuantityString(int id, int quantity, Object... formatArgs) 72 throws NotFoundException { 73 throw new UnsupportedOperationException("mock object, not implemented"); 74 } 75 76 @Override getQuantityString(int id, int quantity)77 public String getQuantityString(int id, int quantity) throws NotFoundException { 78 throw new UnsupportedOperationException("mock object, not implemented"); 79 } 80 81 @Override getText(int id, CharSequence def)82 public CharSequence getText(int id, CharSequence def) { 83 throw new UnsupportedOperationException("mock object, not implemented"); 84 } 85 86 @Override getTextArray(int id)87 public CharSequence[] getTextArray(int id) throws NotFoundException { 88 throw new UnsupportedOperationException("mock object, not implemented"); 89 } 90 91 @Override getStringArray(int id)92 public String[] getStringArray(int id) throws NotFoundException { 93 throw new UnsupportedOperationException("mock object, not implemented"); 94 } 95 96 @Override getIntArray(int id)97 public int[] getIntArray(int id) throws NotFoundException { 98 throw new UnsupportedOperationException("mock object, not implemented"); 99 } 100 101 @Override obtainTypedArray(int id)102 public TypedArray obtainTypedArray(int id) throws NotFoundException { 103 throw new UnsupportedOperationException("mock object, not implemented"); 104 } 105 106 @Override getDimension(int id)107 public float getDimension(int id) throws NotFoundException { 108 throw new UnsupportedOperationException("mock object, not implemented"); 109 } 110 111 @Override getDimensionPixelOffset(int id)112 public int getDimensionPixelOffset(int id) throws NotFoundException { 113 throw new UnsupportedOperationException("mock object, not implemented"); 114 } 115 116 @Override getDimensionPixelSize(int id)117 public int getDimensionPixelSize(int id) throws NotFoundException { 118 throw new UnsupportedOperationException("mock object, not implemented"); 119 } 120 121 @Override getDrawable(int id)122 public Drawable getDrawable(int id) throws NotFoundException { 123 throw new UnsupportedOperationException("mock object, not implemented"); 124 } 125 126 @Override getMovie(int id)127 public Movie getMovie(int id) throws NotFoundException { 128 throw new UnsupportedOperationException("mock object, not implemented"); 129 } 130 131 @Override getColor(int id)132 public int getColor(int id) throws NotFoundException { 133 throw new UnsupportedOperationException("mock object, not implemented"); 134 } 135 136 @Override getColorStateList(int id)137 public ColorStateList getColorStateList(int id) throws NotFoundException { 138 throw new UnsupportedOperationException("mock object, not implemented"); 139 } 140 141 @Override getInteger(int id)142 public int getInteger(int id) throws NotFoundException { 143 throw new UnsupportedOperationException("mock object, not implemented"); 144 } 145 146 @Override getLayout(int id)147 public XmlResourceParser getLayout(int id) throws NotFoundException { 148 throw new UnsupportedOperationException("mock object, not implemented"); 149 } 150 151 @Override getAnimation(int id)152 public XmlResourceParser getAnimation(int id) throws NotFoundException { 153 throw new UnsupportedOperationException("mock object, not implemented"); 154 } 155 156 @Override getXml(int id)157 public XmlResourceParser getXml(int id) throws NotFoundException { 158 throw new UnsupportedOperationException("mock object, not implemented"); 159 } 160 161 @Override openRawResource(int id)162 public InputStream openRawResource(int id) throws NotFoundException { 163 throw new UnsupportedOperationException("mock object, not implemented"); 164 } 165 166 @Override openRawResourceFd(int id)167 public AssetFileDescriptor openRawResourceFd(int id) throws NotFoundException { 168 throw new UnsupportedOperationException("mock object, not implemented"); 169 } 170 171 @Override getValue(int id, TypedValue outValue, boolean resolveRefs)172 public void getValue(int id, TypedValue outValue, boolean resolveRefs) 173 throws NotFoundException { 174 throw new UnsupportedOperationException("mock object, not implemented"); 175 } 176 177 @Override getValue(String name, TypedValue outValue, boolean resolveRefs)178 public void getValue(String name, TypedValue outValue, boolean resolveRefs) 179 throws NotFoundException { 180 throw new UnsupportedOperationException("mock object, not implemented"); 181 } 182 183 @Override obtainAttributes(AttributeSet set, int[] attrs)184 public TypedArray obtainAttributes(AttributeSet set, int[] attrs) { 185 throw new UnsupportedOperationException("mock object, not implemented"); 186 } 187 188 @Override getDisplayMetrics()189 public DisplayMetrics getDisplayMetrics() { 190 throw new UnsupportedOperationException("mock object, not implemented"); 191 } 192 193 @Override getConfiguration()194 public Configuration getConfiguration() { 195 throw new UnsupportedOperationException("mock object, not implemented"); 196 } 197 198 @Override getIdentifier(String name, String defType, String defPackage)199 public int getIdentifier(String name, String defType, String defPackage) { 200 throw new UnsupportedOperationException("mock object, not implemented"); 201 } 202 203 @Override getResourceName(int resid)204 public String getResourceName(int resid) throws NotFoundException { 205 throw new UnsupportedOperationException("mock object, not implemented"); 206 } 207 208 @Override getResourcePackageName(int resid)209 public String getResourcePackageName(int resid) throws NotFoundException { 210 throw new UnsupportedOperationException("mock object, not implemented"); 211 } 212 213 @Override getResourceTypeName(int resid)214 public String getResourceTypeName(int resid) throws NotFoundException { 215 throw new UnsupportedOperationException("mock object, not implemented"); 216 } 217 218 @Override getResourceEntryName(int resid)219 public String getResourceEntryName(int resid) throws NotFoundException { 220 throw new UnsupportedOperationException("mock object, not implemented"); 221 } 222 } 223