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