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