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