| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 17 | package android.test.mock; |
| 18 | |
| 19 | import android.content.ComponentName; |
| 20 | import android.content.ContentResolver; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.content.IntentFilter; |
| 24 | import android.content.BroadcastReceiver; |
| Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 25 | import android.content.IntentSender; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.content.ServiceConnection; |
| 27 | import android.content.SharedPreferences; |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 28 | import android.content.pm.ApplicationInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.content.pm.PackageManager; |
| 30 | import android.content.res.AssetManager; |
| 31 | import android.content.res.Resources; |
| Vasu Nori | 74f170f | 2010-06-01 18:06:18 -0700 | [diff] [blame] | 32 | import android.database.DatabaseErrorHandler; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.database.sqlite.SQLiteDatabase; |
| 34 | import android.graphics.Bitmap; |
| 35 | import android.graphics.drawable.Drawable; |
| 36 | import android.net.Uri; |
| 37 | import android.os.Bundle; |
| 38 | import android.os.Handler; |
| 39 | import android.os.Looper; |
| 40 | |
| 41 | import java.io.File; |
| 42 | import java.io.FileInputStream; |
| 43 | import java.io.FileNotFoundException; |
| 44 | import java.io.FileOutputStream; |
| 45 | import java.io.IOException; |
| 46 | import 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 | */ |
| 53 | public 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 |
| Dianne Hackborn | 5c1e00b | 2009-06-18 17:10:57 -0700 | [diff] [blame] | 106 | public ApplicationInfo getApplicationInfo() { |
| 107 | throw new UnsupportedOperationException(); |
| 108 | } |
| 109 | |
| 110 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | public String getPackageResourcePath() { |
| 112 | throw new UnsupportedOperationException(); |
| 113 | } |
| 114 | |
| Dianne Hackborn | 7f20543 | 2009-07-28 00:13:47 -0700 | [diff] [blame] | 115 | /** @hide */ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | @Override |
| Joe Onorato | 23ecae3 | 2009-06-10 17:07:15 -0700 | [diff] [blame] | 117 | public File getSharedPrefsFile(String name) { |
| 118 | throw new UnsupportedOperationException(); |
| 119 | } |
| 120 | |
| 121 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 162 | public File getExternalFilesDir(String type) { |
| 163 | throw new UnsupportedOperationException(); |
| 164 | } |
| 165 | |
| 166 | @Override |
| Dianne Hackborn | 805fd7e | 2011-01-16 18:30:29 -0800 | [diff] [blame] | 167 | public File getObbDir() { |
| 168 | throw new UnsupportedOperationException(); |
| 169 | } |
| 170 | |
| 171 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | public File getCacheDir() { |
| 173 | throw new UnsupportedOperationException(); |
| 174 | } |
| 175 | |
| 176 | @Override |
| Dianne Hackborn | e83cefce | 2010-02-04 17:38:14 -0800 | [diff] [blame] | 177 | public File getExternalCacheDir() { |
| 178 | throw new UnsupportedOperationException(); |
| 179 | } |
| 180 | |
| 181 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | public File getDir(String name, int mode) { |
| 183 | throw new UnsupportedOperationException(); |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public SQLiteDatabase openOrCreateDatabase(String file, int mode, |
| 188 | SQLiteDatabase.CursorFactory factory) { |
| 189 | throw new UnsupportedOperationException(); |
| 190 | } |
| 191 | |
| 192 | @Override |
| Vasu Nori | 74f170f | 2010-06-01 18:06:18 -0700 | [diff] [blame] | 193 | public SQLiteDatabase openOrCreateDatabase(String file, int mode, |
| 194 | SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler) { |
| 195 | throw new UnsupportedOperationException(); |
| 196 | } |
| 197 | |
| 198 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | public File getDatabasePath(String name) { |
| 200 | throw new UnsupportedOperationException(); |
| 201 | } |
| 202 | |
| 203 | @Override |
| 204 | public String[] databaseList() { |
| 205 | throw new UnsupportedOperationException(); |
| 206 | } |
| 207 | |
| 208 | @Override |
| 209 | public boolean deleteDatabase(String name) { |
| 210 | throw new UnsupportedOperationException(); |
| 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public Drawable getWallpaper() { |
| 215 | throw new UnsupportedOperationException(); |
| 216 | } |
| 217 | |
| 218 | @Override |
| 219 | public Drawable peekWallpaper() { |
| 220 | throw new UnsupportedOperationException(); |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public int getWallpaperDesiredMinimumWidth() { |
| 225 | throw new UnsupportedOperationException(); |
| 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public int getWallpaperDesiredMinimumHeight() { |
| 230 | throw new UnsupportedOperationException(); |
| 231 | } |
| 232 | |
| 233 | @Override |
| 234 | public void setWallpaper(Bitmap bitmap) throws IOException { |
| 235 | throw new UnsupportedOperationException(); |
| 236 | } |
| 237 | |
| 238 | @Override |
| 239 | public void setWallpaper(InputStream data) throws IOException { |
| 240 | throw new UnsupportedOperationException(); |
| 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public void clearWallpaper() { |
| 245 | throw new UnsupportedOperationException(); |
| 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public void startActivity(Intent intent) { |
| 250 | throw new UnsupportedOperationException(); |
| 251 | } |
| 252 | |
| 253 | @Override |
| Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 254 | public void startActivity(Intent intent, Bundle options) { |
| 255 | startActivity(intent); |
| 256 | } |
| 257 | |
| 258 | @Override |
| Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 259 | public void startActivities(Intent[] intents) { |
| 260 | throw new UnsupportedOperationException(); |
| 261 | } |
| 262 | |
| 263 | @Override |
| Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 264 | public void startActivities(Intent[] intents, Bundle options) { |
| 265 | startActivities(intents); |
| 266 | } |
| 267 | |
| 268 | @Override |
| Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 269 | public void startIntentSender(IntentSender intent, |
| 270 | Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) |
| 271 | throws IntentSender.SendIntentException { |
| 272 | throw new UnsupportedOperationException(); |
| 273 | } |
| Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 274 | |
| 275 | @Override |
| 276 | public void startIntentSender(IntentSender intent, |
| 277 | Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, |
| 278 | Bundle options) throws IntentSender.SendIntentException { |
| 279 | startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags); |
| 280 | } |
| Dianne Hackborn | fa82f22 | 2009-09-17 15:14:12 -0700 | [diff] [blame] | 281 | |
| 282 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | public void sendBroadcast(Intent intent) { |
| 284 | throw new UnsupportedOperationException(); |
| 285 | } |
| 286 | |
| Amith Yamasani | 67cf7d3 | 2012-02-16 14:31:23 -0800 | [diff] [blame] | 287 | /** @hide */ |
| 288 | @Override |
| 289 | public void sendBroadcast(Intent intent, int userId) { |
| 290 | throw new UnsupportedOperationException(); |
| 291 | } |
| 292 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | @Override |
| 294 | public void sendBroadcast(Intent intent, String receiverPermission) { |
| 295 | throw new UnsupportedOperationException(); |
| 296 | } |
| 297 | |
| 298 | @Override |
| 299 | public void sendOrderedBroadcast(Intent intent, |
| 300 | String receiverPermission) { |
| 301 | throw new UnsupportedOperationException(); |
| 302 | } |
| 303 | |
| 304 | @Override |
| 305 | public void sendOrderedBroadcast(Intent intent, String receiverPermission, |
| 306 | BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, |
| 307 | Bundle initialExtras) { |
| 308 | throw new UnsupportedOperationException(); |
| 309 | } |
| 310 | |
| 311 | @Override |
| 312 | public void sendStickyBroadcast(Intent intent) { |
| 313 | throw new UnsupportedOperationException(); |
| 314 | } |
| 315 | |
| 316 | @Override |
| Dianne Hackborn | efa199f | 2009-09-19 12:03:15 -0700 | [diff] [blame] | 317 | public void sendStickyOrderedBroadcast(Intent intent, |
| 318 | BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, |
| 319 | Bundle initialExtras) { |
| 320 | throw new UnsupportedOperationException(); |
| 321 | } |
| 322 | |
| 323 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | public void removeStickyBroadcast(Intent intent) { |
| 325 | throw new UnsupportedOperationException(); |
| 326 | } |
| 327 | |
| 328 | @Override |
| 329 | public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) { |
| 330 | throw new UnsupportedOperationException(); |
| 331 | } |
| 332 | |
| 333 | @Override |
| 334 | public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, |
| 335 | String broadcastPermission, Handler scheduler) { |
| 336 | throw new UnsupportedOperationException(); |
| 337 | } |
| 338 | |
| 339 | @Override |
| 340 | public void unregisterReceiver(BroadcastReceiver receiver) { |
| 341 | throw new UnsupportedOperationException(); |
| 342 | } |
| 343 | |
| 344 | @Override |
| 345 | public ComponentName startService(Intent service) { |
| 346 | throw new UnsupportedOperationException(); |
| 347 | } |
| 348 | |
| 349 | @Override |
| 350 | public boolean stopService(Intent service) { |
| 351 | throw new UnsupportedOperationException(); |
| 352 | } |
| 353 | |
| 354 | @Override |
| 355 | public boolean bindService(Intent service, ServiceConnection conn, int flags) { |
| 356 | throw new UnsupportedOperationException(); |
| 357 | } |
| 358 | |
| Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 359 | /** @hide */ |
| 360 | @Override |
| 361 | public boolean bindService(Intent service, ServiceConnection conn, int flags, int userId) { |
| 362 | throw new UnsupportedOperationException(); |
| 363 | } |
| 364 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | @Override |
| 366 | public void unbindService(ServiceConnection conn) { |
| 367 | throw new UnsupportedOperationException(); |
| 368 | } |
| 369 | |
| 370 | @Override |
| 371 | public boolean startInstrumentation(ComponentName className, |
| 372 | String profileFile, Bundle arguments) { |
| 373 | throw new UnsupportedOperationException(); |
| 374 | } |
| 375 | |
| 376 | @Override |
| 377 | public Object getSystemService(String name) { |
| 378 | throw new UnsupportedOperationException(); |
| 379 | } |
| 380 | |
| 381 | @Override |
| 382 | public int checkPermission(String permission, int pid, int uid) { |
| 383 | throw new UnsupportedOperationException(); |
| 384 | } |
| 385 | |
| 386 | @Override |
| 387 | public int checkCallingPermission(String permission) { |
| 388 | throw new UnsupportedOperationException(); |
| 389 | } |
| 390 | |
| 391 | @Override |
| 392 | public int checkCallingOrSelfPermission(String permission) { |
| 393 | throw new UnsupportedOperationException(); |
| 394 | } |
| 395 | |
| 396 | @Override |
| 397 | public void enforcePermission( |
| 398 | String permission, int pid, int uid, String message) { |
| 399 | throw new UnsupportedOperationException(); |
| 400 | } |
| 401 | |
| 402 | @Override |
| 403 | public void enforceCallingPermission(String permission, String message) { |
| 404 | throw new UnsupportedOperationException(); |
| 405 | } |
| 406 | |
| 407 | @Override |
| 408 | public void enforceCallingOrSelfPermission(String permission, String message) { |
| 409 | throw new UnsupportedOperationException(); |
| 410 | } |
| 411 | |
| 412 | @Override |
| 413 | public void grantUriPermission(String toPackage, Uri uri, int modeFlags) { |
| 414 | throw new UnsupportedOperationException(); |
| 415 | } |
| 416 | |
| 417 | @Override |
| 418 | public void revokeUriPermission(Uri uri, int modeFlags) { |
| 419 | throw new UnsupportedOperationException(); |
| 420 | } |
| 421 | |
| 422 | @Override |
| 423 | public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) { |
| 424 | throw new UnsupportedOperationException(); |
| 425 | } |
| 426 | |
| 427 | @Override |
| 428 | public int checkCallingUriPermission(Uri uri, int modeFlags) { |
| 429 | throw new UnsupportedOperationException(); |
| 430 | } |
| 431 | |
| 432 | @Override |
| 433 | public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) { |
| 434 | throw new UnsupportedOperationException(); |
| 435 | } |
| 436 | |
| 437 | @Override |
| 438 | public int checkUriPermission(Uri uri, String readPermission, |
| 439 | String writePermission, int pid, int uid, int modeFlags) { |
| 440 | throw new UnsupportedOperationException(); |
| 441 | } |
| 442 | |
| 443 | @Override |
| 444 | public void enforceUriPermission( |
| 445 | Uri uri, int pid, int uid, int modeFlags, String message) { |
| 446 | throw new UnsupportedOperationException(); |
| 447 | } |
| 448 | |
| 449 | @Override |
| 450 | public void enforceCallingUriPermission( |
| 451 | Uri uri, int modeFlags, String message) { |
| 452 | throw new UnsupportedOperationException(); |
| 453 | } |
| 454 | |
| 455 | @Override |
| 456 | public void enforceCallingOrSelfUriPermission( |
| 457 | Uri uri, int modeFlags, String message) { |
| 458 | throw new UnsupportedOperationException(); |
| 459 | } |
| 460 | |
| 461 | public void enforceUriPermission( |
| 462 | Uri uri, String readPermission, String writePermission, |
| 463 | int pid, int uid, int modeFlags, String message) { |
| 464 | throw new UnsupportedOperationException(); |
| 465 | } |
| 466 | |
| 467 | @Override |
| 468 | public Context createPackageContext(String packageName, int flags) |
| 469 | throws PackageManager.NameNotFoundException { |
| 470 | throw new UnsupportedOperationException(); |
| 471 | } |
| Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 472 | |
| 473 | @Override |
| 474 | public boolean isRestricted() { |
| 475 | throw new UnsupportedOperationException(); |
| 476 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | } |