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