MockContext.java revision e70f61b1160e953e5e4d18d30a463fa9ba821779
1/* 2 * Copyright (C) 2007 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 17package android.test.mock; 18 19import android.content.ComponentName; 20import android.content.ContentResolver; 21import android.content.Context; 22import android.content.Intent; 23import android.content.IntentFilter; 24import android.content.BroadcastReceiver; 25import android.content.IntentSender; 26import android.content.ServiceConnection; 27import android.content.SharedPreferences; 28import android.content.pm.ApplicationInfo; 29import android.content.pm.PackageManager; 30import android.content.res.AssetManager; 31import android.content.res.Resources; 32import android.database.sqlite.SQLiteDatabase; 33import android.graphics.Bitmap; 34import android.graphics.drawable.Drawable; 35import android.net.Uri; 36import android.os.Bundle; 37import android.os.Handler; 38import android.os.Looper; 39 40import java.io.File; 41import java.io.FileInputStream; 42import java.io.FileNotFoundException; 43import java.io.FileOutputStream; 44import java.io.IOException; 45import java.io.InputStream; 46 47/** 48 * A mock {@link android.content.Context} class. All methods are non-functional and throw 49 * {@link java.lang.UnsupportedOperationException}. You can use this to inject other dependencies, 50 * mocks, or monitors into the classes you are testing. 51 */ 52public class MockContext extends Context { 53 54 @Override 55 public AssetManager getAssets() { 56 throw new UnsupportedOperationException(); 57 } 58 59 @Override 60 public Resources getResources() { 61 throw new UnsupportedOperationException(); 62 } 63 64 @Override 65 public PackageManager getPackageManager() { 66 throw new UnsupportedOperationException(); 67 } 68 69 @Override 70 public ContentResolver getContentResolver() { 71 throw new UnsupportedOperationException(); 72 } 73 74 @Override 75 public Looper getMainLooper() { 76 throw new UnsupportedOperationException(); 77 } 78 79 @Override 80 public Context getApplicationContext() { 81 throw new UnsupportedOperationException(); 82 } 83 84 @Override 85 public void setTheme(int resid) { 86 throw new UnsupportedOperationException(); 87 } 88 89 @Override 90 public Resources.Theme getTheme() { 91 throw new UnsupportedOperationException(); 92 } 93 94 @Override 95 public ClassLoader getClassLoader() { 96 throw new UnsupportedOperationException(); 97 } 98 99 @Override 100 public String getPackageName() { 101 throw new UnsupportedOperationException(); 102 } 103 104 @Override 105 public ApplicationInfo getApplicationInfo() { 106 throw new UnsupportedOperationException(); 107 } 108 109 @Override 110 public String getPackageResourcePath() { 111 throw new UnsupportedOperationException(); 112 } 113 114 /** @hide */ 115 @Override 116 public File getSharedPrefsFile(String name) { 117 throw new UnsupportedOperationException(); 118 } 119 120 @Override 121 public String getPackageCodePath() { 122 throw new UnsupportedOperationException(); 123 } 124 125 @Override 126 public SharedPreferences getSharedPreferences(String name, int mode) { 127 throw new UnsupportedOperationException(); 128 } 129 130 @Override 131 public FileInputStream openFileInput(String name) throws FileNotFoundException { 132 throw new UnsupportedOperationException(); 133 } 134 135 @Override 136 public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException { 137 throw new UnsupportedOperationException(); 138 } 139 140 @Override 141 public boolean deleteFile(String name) { 142 throw new UnsupportedOperationException(); 143 } 144 145 @Override 146 public File getFileStreamPath(String name) { 147 throw new UnsupportedOperationException(); 148 } 149 150 @Override 151 public String[] fileList() { 152 throw new UnsupportedOperationException(); 153 } 154 155 @Override 156 public File getFilesDir() { 157 throw new UnsupportedOperationException(); 158 } 159 160 @Override 161 public File getExternalFilesDir(String type) { 162 throw new UnsupportedOperationException(); 163 } 164 165 @Override 166 public File getCacheDir() { 167 throw new UnsupportedOperationException(); 168 } 169 170 @Override 171 public File getExternalCacheDir() { 172 throw new UnsupportedOperationException(); 173 } 174 175 @Override 176 public File getDir(String name, int mode) { 177 throw new UnsupportedOperationException(); 178 } 179 180 @Override 181 public SQLiteDatabase openOrCreateDatabase(String file, int mode, 182 SQLiteDatabase.CursorFactory factory) { 183 throw new UnsupportedOperationException(); 184 } 185 186 @Override 187 public File getDatabasePath(String name) { 188 throw new UnsupportedOperationException(); 189 } 190 191 @Override 192 public String[] databaseList() { 193 throw new UnsupportedOperationException(); 194 } 195 196 @Override 197 public boolean deleteDatabase(String name) { 198 throw new UnsupportedOperationException(); 199 } 200 201 @Override 202 public Drawable getWallpaper() { 203 throw new UnsupportedOperationException(); 204 } 205 206 @Override 207 public Drawable peekWallpaper() { 208 throw new UnsupportedOperationException(); 209 } 210 211 @Override 212 public int getWallpaperDesiredMinimumWidth() { 213 throw new UnsupportedOperationException(); 214 } 215 216 @Override 217 public int getWallpaperDesiredMinimumHeight() { 218 throw new UnsupportedOperationException(); 219 } 220 221 @Override 222 public void setWallpaper(Bitmap bitmap) throws IOException { 223 throw new UnsupportedOperationException(); 224 } 225 226 @Override 227 public void setWallpaper(InputStream data) throws IOException { 228 throw new UnsupportedOperationException(); 229 } 230 231 @Override 232 public void clearWallpaper() { 233 throw new UnsupportedOperationException(); 234 } 235 236 @Override 237 public void startActivity(Intent intent) { 238 throw new UnsupportedOperationException(); 239 } 240 241 @Override 242 public void startIntentSender(IntentSender intent, 243 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) 244 throws IntentSender.SendIntentException { 245 throw new UnsupportedOperationException(); 246 } 247 248 @Override 249 public void sendBroadcast(Intent intent) { 250 throw new UnsupportedOperationException(); 251 } 252 253 @Override 254 public void sendBroadcast(Intent intent, String receiverPermission) { 255 throw new UnsupportedOperationException(); 256 } 257 258 @Override 259 public void sendOrderedBroadcast(Intent intent, 260 String receiverPermission) { 261 throw new UnsupportedOperationException(); 262 } 263 264 @Override 265 public void sendOrderedBroadcast(Intent intent, String receiverPermission, 266 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, 267 Bundle initialExtras) { 268 throw new UnsupportedOperationException(); 269 } 270 271 @Override 272 public void sendStickyBroadcast(Intent intent) { 273 throw new UnsupportedOperationException(); 274 } 275 276 @Override 277 public void sendStickyOrderedBroadcast(Intent intent, 278 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, 279 Bundle initialExtras) { 280 throw new UnsupportedOperationException(); 281 } 282 283 @Override 284 public void removeStickyBroadcast(Intent intent) { 285 throw new UnsupportedOperationException(); 286 } 287 288 @Override 289 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) { 290 throw new UnsupportedOperationException(); 291 } 292 293 @Override 294 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, 295 String broadcastPermission, Handler scheduler) { 296 throw new UnsupportedOperationException(); 297 } 298 299 @Override 300 public void unregisterReceiver(BroadcastReceiver receiver) { 301 throw new UnsupportedOperationException(); 302 } 303 304 @Override 305 public ComponentName startService(Intent service) { 306 throw new UnsupportedOperationException(); 307 } 308 309 @Override 310 public boolean stopService(Intent service) { 311 throw new UnsupportedOperationException(); 312 } 313 314 @Override 315 public boolean bindService(Intent service, ServiceConnection conn, int flags) { 316 throw new UnsupportedOperationException(); 317 } 318 319 @Override 320 public void unbindService(ServiceConnection conn) { 321 throw new UnsupportedOperationException(); 322 } 323 324 @Override 325 public boolean startInstrumentation(ComponentName className, 326 String profileFile, Bundle arguments) { 327 throw new UnsupportedOperationException(); 328 } 329 330 @Override 331 public Object getSystemService(String name) { 332 throw new UnsupportedOperationException(); 333 } 334 335 @Override 336 public int checkPermission(String permission, int pid, int uid) { 337 throw new UnsupportedOperationException(); 338 } 339 340 @Override 341 public int checkCallingPermission(String permission) { 342 throw new UnsupportedOperationException(); 343 } 344 345 @Override 346 public int checkCallingOrSelfPermission(String permission) { 347 throw new UnsupportedOperationException(); 348 } 349 350 @Override 351 public void enforcePermission( 352 String permission, int pid, int uid, String message) { 353 throw new UnsupportedOperationException(); 354 } 355 356 @Override 357 public void enforceCallingPermission(String permission, String message) { 358 throw new UnsupportedOperationException(); 359 } 360 361 @Override 362 public void enforceCallingOrSelfPermission(String permission, String message) { 363 throw new UnsupportedOperationException(); 364 } 365 366 @Override 367 public void grantUriPermission(String toPackage, Uri uri, int modeFlags) { 368 throw new UnsupportedOperationException(); 369 } 370 371 @Override 372 public void revokeUriPermission(Uri uri, int modeFlags) { 373 throw new UnsupportedOperationException(); 374 } 375 376 @Override 377 public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) { 378 throw new UnsupportedOperationException(); 379 } 380 381 @Override 382 public int checkCallingUriPermission(Uri uri, int modeFlags) { 383 throw new UnsupportedOperationException(); 384 } 385 386 @Override 387 public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) { 388 throw new UnsupportedOperationException(); 389 } 390 391 @Override 392 public int checkUriPermission(Uri uri, String readPermission, 393 String writePermission, int pid, int uid, int modeFlags) { 394 throw new UnsupportedOperationException(); 395 } 396 397 @Override 398 public void enforceUriPermission( 399 Uri uri, int pid, int uid, int modeFlags, String message) { 400 throw new UnsupportedOperationException(); 401 } 402 403 @Override 404 public void enforceCallingUriPermission( 405 Uri uri, int modeFlags, String message) { 406 throw new UnsupportedOperationException(); 407 } 408 409 @Override 410 public void enforceCallingOrSelfUriPermission( 411 Uri uri, int modeFlags, String message) { 412 throw new UnsupportedOperationException(); 413 } 414 415 public void enforceUriPermission( 416 Uri uri, String readPermission, String writePermission, 417 int pid, int uid, int modeFlags, String message) { 418 throw new UnsupportedOperationException(); 419 } 420 421 @Override 422 public Context createPackageContext(String packageName, int flags) 423 throws PackageManager.NameNotFoundException { 424 throw new UnsupportedOperationException(); 425 } 426 427 @Override 428 public boolean isRestricted() { 429 throw new UnsupportedOperationException(); 430 } 431} 432