2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.test.mock;
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.IntentSender;
26 import android.content.ServiceConnection;
27 import android.content.SharedPreferences;
28 import android.content.pm.ApplicationInfo;
29 import android.content.pm.PackageManager;
30 import android.content.res.AssetManager;
31 import android.content.res.Configuration;
32 import android.content.res.Resources;
33 import android.database.DatabaseErrorHandler;
34 import android.database.sqlite.SQLiteDatabase;
35 import android.graphics.Bitmap;
36 import android.graphics.drawable.Drawable;
37 import android.net.Uri;
38 import android.os.Bundle;
39 import android.os.Handler;
40 import android.os.Looper;
41 import android.os.UserHandle;
42 import android.view.CompatibilityInfoHolder;
43 import android.view.Display;
46 import java.io.FileInputStream;
47 import java.io.FileNotFoundException;
48 import java.io.FileOutputStream;
49 import java.io.IOException;
50 import java.io.InputStream;
53 * A mock {@link android.content.Context} class. All methods are non-functional and throw
54 * {@link java.lang.UnsupportedOperationException}. You can use this to inject other dependencies,
55 * mocks, or monitors into the classes you are testing.
57 public class MockContext extends Context {
60 public AssetManager getAssets() {
61 throw new UnsupportedOperationException();
65 public Resources getResources() {
66 throw new UnsupportedOperationException();
70 public PackageManager getPackageManager() {
71 throw new UnsupportedOperationException();
75 public ContentResolver getContentResolver() {
76 throw new UnsupportedOperationException();
80 public Looper getMainLooper() {
81 throw new UnsupportedOperationException();
85 public Context getApplicationContext() {
86 throw new UnsupportedOperationException();
90 public void setTheme(int resid) {
91 throw new UnsupportedOperationException();
95 public Resources.Theme getTheme() {
96 throw new UnsupportedOperationException();
100 public ClassLoader getClassLoader() {
101 throw new UnsupportedOperationException();
105 public String getPackageName() {
106 throw new UnsupportedOperationException();
110 public ApplicationInfo getApplicationInfo() {
111 throw new UnsupportedOperationException();
115 public String getPackageResourcePath() {
116 throw new UnsupportedOperationException();
121 public File getSharedPrefsFile(String name) {
122 throw new UnsupportedOperationException();
126 public String getPackageCodePath() {
127 throw new UnsupportedOperationException();
131 public SharedPreferences getSharedPreferences(String name, int mode) {
132 throw new UnsupportedOperationException();
136 public FileInputStream openFileInput(String name) throws FileNotFoundException {
137 throw new UnsupportedOperationException();
141 public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException {
142 throw new UnsupportedOperationException();
146 public boolean deleteFile(String name) {
147 throw new UnsupportedOperationException();
151 public File getFileStreamPath(String name) {
152 throw new UnsupportedOperationException();
156 public String[] fileList() {
157 throw new UnsupportedOperationException();
161 public File getFilesDir() {
162 throw new UnsupportedOperationException();
166 public File getExternalFilesDir(String type) {
167 throw new UnsupportedOperationException();
171 public File getObbDir() {
172 throw new UnsupportedOperationException();
176 public File getCacheDir() {
177 throw new UnsupportedOperationException();
181 public File getExternalCacheDir() {
182 throw new UnsupportedOperationException();
186 public File getDir(String name, int mode) {
187 throw new UnsupportedOperationException();
191 public SQLiteDatabase openOrCreateDatabase(String file, int mode,
192 SQLiteDatabase.CursorFactory factory) {
193 throw new UnsupportedOperationException();
197 public SQLiteDatabase openOrCreateDatabase(String file, int mode,
198 SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler) {
199 throw new UnsupportedOperationException();
203 public File getDatabasePath(String name) {
204 throw new UnsupportedOperationException();
208 public String[] databaseList() {
209 throw new UnsupportedOperationException();
213 public boolean deleteDatabase(String name) {
214 throw new UnsupportedOperationException();
218 public Drawable getWallpaper() {
219 throw new UnsupportedOperationException();
223 public Drawable peekWallpaper() {
224 throw new UnsupportedOperationException();
228 public int getWallpaperDesiredMinimumWidth() {
229 throw new UnsupportedOperationException();
233 public int getWallpaperDesiredMinimumHeight() {
234 throw new UnsupportedOperationException();
238 public void setWallpaper(Bitmap bitmap) throws IOException {
239 throw new UnsupportedOperationException();
243 public void setWallpaper(InputStream data) throws IOException {
244 throw new UnsupportedOperationException();
248 public void clearWallpaper() {
249 throw new UnsupportedOperationException();
253 public void startActivity(Intent intent) {
254 throw new UnsupportedOperationException();
258 public void startActivity(Intent intent, Bundle options) {
259 startActivity(intent);
263 public void startActivities(Intent[] intents) {
264 throw new UnsupportedOperationException();
268 public void startActivities(Intent[] intents, Bundle options) {
269 startActivities(intents);
273 public void startIntentSender(IntentSender intent,
274 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
275 throws IntentSender.SendIntentException {
276 throw new UnsupportedOperationException();
280 public void startIntentSender(IntentSender intent,
281 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
282 Bundle options) throws IntentSender.SendIntentException {
283 startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags);
287 public void sendBroadcast(Intent intent) {
288 throw new UnsupportedOperationException();
292 public void sendBroadcast(Intent intent, String receiverPermission) {
293 throw new UnsupportedOperationException();
297 public void sendOrderedBroadcast(Intent intent,
298 String receiverPermission) {
299 throw new UnsupportedOperationException();
303 public void sendOrderedBroadcast(Intent intent, String receiverPermission,
304 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
305 Bundle initialExtras) {
306 throw new UnsupportedOperationException();
310 public void sendBroadcastAsUser(Intent intent, UserHandle user) {
311 throw new UnsupportedOperationException();
315 public void sendBroadcastAsUser(Intent intent, UserHandle user,
316 String receiverPermission) {
317 throw new UnsupportedOperationException();
321 public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
322 String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler,
323 int initialCode, String initialData, Bundle initialExtras) {
324 throw new UnsupportedOperationException();
328 public void sendStickyBroadcast(Intent intent) {
329 throw new UnsupportedOperationException();
333 public void sendStickyOrderedBroadcast(Intent intent,
334 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
335 Bundle initialExtras) {
336 throw new UnsupportedOperationException();
340 public void removeStickyBroadcast(Intent intent) {
341 throw new UnsupportedOperationException();
345 public void sendStickyBroadcastAsUser(Intent intent, UserHandle user) {
346 throw new UnsupportedOperationException();
350 public void sendStickyOrderedBroadcastAsUser(Intent intent,
351 UserHandle user, BroadcastReceiver resultReceiver,
352 Handler scheduler, int initialCode, String initialData,
353 Bundle initialExtras) {
354 throw new UnsupportedOperationException();
358 public void removeStickyBroadcastAsUser(Intent intent, UserHandle user) {
359 throw new UnsupportedOperationException();
363 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
364 throw new UnsupportedOperationException();
368 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
369 String broadcastPermission, Handler scheduler) {
370 throw new UnsupportedOperationException();
375 public Intent registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user,
376 IntentFilter filter, String broadcastPermission, Handler scheduler) {
377 throw new UnsupportedOperationException();
381 public void unregisterReceiver(BroadcastReceiver receiver) {
382 throw new UnsupportedOperationException();
386 public ComponentName startService(Intent service) {
387 throw new UnsupportedOperationException();
391 public boolean stopService(Intent service) {
392 throw new UnsupportedOperationException();
397 public ComponentName startServiceAsUser(Intent service, UserHandle user) {
398 throw new UnsupportedOperationException();
403 public boolean stopServiceAsUser(Intent service, UserHandle user) {
404 throw new UnsupportedOperationException();
408 public boolean bindService(Intent service, ServiceConnection conn, int flags) {
409 throw new UnsupportedOperationException();
414 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
416 throw new UnsupportedOperationException();
420 public void unbindService(ServiceConnection conn) {
421 throw new UnsupportedOperationException();
425 public boolean startInstrumentation(ComponentName className,
426 String profileFile, Bundle arguments) {
427 throw new UnsupportedOperationException();
431 public Object getSystemService(String name) {
432 throw new UnsupportedOperationException();
436 public int checkPermission(String permission, int pid, int uid) {
437 throw new UnsupportedOperationException();
441 public int checkCallingPermission(String permission) {
442 throw new UnsupportedOperationException();
446 public int checkCallingOrSelfPermission(String permission) {
447 throw new UnsupportedOperationException();
451 public void enforcePermission(
452 String permission, int pid, int uid, String message) {
453 throw new UnsupportedOperationException();
457 public void enforceCallingPermission(String permission, String message) {
458 throw new UnsupportedOperationException();
462 public void enforceCallingOrSelfPermission(String permission, String message) {
463 throw new UnsupportedOperationException();
467 public void grantUriPermission(String toPackage, Uri uri, int modeFlags) {
468 throw new UnsupportedOperationException();
472 public void revokeUriPermission(Uri uri, int modeFlags) {
473 throw new UnsupportedOperationException();
477 public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) {
478 throw new UnsupportedOperationException();
482 public int checkCallingUriPermission(Uri uri, int modeFlags) {
483 throw new UnsupportedOperationException();
487 public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) {
488 throw new UnsupportedOperationException();
492 public int checkUriPermission(Uri uri, String readPermission,
493 String writePermission, int pid, int uid, int modeFlags) {
494 throw new UnsupportedOperationException();
498 public void enforceUriPermission(
499 Uri uri, int pid, int uid, int modeFlags, String message) {
500 throw new UnsupportedOperationException();
504 public void enforceCallingUriPermission(
505 Uri uri, int modeFlags, String message) {
506 throw new UnsupportedOperationException();
510 public void enforceCallingOrSelfUriPermission(
511 Uri uri, int modeFlags, String message) {
512 throw new UnsupportedOperationException();
515 public void enforceUriPermission(
516 Uri uri, String readPermission, String writePermission,
517 int pid, int uid, int modeFlags, String message) {
518 throw new UnsupportedOperationException();
522 public Context createPackageContext(String packageName, int flags)
523 throws PackageManager.NameNotFoundException {
524 throw new UnsupportedOperationException();
529 public Context createPackageContextAsUser(String packageName, int flags, UserHandle user)
530 throws PackageManager.NameNotFoundException {
531 throw new UnsupportedOperationException();
535 public Context createConfigurationContext(Configuration overrideConfiguration) {
536 throw new UnsupportedOperationException();
540 public Context createDisplayContext(Display display) {
541 throw new UnsupportedOperationException();
545 public boolean isRestricted() {
546 throw new UnsupportedOperationException();
551 public CompatibilityInfoHolder getCompatibilityInfo(int displayId) {
552 throw new UnsupportedOperationException();