blob: 5fab2bb2d65d2759c2e28578b6ef04132d6c40de [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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;
Dianne Hackbornfa82f222009-09-17 15:14:12 -070025import android.content.IntentSender;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.content.ServiceConnection;
27import android.content.SharedPreferences;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070028import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.content.pm.PackageManager;
30import android.content.res.AssetManager;
31import android.content.res.Resources;
Vasu Nori74f170f2010-06-01 18:06:18 -070032import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.database.sqlite.SQLiteDatabase;
34import android.graphics.Bitmap;
35import android.graphics.drawable.Drawable;
36import android.net.Uri;
37import android.os.Bundle;
38import android.os.Handler;
39import android.os.Looper;
40
41import java.io.File;
42import java.io.FileInputStream;
43import java.io.FileNotFoundException;
44import java.io.FileOutputStream;
45import java.io.IOException;
46import java.io.InputStream;
47
48/**
49 * A mock {@link android.content.Context} class. All methods are non-functional and throw
50 * {@link java.lang.UnsupportedOperationException}. You can use this to inject other dependencies,
51 * mocks, or monitors into the classes you are testing.
52 */
53public class MockContext extends Context {
54
55 @Override
56 public AssetManager getAssets() {
57 throw new UnsupportedOperationException();
58 }
59
60 @Override
61 public Resources getResources() {
62 throw new UnsupportedOperationException();
63 }
64
65 @Override
66 public PackageManager getPackageManager() {
67 throw new UnsupportedOperationException();
68 }
69
70 @Override
71 public ContentResolver getContentResolver() {
72 throw new UnsupportedOperationException();
73 }
74
75 @Override
76 public Looper getMainLooper() {
77 throw new UnsupportedOperationException();
78 }
79
80 @Override
81 public Context getApplicationContext() {
82 throw new UnsupportedOperationException();
83 }
84
85 @Override
86 public void setTheme(int resid) {
87 throw new UnsupportedOperationException();
88 }
89
90 @Override
91 public Resources.Theme getTheme() {
92 throw new UnsupportedOperationException();
93 }
94
95 @Override
96 public ClassLoader getClassLoader() {
97 throw new UnsupportedOperationException();
98 }
99
100 @Override
101 public String getPackageName() {
102 throw new UnsupportedOperationException();
103 }
104
105 @Override
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700106 public ApplicationInfo getApplicationInfo() {
107 throw new UnsupportedOperationException();
108 }
109
110 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 public String getPackageResourcePath() {
112 throw new UnsupportedOperationException();
113 }
114
Dianne Hackborn7f205432009-07-28 00:13:47 -0700115 /** @hide */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 @Override
Joe Onorato23ecae32009-06-10 17:07:15 -0700117 public File getSharedPrefsFile(String name) {
118 throw new UnsupportedOperationException();
119 }
120
121 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 public String getPackageCodePath() {
123 throw new UnsupportedOperationException();
124 }
125
126 @Override
127 public SharedPreferences getSharedPreferences(String name, int mode) {
128 throw new UnsupportedOperationException();
129 }
130
131 @Override
132 public FileInputStream openFileInput(String name) throws FileNotFoundException {
133 throw new UnsupportedOperationException();
134 }
135
136 @Override
137 public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException {
138 throw new UnsupportedOperationException();
139 }
140
141 @Override
142 public boolean deleteFile(String name) {
143 throw new UnsupportedOperationException();
144 }
145
146 @Override
147 public File getFileStreamPath(String name) {
148 throw new UnsupportedOperationException();
149 }
150
151 @Override
152 public String[] fileList() {
153 throw new UnsupportedOperationException();
154 }
155
156 @Override
157 public File getFilesDir() {
158 throw new UnsupportedOperationException();
159 }
160
161 @Override
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800162 public File getExternalFilesDir(String type) {
163 throw new UnsupportedOperationException();
164 }
165
166 @Override
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800167 public File getObbDir() {
168 throw new UnsupportedOperationException();
169 }
170
171 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 public File getCacheDir() {
173 throw new UnsupportedOperationException();
174 }
175
176 @Override
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800177 public File getExternalCacheDir() {
178 throw new UnsupportedOperationException();
179 }
180
181 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 public File getDir(String name, int mode) {
183 throw new UnsupportedOperationException();
184 }
185
186 @Override
187 public SQLiteDatabase openOrCreateDatabase(String file, int mode,
188 SQLiteDatabase.CursorFactory factory) {
189 throw new UnsupportedOperationException();
190 }
191
192 @Override
Vasu Nori74f170f2010-06-01 18:06:18 -0700193 public SQLiteDatabase openOrCreateDatabase(String file, int mode,
194 SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler) {
195 throw new UnsupportedOperationException();
196 }
197
198 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 public File getDatabasePath(String name) {
200 throw new UnsupportedOperationException();
201 }
202
203 @Override
204 public String[] databaseList() {
205 throw new UnsupportedOperationException();
206 }
207
208 @Override
209 public boolean deleteDatabase(String name) {
210 throw new UnsupportedOperationException();
211 }
212
213 @Override
214 public Drawable getWallpaper() {
215 throw new UnsupportedOperationException();
216 }
217
218 @Override
219 public Drawable peekWallpaper() {
220 throw new UnsupportedOperationException();
221 }
222
223 @Override
224 public int getWallpaperDesiredMinimumWidth() {
225 throw new UnsupportedOperationException();
226 }
227
228 @Override
229 public int getWallpaperDesiredMinimumHeight() {
230 throw new UnsupportedOperationException();
231 }
232
233 @Override
234 public void setWallpaper(Bitmap bitmap) throws IOException {
235 throw new UnsupportedOperationException();
236 }
237
238 @Override
239 public void setWallpaper(InputStream data) throws IOException {
240 throw new UnsupportedOperationException();
241 }
242
243 @Override
244 public void clearWallpaper() {
245 throw new UnsupportedOperationException();
246 }
247
248 @Override
249 public void startActivity(Intent intent) {
250 throw new UnsupportedOperationException();
251 }
252
253 @Override
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800254 public void startActivities(Intent[] intents) {
255 throw new UnsupportedOperationException();
256 }
257
258 @Override
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700259 public void startIntentSender(IntentSender intent,
260 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
261 throws IntentSender.SendIntentException {
262 throw new UnsupportedOperationException();
263 }
264
265 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 public void sendBroadcast(Intent intent) {
267 throw new UnsupportedOperationException();
268 }
269
Amith Yamasani67cf7d32012-02-16 14:31:23 -0800270 /** @hide */
271 @Override
272 public void sendBroadcast(Intent intent, int userId) {
273 throw new UnsupportedOperationException();
274 }
275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 @Override
277 public void sendBroadcast(Intent intent, String receiverPermission) {
278 throw new UnsupportedOperationException();
279 }
280
281 @Override
282 public void sendOrderedBroadcast(Intent intent,
283 String receiverPermission) {
284 throw new UnsupportedOperationException();
285 }
286
287 @Override
288 public void sendOrderedBroadcast(Intent intent, String receiverPermission,
289 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
290 Bundle initialExtras) {
291 throw new UnsupportedOperationException();
292 }
293
294 @Override
295 public void sendStickyBroadcast(Intent intent) {
296 throw new UnsupportedOperationException();
297 }
298
299 @Override
Dianne Hackbornefa199f2009-09-19 12:03:15 -0700300 public void sendStickyOrderedBroadcast(Intent intent,
301 BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData,
302 Bundle initialExtras) {
303 throw new UnsupportedOperationException();
304 }
305
306 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 public void removeStickyBroadcast(Intent intent) {
308 throw new UnsupportedOperationException();
309 }
310
311 @Override
312 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
313 throw new UnsupportedOperationException();
314 }
315
316 @Override
317 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
318 String broadcastPermission, Handler scheduler) {
319 throw new UnsupportedOperationException();
320 }
321
322 @Override
323 public void unregisterReceiver(BroadcastReceiver receiver) {
324 throw new UnsupportedOperationException();
325 }
326
327 @Override
328 public ComponentName startService(Intent service) {
329 throw new UnsupportedOperationException();
330 }
331
332 @Override
333 public boolean stopService(Intent service) {
334 throw new UnsupportedOperationException();
335 }
336
337 @Override
338 public boolean bindService(Intent service, ServiceConnection conn, int flags) {
339 throw new UnsupportedOperationException();
340 }
341
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800342 /** @hide */
343 @Override
344 public boolean bindService(Intent service, ServiceConnection conn, int flags, int userId) {
345 throw new UnsupportedOperationException();
346 }
347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348 @Override
349 public void unbindService(ServiceConnection conn) {
350 throw new UnsupportedOperationException();
351 }
352
353 @Override
354 public boolean startInstrumentation(ComponentName className,
355 String profileFile, Bundle arguments) {
356 throw new UnsupportedOperationException();
357 }
358
359 @Override
360 public Object getSystemService(String name) {
361 throw new UnsupportedOperationException();
362 }
363
364 @Override
365 public int checkPermission(String permission, int pid, int uid) {
366 throw new UnsupportedOperationException();
367 }
368
369 @Override
370 public int checkCallingPermission(String permission) {
371 throw new UnsupportedOperationException();
372 }
373
374 @Override
375 public int checkCallingOrSelfPermission(String permission) {
376 throw new UnsupportedOperationException();
377 }
378
379 @Override
380 public void enforcePermission(
381 String permission, int pid, int uid, String message) {
382 throw new UnsupportedOperationException();
383 }
384
385 @Override
386 public void enforceCallingPermission(String permission, String message) {
387 throw new UnsupportedOperationException();
388 }
389
390 @Override
391 public void enforceCallingOrSelfPermission(String permission, String message) {
392 throw new UnsupportedOperationException();
393 }
394
395 @Override
396 public void grantUriPermission(String toPackage, Uri uri, int modeFlags) {
397 throw new UnsupportedOperationException();
398 }
399
400 @Override
401 public void revokeUriPermission(Uri uri, int modeFlags) {
402 throw new UnsupportedOperationException();
403 }
404
405 @Override
406 public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) {
407 throw new UnsupportedOperationException();
408 }
409
410 @Override
411 public int checkCallingUriPermission(Uri uri, int modeFlags) {
412 throw new UnsupportedOperationException();
413 }
414
415 @Override
416 public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) {
417 throw new UnsupportedOperationException();
418 }
419
420 @Override
421 public int checkUriPermission(Uri uri, String readPermission,
422 String writePermission, int pid, int uid, int modeFlags) {
423 throw new UnsupportedOperationException();
424 }
425
426 @Override
427 public void enforceUriPermission(
428 Uri uri, int pid, int uid, int modeFlags, String message) {
429 throw new UnsupportedOperationException();
430 }
431
432 @Override
433 public void enforceCallingUriPermission(
434 Uri uri, int modeFlags, String message) {
435 throw new UnsupportedOperationException();
436 }
437
438 @Override
439 public void enforceCallingOrSelfUriPermission(
440 Uri uri, int modeFlags, String message) {
441 throw new UnsupportedOperationException();
442 }
443
444 public void enforceUriPermission(
445 Uri uri, String readPermission, String writePermission,
446 int pid, int uid, int modeFlags, String message) {
447 throw new UnsupportedOperationException();
448 }
449
450 @Override
451 public Context createPackageContext(String packageName, int flags)
452 throws PackageManager.NameNotFoundException {
453 throw new UnsupportedOperationException();
454 }
Romain Guy870e09f2009-07-06 16:35:25 -0700455
456 @Override
457 public boolean isRestricted() {
458 throw new UnsupportedOperationException();
459 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460}