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