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