• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.xtremelabs.robolectric;
2 
3 import java.lang.reflect.Field;
4 import java.lang.reflect.Modifier;
5 import java.util.Arrays;
6 import java.util.List;
7 
8 import org.apache.http.Header;
9 import org.apache.http.HttpRequest;
10 import org.apache.http.HttpResponse;
11 import org.apache.http.impl.client.DefaultRequestDirector;
12 
13 import android.accounts.AccountManager;
14 import android.app.*;
15 import android.appwidget.AppWidgetManager;
16 import android.bluetooth.BluetoothAdapter;
17 import android.bluetooth.BluetoothDevice;
18 import android.content.*;
19 import android.content.pm.ResolveInfo;
20 import android.content.pm.Signature;
21 import android.content.res.AssetManager;
22 import android.content.res.Configuration;
23 import android.content.res.Resources;
24 import android.content.res.Resources.Theme;
25 import android.database.CursorWrapper;
26 import android.database.sqlite.*;
27 import android.graphics.*;
28 import android.graphics.drawable.*;
29 import android.hardware.Camera;
30 import android.hardware.SensorManager;
31 import android.location.Address;
32 import android.location.Geocoder;
33 import android.location.LocationManager;
34 import android.media.AudioManager;
35 import android.media.MediaPlayer;
36 import android.media.MediaRecorder;
37 import android.net.ConnectivityManager;
38 import android.net.NetworkInfo;
39 import android.net.wifi.ScanResult;
40 import android.net.wifi.WifiConfiguration;
41 import android.net.wifi.WifiInfo;
42 import android.net.wifi.WifiManager;
43 import android.os.*;
44 import android.preference.*;
45 import android.support.v4.app.DialogFragment;
46 import android.support.v4.app.Fragment;
47 import android.support.v4.app.FragmentActivity;
48 import android.support.v4.app.FragmentPagerAdapter;
49 import android.support.v4.app.ListFragment;
50 import android.support.v4.content.CursorLoader;
51 import android.support.v4.view.PagerAdapter;
52 import android.support.v4.view.ViewPager;
53 import android.telephony.PhoneNumberUtils;
54 import android.telephony.SmsManager;
55 import android.telephony.TelephonyManager;
56 import android.text.ClipboardManager;
57 import android.text.TextPaint;
58 import android.text.format.DateFormat;
59 import android.text.method.PasswordTransformationMethod;
60 import android.util.SparseArray;
61 import android.util.SparseBooleanArray;
62 import android.util.SparseIntArray;
63 import android.view.*;
64 import android.view.animation.*;
65 import android.view.inputmethod.InputMethodManager;
66 import android.webkit.*;
67 import android.widget.*;
68 
69 import com.xtremelabs.robolectric.bytecode.RobolectricInternals;
70 import com.xtremelabs.robolectric.bytecode.ShadowWrangler;
71 import com.xtremelabs.robolectric.shadows.*;
72 import com.xtremelabs.robolectric.shadows.ShadowResources.ShadowTheme;
73 import com.xtremelabs.robolectric.tester.org.apache.http.FakeHttpLayer;
74 import com.xtremelabs.robolectric.tester.org.apache.http.HttpRequestInfo;
75 import com.xtremelabs.robolectric.tester.org.apache.http.RequestMatcher;
76 import com.xtremelabs.robolectric.util.Scheduler;
77 
78 public class Robolectric {
79     public static Application application;
80 
newInstanceOf(Class<T> clazz)81     public static <T> T newInstanceOf(Class<T> clazz) {
82         return RobolectricInternals.newInstanceOf(clazz);
83     }
84 
newInstanceOf(String className)85     public static Object newInstanceOf(String className) {
86         try {
87             Class<?> clazz = Class.forName(className);
88             if (clazz != null) {
89                 return newInstanceOf(clazz);
90             }
91         } catch (ClassNotFoundException e) {
92         }
93         return null;
94     }
95 
bindShadowClass(Class<?> shadowClass)96     public static void bindShadowClass(Class<?> shadowClass) {
97         RobolectricInternals.bindShadowClass(shadowClass);
98     }
99 
bindDefaultShadowClasses()100     public static void bindDefaultShadowClasses() {
101         bindShadowClasses(getDefaultShadowClasses());
102     }
103 
bindShadowClasses(List<Class<?>> shadowClasses)104     public static void bindShadowClasses(List<Class<?>> shadowClasses) {
105         for (Class<?> shadowClass : shadowClasses) {
106             bindShadowClass(shadowClass);
107         }
108     }
109 
110     /**
111      * Invoke this utility method in tests to reveal which Android api classes and methods are being invoked
112      * for which there are no shadows or shadow methods. This helps expose which methods are being invoked
113      * either by a third party library or application code which need new shadow methods to be written. Generates
114      * output for the current test only.
115      */
logMissingInvokedShadowMethods()116     public static void logMissingInvokedShadowMethods() {
117         ShadowWrangler.getInstance().logMissingInvokedShadowMethods();
118     }
119 
getDefaultShadowClasses()120     public static List<Class<?>> getDefaultShadowClasses() {
121         return Arrays.asList(
122                 ShadowAbsListView.class,
123                 ShadowAbsoluteLayout.class,
124                 ShadowAbsSeekBar.class,
125                 ShadowAbsSpinner.class,
126                 ShadowAbstractCursor.class,
127                 ShadowAccount.class,
128                 ShadowAccountManager.class,
129                 ShadowActivity.class,
130                 ShadowActivityInfo.class,
131                 ShadowActivityGroup.class,
132                 ShadowActivityManager.class,
133                 ShadowAdapterView.class,
134                 ShadowAddress.class,
135                 ShadowAlarmManager.class,
136                 ShadowAlertDialog.class,
137                 ShadowAlertDialog.ShadowBuilder.class,
138                 ShadowAlphaAnimation.class,
139                 ShadowAndroidHttpClient.class,
140                 ShadowAnimation.class,
141                 ShadowAnimationDrawable.class,
142                 ShadowAnimationSet.class,
143                 ShadowAnimationUtils.class,
144                 ShadowApplication.class,
145                 ShadowAppWidgetManager.class,
146                 ShadowArrayAdapter.class,
147                 ShadowAssetManager.class,
148                 ShadowAsyncTask.class,
149                 ShadowAudioManager.class,
150                 ShadowAutoCompleteTextView.class,
151                 ShadowBase64.class,
152                 ShadowBaseAdapter.class,
153                 ShadowBinder.class,
154                 ShadowBitmap.class,
155                 ShadowBitmapDrawable.class,
156                 ShadowBitmapFactory.class,
157                 ShadowBluetoothAdapter.class,
158                 ShadowBluetoothDevice.class,
159                 ShadowBundle.class,
160                 ShadowButton.class,
161                 ShadowCamera.class,
162                 ShadowCameraParameters.class,
163                 ShadowCameraSize.class,
164                 ShadowCanvas.class,
165                 ShadowCheckedTextView.class,
166                 ShadowClipboardManager.class,
167                 ShadowColor.class,
168                 ShadowColorDrawable.class,
169                 ShadowColorMatrix.class,
170                 ShadowColorMatrixColorFilter.class,
171                 ShadowColorStateList.class,
172                 ShadowComponentName.class,
173                 ShadowCompoundButton.class,
174                 ShadowConfiguration.class,
175                 ShadowConnectivityManager.class,
176                 ShadowContentProvider.class,
177                 ShadowContentProviderOperation.class,
178                 ShadowContentProviderOperationBuilder.class,
179                 ShadowContentProviderResult.class,
180                 ShadowContentResolver.class,
181                 ShadowContentUris.class,
182                 ShadowContentValues.class,
183                 ShadowContext.class,
184                 ShadowContextWrapper.class,
185                 ShadowContextThemeWrapper.class,
186                 ShadowCookieManager.class,
187                 ShadowCookieSyncManager.class,
188                 ShadowCriteria.class,
189                 ShadowCountDownTimer.class,
190                 ShadowCursorAdapter.class,
191                 ShadowCursorLoader.class,
192                 ShadowCursorWrapper.class,
193                 ShadowDatabaseUtils.class,
194                 ShadowDateFormat.class,
195                 ShadowDefaultRequestDirector.class,
196                 ShadowDisplay.class,
197                 ShadowDrawable.class,
198                 ShadowDialog.class,
199                 ShadowDialogFragment.class,
200                 ShadowDialogPreference.class,
201                 ShadowEditText.class,
202                 ShadowEnvironment.class,
203                 ShadowExpandableListView.class,
204                 ShadowFilter.class,
205                 ShadowFloatMath.class,
206                 ShadowFragment.class,
207                 ShadowFragmentActivity.class,
208                 ShadowFragmentPagerAdapter.class,
209                 ShadowFrameLayout.class,
210                 ShadowGallery.class,
211                 ShadowGeocoder.class,
212                 ShadowGeoPoint.class,
213                 ShadowGridView.class,
214                 ShadowHandler.class,
215                 ShadowHandlerThread.class,
216                 ShadowHtml.class,
217                 ShadowImageView.class,
218                 ShadowInputMethodManager.class,
219                 ShadowIntent.class,
220                 ShadowIntentFilter.class,
221                 ShadowIntentFilterAuthorityEntry.class,
222                 ShadowItemizedOverlay.class,
223                 ShadowJsPromptResult.class,
224                 ShadowJsResult.class,
225                 ShadowKeyEvent.class,
226                 ShadowKeyguardManager.class,
227                 ShadowKeyGuardLock.class,
228                 ShadowLayerDrawable.class,
229                 ShadowLayoutInflater.class,
230                 ShadowLayoutParams.class,
231                 ShadowLinearLayout.class,
232                 ShadowLinkMovementMethod.class,
233                 ShadowListActivity.class,
234                 ShadowListFragment.class,
235                 ShadowListPreference.class,
236                 ShadowListView.class,
237                 ShadowLocation.class,
238                 ShadowLocationManager.class,
239                 ShadowLog.class,
240                 ShadowLooper.class,
241                 ShadowMapController.class,
242                 ShadowMapActivity.class,
243                 ShadowMapView.class,
244                 ShadowMarginLayoutParams.class,
245                 ShadowMatrix.class,
246                 ShadowMatrixCursor.class,
247                 ShadowMediaPlayer.class,
248                 ShadowMediaRecorder.class,
249                 ShadowMediaStore.ShadowImages.ShadowMedia.class,
250                 ShadowMenuInflater.class,
251                 ShadowMessage.class,
252                 ShadowMessenger.class,
253                 ShadowMimeTypeMap.class,
254                 ShadowMotionEvent.class,
255                 ShadowNotification.class,
256                 ShadowNdefMessage.class,
257                 ShadowNdefRecord.class,
258                 ShadowNfcAdapter.class,
259                 ShadowNotificationManager.class,
260                 ShadowNetworkInfo.class,
261                 ShadowOverlayItem.class,
262                 ShadowPagerAdapter.class,
263                 ShadowPaint.class,
264                 ShadowPair.class,
265                 ShadowParcel.class,
266                 ShadowPasswordTransformationMethod.class,
267                 ShadowPath.class,
268                 ShadowPatterns.class,
269                 ShadowPendingIntent.class,
270                 ShadowPeriodicSync.class,
271                 ShadowPhoneNumberUtils.class,
272                 ShadowPoint.class,
273                 ShadowPointF.class,
274                 ShadowPopupWindow.class,
275                 ShadowPowerManager.class,
276                 ShadowPowerManager.ShadowWakeLock.class,
277                 ShadowPreference.class,
278                 ShadowPreferenceActivity.class,
279                 ShadowPreferenceCategory.class,
280                 ShadowPreferenceGroup.class,
281                 ShadowPreferenceManager.class,
282                 ShadowPreferenceScreen.class,
283                 ShadowProcess.class,
284                 ShadowProgressBar.class,
285                 ShadowProgressDialog.class,
286                 ShadowRadioButton.class,
287                 ShadowRadioGroup.class,
288                 ShadowRatingBar.class,
289                 ShadowRect.class,
290                 ShadowResolveInfo.class,
291                 ShadowRemoteCallbackList.class,
292                 ShadowRemoteViews.class,
293                 ShadowResultReceiver.class,
294                 ShadowResourceCursorAdapter.class,
295                 ShadowResources.class,
296                 ShadowResources.ShadowTheme.class,
297                 ShadowScanResult.class,
298                 ShadowScrollView.class,
299                 ShadowSeekBar.class,
300                 ShadowSensorManager.class,
301                 ShadowService.class,
302                 ShadowSettings.class,
303                 ShadowSettings.ShadowGlobal.class,
304                 ShadowSettings.ShadowSecure.class,
305                 ShadowSettings.ShadowSystem.class,
306                 ShadowSignature.class,
307                 ShadowSimpleCursorAdapter.class,
308                 ShadowShapeDrawable.class,
309                 ShadowSmsManager.class,
310                 ShadowSpannableString.class,
311                 ShadowSpannableStringBuilder.class,
312                 ShadowSparseArray.class,
313                 ShadowSparseBooleanArray.class,
314                 ShadowSparseIntArray.class,
315                 ShadowSpinner.class,
316                 ShadowSSLCertificateSocketFactory.class,
317                 ShadowSyncResult.class,
318                 ShadowSyncResult.ShadowSyncStats.class,
319                 ShadowSQLiteProgram.class,
320                 ShadowSQLiteCloseable.class,
321                 ShadowSQLiteDatabase.class,
322                 ShadowSQLiteCursor.class,
323                 ShadowSQLiteOpenHelper.class,
324                 ShadowSQLiteStatement.class,
325                 ShadowSQLiteQueryBuilder.class,
326                 ShadowSslErrorHandler.class,
327                 ShadowStateListDrawable.class,
328                 ShadowStatFs.class,
329                 ShadowSurfaceView.class,
330                 ShadowTabActivity.class,
331                 ShadowTabHost.class,
332                 ShadowTabSpec.class,
333                 ShadowTelephonyManager.class,
334                 ShadowTextPaint.class,
335                 ShadowTextUtils.class,
336                 ShadowTextView.class,
337                 ShadowTime.class,
338                 ShadowToast.class,
339                 ShadowTranslateAnimation.class,
340                 ShadowTypedArray.class,
341                 ShadowTypedValue.class,
342                 ShadowUriMatcher.class,
343                 ShadowURLSpan.class,
344                 ShadowVibrator.class,
345                 ShadowVideoView.class,
346                 ShadowView.class,
347                 ShadowViewAnimator.class,
348                 ShadowViewConfiguration.class,
349                 ShadowViewGroup.class,
350                 ShadowViewFlipper.class,
351                 ShadowViewMeasureSpec.class,
352                 ShadowViewPager.class,
353                 ShadowViewStub.class,
354                 ShadowViewTreeObserver.class,
355                 ShadowWebView.class,
356                 ShadowWifiConfiguration.class,
357                 ShadowWifiInfo.class,
358                 ShadowWifiManager.class,
359                 ShadowWifiManager.ShadowWifiLock.class,
360                 ShadowWindow.class,
361                 ShadowZoomButtonsController.class
362         );
363     }
364 
resetStaticState()365     public static void resetStaticState() {
366         ShadowWrangler.getInstance().silence();
367         Robolectric.application = new Application();
368         ShadowBinder.reset();
369         ShadowBitmapFactory.reset();
370         ShadowDrawable.reset();
371         ShadowMediaStore.reset();
372         ShadowLog.reset();
373         ShadowContext.clearFilesAndCache();
374         ShadowLooper.resetThreadLoopers();
375         ShadowDialog.reset();
376         ShadowContentResolver.reset();
377         ShadowLocalBroadcastManager.reset();
378         ShadowMimeTypeMap.reset();
379         ShadowStatFs.reset();
380         ShadowProcess.reset();
381         ShadowAccount.reset();
382         ShadowIntent.reset();
383         ShadowSignature.reset();
384         ShadowBundle.reset();
385         ShadowPatterns.reset();
386     }
387 
directlyOn(T shadowedObject)388     public static <T> T directlyOn(T shadowedObject) {
389         return RobolectricInternals.directlyOn(shadowedObject);
390     }
391 
shadowOf(AbsListView instance)392     public static ShadowAbsListView shadowOf(AbsListView instance) {
393         return (ShadowAbsListView) shadowOf_(instance);
394     }
395 
shadowOf(AbsSeekBar instance)396     public static ShadowAbsSeekBar shadowOf(AbsSeekBar instance) {
397         return (ShadowAbsSeekBar) shadowOf_(instance);
398     }
399 
shadowOf(AccountManager instance)400     public static ShadowAccountManager shadowOf(AccountManager instance) {
401         return (ShadowAccountManager) shadowOf_(instance);
402     }
403 
shadowOf(Activity instance)404     public static ShadowActivity shadowOf(Activity instance) {
405         return (ShadowActivity) shadowOf_(instance);
406     }
407 
shadowOf(ActivityGroup instance)408     public static ShadowActivityGroup shadowOf(ActivityGroup instance) {
409         return (ShadowActivityGroup) shadowOf_(instance);
410     }
411 
shadowOf(ActivityManager instance)412     public static ShadowActivityManager shadowOf(ActivityManager instance) {
413         return (ShadowActivityManager) shadowOf_(instance);
414     }
415 
shadowOf(AdapterView instance)416     public static ShadowAdapterView shadowOf(AdapterView instance) {
417         return (ShadowAdapterView) shadowOf_(instance);
418     }
419 
shadowOf(Address instance)420     public static ShadowAddress shadowOf(Address instance) {
421         return (ShadowAddress) shadowOf_(instance);
422     }
423 
shadowOf(AlarmManager instance)424     public static ShadowAlarmManager shadowOf(AlarmManager instance) {
425         return (ShadowAlarmManager) Robolectric.shadowOf_(instance);
426     }
427 
shadowOf(AlertDialog instance)428     public static ShadowAlertDialog shadowOf(AlertDialog instance) {
429         return (ShadowAlertDialog) shadowOf_(instance);
430     }
431 
shadowOf(AlphaAnimation instance)432     public static ShadowAlphaAnimation shadowOf(AlphaAnimation instance) {
433         return (ShadowAlphaAnimation) shadowOf_(instance);
434     }
435 
shadowOf(Animation instance)436     public static ShadowAnimation shadowOf(Animation instance) {
437         return (ShadowAnimation) shadowOf_(instance);
438     }
439 
shadowOf(AnimationDrawable instance)440     public static ShadowAnimationDrawable shadowOf(AnimationDrawable instance) {
441         return (ShadowAnimationDrawable) shadowOf_(instance);
442     }
443 
shadowOf(AnimationSet instance)444     public static ShadowAnimationSet shadowOf(AnimationSet instance) {
445         return (ShadowAnimationSet) shadowOf_(instance);
446     }
447 
shadowOf(AnimationUtils instance)448     public static ShadowAnimationUtils shadowOf(AnimationUtils instance) {
449         return (ShadowAnimationUtils) shadowOf_(instance);
450     }
451 
shadowOf(Application instance)452     public static ShadowApplication shadowOf(Application instance) {
453         return (ShadowApplication) shadowOf_(instance);
454     }
455 
shadowOf(AppWidgetManager instance)456     public static ShadowAppWidgetManager shadowOf(AppWidgetManager instance) {
457         return (ShadowAppWidgetManager) shadowOf_(instance);
458     }
459 
shadowOf(ArrayAdapter instance)460     public static ShadowArrayAdapter shadowOf(ArrayAdapter instance) {
461         return (ShadowArrayAdapter) shadowOf_(instance);
462     }
463 
shadowOf(AssetManager instance)464     public static ShadowAssetManager shadowOf(AssetManager instance) {
465         return (ShadowAssetManager) Robolectric.shadowOf_(instance);
466     }
467 
468     @SuppressWarnings("rawtypes")
shadowOf(AsyncTask instance)469 	public static ShadowAsyncTask shadowOf(AsyncTask instance){
470     	return (ShadowAsyncTask) Robolectric.shadowOf_( instance );
471     }
472 
shadowOf(AudioManager instance)473     public static ShadowAudioManager shadowOf(AudioManager instance) {
474         return (ShadowAudioManager) shadowOf_(instance);
475     }
476 
shadowOf(AutoCompleteTextView instance)477     public static ShadowAutoCompleteTextView shadowOf(AutoCompleteTextView instance) {
478         return (ShadowAutoCompleteTextView) shadowOf_(instance);
479     }
480 
shadowOf(BaseAdapter other)481     public static ShadowBaseAdapter shadowOf(BaseAdapter other) {
482         return (ShadowBaseAdapter) Robolectric.shadowOf_(other);
483     }
484 
shadowOf(Bitmap other)485     public static ShadowBitmap shadowOf(Bitmap other) {
486         return (ShadowBitmap) Robolectric.shadowOf_(other);
487     }
488 
shadowOf(BitmapDrawable instance)489     public static ShadowBitmapDrawable shadowOf(BitmapDrawable instance) {
490         return (ShadowBitmapDrawable) shadowOf_(instance);
491     }
492 
shadowOf(BluetoothAdapter other)493     public static ShadowBluetoothAdapter shadowOf(BluetoothAdapter other) {
494         return (ShadowBluetoothAdapter) Robolectric.shadowOf_(other);
495     }
496 
shadowOf(BluetoothDevice other)497     public static ShadowBluetoothDevice shadowOf(BluetoothDevice other) {
498         return (ShadowBluetoothDevice) Robolectric.shadowOf_(other);
499     }
500 
shadowOf(Bundle instance)501     public static ShadowBundle shadowOf(Bundle instance) {
502         return (ShadowBundle) shadowOf_(instance);
503     }
504 
shadowOf(Camera instance)505     public static ShadowCamera shadowOf(Camera instance) {
506         return (ShadowCamera) shadowOf_(instance);
507     }
508 
shadowOf(Camera.Parameters instance)509     public static ShadowCameraParameters shadowOf(Camera.Parameters instance) {
510         return (ShadowCameraParameters) shadowOf_(instance);
511     }
512 
shadowOf(Camera.Size instance)513     public static ShadowCameraSize shadowOf(Camera.Size instance) {
514         return (ShadowCameraSize) shadowOf_(instance);
515     }
516 
shadowOf(Canvas instance)517     public static ShadowCanvas shadowOf(Canvas instance) {
518         return (ShadowCanvas) shadowOf_(instance);
519     }
520 
shadowOf(CheckedTextView instance)521     public static ShadowCheckedTextView shadowOf(CheckedTextView instance) {
522         return (ShadowCheckedTextView) shadowOf_(instance);
523     }
524 
shadowOf(ClipboardManager instance)525     public static ShadowClipboardManager shadowOf(ClipboardManager instance) {
526         return (ShadowClipboardManager) shadowOf_(instance);
527     }
528 
shadowOf(Color instance)529     public static ShadowColor shadowOf(Color instance) {
530         return (ShadowColor) shadowOf_(instance);
531     }
532 
shadowOf(ColorDrawable instance)533     public static ShadowColorDrawable shadowOf(ColorDrawable instance) {
534         return (ShadowColorDrawable) shadowOf_(instance);
535     }
536 
shadowOf(ColorMatrix instance)537     public static ShadowColorMatrix shadowOf(ColorMatrix instance) {
538         return (ShadowColorMatrix) shadowOf_(instance);
539     }
540 
shadowOf(Configuration instance)541     public static ShadowConfiguration shadowOf(Configuration instance) {
542         return (ShadowConfiguration) Robolectric.shadowOf_(instance);
543     }
544 
shadowOf(ConnectivityManager instance)545     public static ShadowConnectivityManager shadowOf(ConnectivityManager instance) {
546         return (ShadowConnectivityManager) shadowOf_(instance);
547     }
548 
shadowOf(CookieManager instance)549     public static ShadowCookieManager shadowOf(CookieManager instance) {
550         return (ShadowCookieManager) shadowOf_(instance);
551     }
552 
shadowOf(ContentResolver instance)553     public static ShadowContentResolver shadowOf(ContentResolver instance) {
554         return (ShadowContentResolver) shadowOf_(instance);
555     }
556 
shadowOf(ContentProviderOperation instance)557     public static ShadowContentProviderOperation shadowOf(ContentProviderOperation instance) {
558         return (ShadowContentProviderOperation) shadowOf_(instance);
559     }
560 
shadowOf(ContentProviderOperation.Builder instance)561     public static ShadowContentProviderOperationBuilder shadowOf(ContentProviderOperation.Builder instance) {
562         return (ShadowContentProviderOperationBuilder) shadowOf_(instance);
563     }
564 
shadowOf(ContentProviderResult instance)565     public static ShadowContentProviderResult shadowOf(ContentProviderResult instance) {
566         return (ShadowContentProviderResult) shadowOf_(instance);
567     }
568 
shadowOf(CookieSyncManager instance)569     public static ShadowCookieSyncManager shadowOf(CookieSyncManager instance) {
570         return (ShadowCookieSyncManager) shadowOf_(instance);
571     }
572 
shadowOf(Context instance)573     public static ShadowContext shadowOf(Context instance) {
574         return (ShadowContext) shadowOf_(instance);
575     }
576 
shadowOf(ContentValues other)577     public static ShadowContentValues shadowOf(ContentValues other) {
578         return (ShadowContentValues) Robolectric.shadowOf_(other);
579     }
580 
shadowOf(ContextWrapper instance)581     public static ShadowContextWrapper shadowOf(ContextWrapper instance) {
582         return (ShadowContextWrapper) shadowOf_(instance);
583     }
584 
shadowOf(CountDownTimer instance)585     public static ShadowCountDownTimer shadowOf(CountDownTimer instance) {
586         return (ShadowCountDownTimer) Robolectric.shadowOf_(instance);
587     }
588 
shadowOf(CursorAdapter instance)589     public static ShadowCursorAdapter shadowOf(CursorAdapter instance) {
590         return (ShadowCursorAdapter) shadowOf_(instance);
591     }
592 
shadowOf(CursorLoader instance)593     public static ShadowCursorLoader shadowOf(CursorLoader instance) {
594         return (ShadowCursorLoader) shadowOf_(instance);
595     }
596 
shadowOf(CursorWrapper instance)597     public static ShadowCursorWrapper shadowOf(CursorWrapper instance) {
598         return (ShadowCursorWrapper) shadowOf_(instance);
599     }
600 
shadowOf(DateFormat instance)601     public static ShadowDateFormat shadowOf(DateFormat instance) {
602         return (ShadowDateFormat) shadowOf_(instance);
603     }
604 
shadowOf(DefaultRequestDirector instance)605     public static ShadowDefaultRequestDirector shadowOf(DefaultRequestDirector instance) {
606         return (ShadowDefaultRequestDirector) shadowOf_(instance);
607     }
608 
shadowOf(Dialog instance)609     public static ShadowDialog shadowOf(Dialog instance) {
610         return (ShadowDialog) shadowOf_(instance);
611     }
612 
shadowOf(DialogFragment instance)613     public static ShadowDialogFragment shadowOf(DialogFragment instance) {
614         return (ShadowDialogFragment) shadowOf_(instance);
615     }
616 
shadowOf(DialogPreference instance)617     public static ShadowDialogPreference shadowOf(DialogPreference instance) {
618         return (ShadowDialogPreference) shadowOf_(instance);
619     }
620 
shadowOf(Drawable instance)621     public static ShadowDrawable shadowOf(Drawable instance) {
622         return (ShadowDrawable) shadowOf_(instance);
623     }
624 
shadowOf(Display instance)625     public static ShadowDisplay shadowOf(Display instance) {
626         return (ShadowDisplay) shadowOf_(instance);
627     }
628 
shadowOf(ExpandableListView instance)629     public static ShadowExpandableListView shadowOf(ExpandableListView instance) {
630         return (ShadowExpandableListView) shadowOf_(instance);
631     }
632 
shadowOf(Filter instance)633     public static ShadowFilter shadowOf(Filter instance) {
634         return (ShadowFilter) shadowOf_(instance);
635     }
636 
shadowOf(Fragment instance)637     public static ShadowFragment shadowOf(Fragment instance) {
638         return (ShadowFragment) shadowOf_(instance);
639     }
640 
shadowOf(FragmentActivity instance)641     public static ShadowFragmentActivity shadowOf(FragmentActivity instance) {
642         return (ShadowFragmentActivity) shadowOf_(instance);
643     }
644 
shadowOf(FragmentPagerAdapter instance)645     public static ShadowFragmentPagerAdapter shadowOf(FragmentPagerAdapter instance) {
646         return (ShadowFragmentPagerAdapter) shadowOf_(instance);
647     }
648 
shadowOf(FrameLayout instance)649     public static ShadowFrameLayout shadowOf(FrameLayout instance) {
650         return (ShadowFrameLayout) shadowOf_(instance);
651     }
652 
shadowOf(Gallery instance)653     public static ShadowGallery shadowOf(Gallery instance) {
654         return (ShadowGallery) shadowOf_(instance);
655     }
656 
shadowOf(Geocoder instance)657     public static ShadowGeocoder shadowOf(Geocoder instance) {
658         return (ShadowGeocoder) shadowOf_(instance);
659     }
660 
shadowOf(GridView instance)661     public static ShadowGridView shadowOf(GridView instance) {
662         return (ShadowGridView) shadowOf_(instance);
663     }
664 
shadowOf(Handler instance)665     public static ShadowHandler shadowOf(Handler instance) {
666         return (ShadowHandler) shadowOf_(instance);
667     }
668 
shadowOf(HandlerThread instance)669     public static ShadowHandlerThread shadowOf(HandlerThread instance) {
670         return (ShadowHandlerThread) shadowOf_(instance);
671     }
672 
shadowOf(ImageView instance)673     public static ShadowImageView shadowOf(ImageView instance) {
674         return (ShadowImageView) shadowOf_(instance);
675     }
676 
shadowOf(InputMethodManager instance)677     public static ShadowInputMethodManager shadowOf(InputMethodManager instance) {
678         return (ShadowInputMethodManager) shadowOf_(instance);
679     }
680 
shadowOf(Intent instance)681     public static ShadowIntent shadowOf(Intent instance) {
682         return (ShadowIntent) shadowOf_(instance);
683     }
684 
shadowOf(JsPromptResult instance)685     public static ShadowJsPromptResult shadowOf(JsPromptResult instance) {
686         return (ShadowJsPromptResult) shadowOf_(instance);
687     }
688 
shadowOf(JsResult instance)689     public static ShadowJsResult shadowOf(JsResult instance) {
690         return (ShadowJsResult) shadowOf_(instance);
691     }
692 
shadowOf(KeyguardManager instance)693     public static ShadowKeyguardManager shadowOf(KeyguardManager instance) {
694         return (ShadowKeyguardManager) shadowOf_(instance);
695     }
696 
shadowOf(KeyguardManager.KeyguardLock instance)697     public static ShadowKeyGuardLock shadowOf(KeyguardManager.KeyguardLock instance) {
698         return (ShadowKeyGuardLock) shadowOf_(instance);
699     }
700 
shadowOf(LayerDrawable instance)701     public static ShadowLayerDrawable shadowOf(LayerDrawable instance) {
702         return (ShadowLayerDrawable) shadowOf_(instance);
703     }
704 
shadowOf(LayoutInflater instance)705     public static ShadowLayoutInflater shadowOf(LayoutInflater instance) {
706         return (ShadowLayoutInflater) shadowOf_(instance);
707     }
708 
shadowOf(ListActivity instance)709     public static ShadowListActivity shadowOf(ListActivity instance) {
710         return (ShadowListActivity) shadowOf_(instance);
711     }
712 
shadowOf(ListFragment instance)713     public static ShadowListFragment shadowOf(ListFragment instance) {
714         return (ShadowListFragment) shadowOf_(instance);
715     }
716 
shadowOf(ListPreference instance)717     public static ShadowListPreference shadowOf(ListPreference instance) {
718         return (ShadowListPreference) shadowOf_(instance);
719     }
720 
shadowOf(ListView instance)721     public static ShadowListView shadowOf(ListView instance) {
722         return (ShadowListView) shadowOf_(instance);
723     }
724 
shadowOf(LocationManager instance)725     public static ShadowLocationManager shadowOf(LocationManager instance) {
726         return (ShadowLocationManager) shadowOf_(instance);
727     }
728 
shadowOf(Looper instance)729     public static ShadowLooper shadowOf(Looper instance) {
730         return (ShadowLooper) shadowOf_(instance);
731     }
732 
shadowOf(Matrix other)733     public static ShadowMatrix shadowOf(Matrix other) {
734         return (ShadowMatrix) Robolectric.shadowOf_(other);
735     }
736 
shadowOf(MediaPlayer instance)737     public static ShadowMediaPlayer shadowOf(MediaPlayer instance) {
738         return (ShadowMediaPlayer) shadowOf_(instance);
739     }
740 
shadowOf(MediaRecorder instance)741     public static ShadowMediaRecorder shadowOf(MediaRecorder instance) {
742         return (ShadowMediaRecorder) shadowOf_(instance);
743     }
744 
shadowOf(MenuInflater instance)745     public static ShadowMenuInflater shadowOf(MenuInflater instance) {
746         return (ShadowMenuInflater) shadowOf_(instance);
747     }
748 
shadowOf(Message instance)749     public static ShadowMessage shadowOf(Message instance) {
750         return (ShadowMessage) shadowOf_(instance);
751     }
752 
shadowOf(MimeTypeMap instance)753     public static ShadowMimeTypeMap shadowOf(MimeTypeMap instance) {
754         return (ShadowMimeTypeMap) shadowOf_(instance);
755     }
756 
shadowOf(MotionEvent other)757     public static ShadowMotionEvent shadowOf(MotionEvent other) {
758         return (ShadowMotionEvent) Robolectric.shadowOf_(other);
759     }
760 
shadowOf(NetworkInfo instance)761     public static ShadowNetworkInfo shadowOf(NetworkInfo instance) {
762         return (ShadowNetworkInfo) shadowOf_(instance);
763     }
764 
shadowOf(Notification other)765     public static ShadowNotification shadowOf(Notification other) {
766         return (ShadowNotification) Robolectric.shadowOf_(other);
767     }
768 
shadowOf(NotificationManager other)769     public static ShadowNotificationManager shadowOf(NotificationManager other) {
770         return (ShadowNotificationManager) Robolectric.shadowOf_(other);
771     }
772 
shadowOf(PagerAdapter instance)773     public static ShadowPagerAdapter shadowOf(PagerAdapter instance) {
774         return (ShadowPagerAdapter) shadowOf_(instance);
775     }
776 
shadowOf(Paint instance)777     public static ShadowPaint shadowOf(Paint instance) {
778         return (ShadowPaint) shadowOf_(instance);
779     }
780 
shadowOf(Parcel instance)781     public static ShadowParcel shadowOf(Parcel instance) {
782         return (ShadowParcel) shadowOf_(instance);
783     }
784 
shadowOf(PasswordTransformationMethod instance)785     public static ShadowPasswordTransformationMethod shadowOf(PasswordTransformationMethod instance) {
786         return (ShadowPasswordTransformationMethod) shadowOf_(instance);
787     }
788 
shadowOf(Path instance)789     public static ShadowPath shadowOf(Path instance) {
790         return (ShadowPath) shadowOf_(instance);
791     }
792 
shadowOf(PendingIntent instance)793     public static ShadowPendingIntent shadowOf(PendingIntent instance) {
794         return (ShadowPendingIntent) shadowOf_(instance);
795     }
796 
shadowOf(PhoneNumberUtils instance)797     public static ShadowPhoneNumberUtils shadowOf(PhoneNumberUtils instance) {
798         return (ShadowPhoneNumberUtils) shadowOf_(instance);
799     }
800 
shadowOf(PopupWindow instance)801     public static ShadowPopupWindow shadowOf(PopupWindow instance) {
802         return (ShadowPopupWindow) shadowOf_(instance);
803     }
804 
shadowOf(PowerManager instance)805     public static ShadowPowerManager shadowOf(PowerManager instance) {
806         return (ShadowPowerManager) shadowOf_(instance);
807     }
808 
shadowOf(Preference instance)809     public static ShadowPreference shadowOf(Preference instance) {
810         return (ShadowPreference) shadowOf_(instance);
811     }
812 
shadowOf(PreferenceActivity instance)813     public static ShadowPreferenceActivity shadowOf(PreferenceActivity instance) {
814         return (ShadowPreferenceActivity) shadowOf_(instance);
815     }
816 
shadowOf(PreferenceCategory instance)817     public static ShadowPreferenceCategory shadowOf(PreferenceCategory instance) {
818         return (ShadowPreferenceCategory) shadowOf_(instance);
819     }
820 
shadowOf(PreferenceGroup instance)821     public static ShadowPreferenceGroup shadowOf(PreferenceGroup instance) {
822         return (ShadowPreferenceGroup) shadowOf_(instance);
823     }
824 
shadowOf(PreferenceScreen instance)825     public static ShadowPreferenceScreen shadowOf(PreferenceScreen instance) {
826         return (ShadowPreferenceScreen) shadowOf_(instance);
827     }
828 
shadowOf(ProgressBar instance)829     public static ShadowProgressBar shadowOf(ProgressBar instance) {
830         return (ShadowProgressBar) shadowOf_(instance);
831     }
832 
shadowOf(ProgressDialog instance)833     public static ShadowProgressDialog shadowOf(ProgressDialog instance) {
834         return (ShadowProgressDialog) shadowOf_(instance);
835     }
836 
shadowOf(Rect instance)837     public static ShadowRect shadowOf(Rect instance) {
838         return (ShadowRect) shadowOf_(instance);
839     }
840 
shadowOf(RatingBar instance)841     public static ShadowRatingBar shadowOf(RatingBar instance) {
842         return (ShadowRatingBar) shadowOf_(instance);
843     }
844 
shadowOf(RemoteViews instance)845     public static ShadowRemoteViews shadowOf(RemoteViews instance) {
846         return (ShadowRemoteViews) shadowOf_(instance);
847     }
848 
shadowOf(ResolveInfo instance)849     public static ShadowResolveInfo shadowOf(ResolveInfo instance) {
850         return (ShadowResolveInfo) shadowOf_(instance);
851     }
852 
shadowOf(ResourceCursorAdapter instance)853     public static ShadowResourceCursorAdapter shadowOf(ResourceCursorAdapter instance) {
854         return (ShadowResourceCursorAdapter) shadowOf_(instance);
855     }
856 
shadowOf(Resources instance)857     public static ShadowResources shadowOf(Resources instance) {
858         return (ShadowResources) shadowOf_(instance);
859     }
860 
shadowOf(ResultReceiver instance)861     public static ShadowResultReceiver shadowOf(ResultReceiver instance) {
862         return (ShadowResultReceiver) shadowOf_(instance);
863     }
864 
shadowOf(ScanResult instance)865     public static ShadowScanResult shadowOf(ScanResult instance) {
866         return (ShadowScanResult) shadowOf_(instance);
867     }
868 
shadowOf(ScrollView instance)869     public static ShadowScrollView shadowOf(ScrollView instance) {
870         return (ShadowScrollView) shadowOf_(instance);
871     }
872 
shadowOf(SeekBar instance)873     public static ShadowSeekBar shadowOf(SeekBar instance) {
874         return (ShadowSeekBar) shadowOf_(instance);
875     }
876 
shadowOf(SensorManager instance)877     public static ShadowSensorManager shadowOf(SensorManager instance) {
878         return (ShadowSensorManager) shadowOf_(instance);
879     }
880 
shadowOf(Service instance)881     public static ShadowService shadowOf(Service instance) {
882         return (ShadowService) shadowOf_(instance);
883     }
884 
shadowOf(ShapeDrawable instance)885     public static ShadowShapeDrawable shadowOf(ShapeDrawable instance) {
886         return (ShadowShapeDrawable) shadowOf_(instance);
887     }
888 
shadowOf(Signature instance)889     public static ShadowSignature shadowOf(Signature instance) {
890         return (ShadowSignature) shadowOf_(instance);
891     }
892 
shadowOf(SimpleCursorAdapter instance)893     public static ShadowSimpleCursorAdapter shadowOf(SimpleCursorAdapter instance) {
894         return (ShadowSimpleCursorAdapter) shadowOf_(instance);
895     }
896 
shadowOf(SmsManager instance)897     public static ShadowSmsManager shadowOf(SmsManager instance) {
898         return (ShadowSmsManager) shadowOf_(instance);
899     }
900 
shadowOf(SparseArray<E> other)901     public static <E> ShadowSparseArray<E> shadowOf(SparseArray<E> other) {
902         //noinspection unchecked
903         return (ShadowSparseArray<E>) Robolectric.shadowOf_(other);
904     }
905 
shadowOf(SparseBooleanArray other)906     public static ShadowSparseBooleanArray shadowOf(SparseBooleanArray other) {
907         return (ShadowSparseBooleanArray) Robolectric.shadowOf_(other);
908     }
909 
shadowOf(SparseIntArray other)910     public static ShadowSparseIntArray shadowOf(SparseIntArray other){
911     	return (ShadowSparseIntArray) Robolectric.shadowOf_( other );
912     }
913 
shadowOf(SQLiteCursor other)914     public static ShadowSQLiteCursor shadowOf(SQLiteCursor other) {
915         return (ShadowSQLiteCursor) Robolectric.shadowOf_(other);
916     }
917 
shadowOf(SQLiteDatabase other)918     public static ShadowSQLiteDatabase shadowOf(SQLiteDatabase other) {
919         return (ShadowSQLiteDatabase) Robolectric.shadowOf_(other);
920     }
921 
shadowOf(SQLiteOpenHelper other)922     public static ShadowSQLiteOpenHelper shadowOf(SQLiteOpenHelper other) {
923         return (ShadowSQLiteOpenHelper) Robolectric.shadowOf_(other);
924     }
925 
shadowOf(SQLiteProgram other)926     public static ShadowSQLiteProgram shadowOf(SQLiteProgram other) {
927         return (ShadowSQLiteProgram) Robolectric.shadowOf_(other);
928     }
929 
shadowOf(SQLiteQueryBuilder other)930     public static ShadowSQLiteQueryBuilder shadowOf(SQLiteQueryBuilder other) {
931         return (ShadowSQLiteQueryBuilder) Robolectric.shadowOf_(other);
932     }
933 
shadowOf(SQLiteStatement other)934     public static ShadowSQLiteStatement shadowOf(SQLiteStatement other) {
935         return (ShadowSQLiteStatement) Robolectric.shadowOf_(other);
936     }
937 
shadowOf(SslErrorHandler instance)938     public static ShadowSslErrorHandler shadowOf(SslErrorHandler instance) {
939         return (ShadowSslErrorHandler) shadowOf_(instance);
940     }
941 
shadowOf(StateListDrawable instance)942     public static ShadowStateListDrawable shadowOf(StateListDrawable instance) {
943         return (ShadowStateListDrawable) shadowOf_(instance);
944     }
945 
shadowOf(TabHost instance)946     public static ShadowTabHost shadowOf(TabHost instance) {
947         return (ShadowTabHost) shadowOf_(instance);
948     }
949 
shadowOf(TabHost.TabSpec instance)950     public static ShadowTabSpec shadowOf(TabHost.TabSpec instance) {
951         return (ShadowTabSpec) shadowOf_(instance);
952     }
953 
shadowOf(TelephonyManager instance)954     public static ShadowTelephonyManager shadowOf(TelephonyManager instance) {
955         return (ShadowTelephonyManager) shadowOf_(instance);
956     }
957 
shadowOf(TextPaint instance)958     public static ShadowTextPaint shadowOf(TextPaint instance) {
959         return (ShadowTextPaint) shadowOf_(instance);
960     }
961 
shadowOf(TextView instance)962     public static ShadowTextView shadowOf(TextView instance) {
963         return (ShadowTextView) shadowOf_(instance);
964     }
965 
shadowOf(Toast instance)966     public static ShadowToast shadowOf(Toast instance) {
967         return (ShadowToast) shadowOf_(instance);
968     }
969 
shadowOf(TranslateAnimation instance)970     public static ShadowTranslateAnimation shadowOf(TranslateAnimation instance) {
971         return (ShadowTranslateAnimation) shadowOf_(instance);
972     }
973 
shadowOf(UriMatcher instance)974     public static ShadowUriMatcher shadowOf(UriMatcher instance) {
975         return (ShadowUriMatcher) shadowOf_(instance);
976     }
977 
shadowOf(View instance)978     public static ShadowView shadowOf(View instance) {
979         return (ShadowView) shadowOf_(instance);
980     }
981 
shadowOf(ViewAnimator instance)982     public static ShadowViewAnimator shadowOf(ViewAnimator instance) {
983         return (ShadowViewAnimator) shadowOf_(instance);
984     }
985 
shadowOf(ViewConfiguration instance)986     public static ShadowViewConfiguration shadowOf(ViewConfiguration instance) {
987         return (ShadowViewConfiguration) shadowOf_(instance);
988     }
989 
shadowOf(ViewFlipper instance)990     public static ShadowViewFlipper shadowOf(ViewFlipper instance) {
991         return (ShadowViewFlipper) shadowOf_(instance);
992     }
993 
shadowOf(ViewPager instance)994     public static ShadowViewPager shadowOf(ViewPager instance) {
995         return (ShadowViewPager) shadowOf_(instance);
996     }
997 
shadowOf(ViewTreeObserver instance)998     public static ShadowViewTreeObserver shadowOf(ViewTreeObserver instance) {
999         return (ShadowViewTreeObserver) shadowOf_(instance);
1000     }
1001 
shadowOf(ViewGroup instance)1002     public static ShadowViewGroup shadowOf(ViewGroup instance) {
1003         return (ShadowViewGroup) shadowOf_(instance);
1004     }
1005 
shadowOf(Vibrator instance)1006     public static ShadowVibrator shadowOf(Vibrator instance) {
1007         return (ShadowVibrator) shadowOf_(instance);
1008     }
1009 
shadowOf(VideoView instance)1010     public static ShadowVideoView shadowOf(VideoView instance) {
1011         return (ShadowVideoView) shadowOf_(instance);
1012     }
1013 
shadowOf(WebView instance)1014     public static ShadowWebView shadowOf(WebView instance) {
1015         return (ShadowWebView) shadowOf_(instance);
1016     }
1017 
shadowOf(WifiConfiguration instance)1018     public static ShadowWifiConfiguration shadowOf(WifiConfiguration instance) {
1019         return (ShadowWifiConfiguration) shadowOf_(instance);
1020     }
1021 
shadowOf(WifiInfo instance)1022     public static ShadowWifiInfo shadowOf(WifiInfo instance) {
1023         return (ShadowWifiInfo) shadowOf_(instance);
1024     }
1025 
shadowOf(WifiManager instance)1026     public static ShadowWifiManager shadowOf(WifiManager instance) {
1027         return (ShadowWifiManager) shadowOf_(instance);
1028     }
1029 
shadowOf(ZoomButtonsController instance)1030     public static ShadowZoomButtonsController shadowOf(ZoomButtonsController instance) {
1031         return (ShadowZoomButtonsController) shadowOf_(instance);
1032     }
1033 
shadowOf(Theme instance)1034     public static ShadowTheme shadowOf(Theme instance) {
1035         return (ShadowTheme) shadowOf_(instance);
1036     }
1037 
1038     @SuppressWarnings({"unchecked"})
shadowOf_(R instance)1039     public static <P, R> P shadowOf_(R instance) {
1040         return (P) ShadowWrangler.getInstance().shadowOf(instance);
1041     }
1042 
1043     /**
1044      * Runs any background tasks previously queued by {@link android.os.AsyncTask#execute(Object[])}.
1045      * <p/>
1046      * <p/>
1047      * Note: calling this method does not pause or un-pause the scheduler.
1048      */
runBackgroundTasks()1049     public static void runBackgroundTasks() {
1050         getBackgroundScheduler().advanceBy(0);
1051     }
1052 
1053     /**
1054      * Runs any immediately runnable tasks previously queued on the UI thread,
1055      * e.g. by {@link Activity#runOnUiThread(Runnable)} or {@link android.os.AsyncTask#onPostExecute(Object)}.
1056      * <p/>
1057      * <p/>
1058      * Note: calling this method does not pause or un-pause the scheduler.
1059      */
runUiThreadTasks()1060     public static void runUiThreadTasks() {
1061         getUiThreadScheduler().advanceBy(0);
1062     }
1063 
runUiThreadTasksIncludingDelayedTasks()1064     public static void runUiThreadTasksIncludingDelayedTasks() {
1065         getUiThreadScheduler().advanceToLastPostedRunnable();
1066     }
1067 
1068     /**
1069      * Sets up an HTTP response to be returned by calls to Apache's {@code HttpClient} implementers.
1070      *
1071      * @param statusCode   the status code of the response
1072      * @param responseBody the body of the response
1073      * @param headers      optional headers for the request
1074      */
addPendingHttpResponse(int statusCode, String responseBody, Header... headers)1075     public static void addPendingHttpResponse(int statusCode, String responseBody, Header... headers) {
1076         getFakeHttpLayer().addPendingHttpResponse(statusCode, responseBody, headers);
1077     }
1078 
1079     /**
1080      * Sets up an HTTP response to be returned by calls to Apache's {@code HttpClient} implementers.
1081      *
1082      * @param statusCode   the status code of the response
1083      * @param responseBody the body of the response
1084      * @param contentType  the contentType of the response
1085      * @deprecated use {@link #addPendingHttpResponse(int, String, Header...)} instead
1086      */
1087     @Deprecated
addPendingHttpResponseWithContentType(int statusCode, String responseBody, Header contentType)1088     public static void addPendingHttpResponseWithContentType(int statusCode, String responseBody, Header contentType) {
1089         getFakeHttpLayer().addPendingHttpResponse(statusCode, responseBody, contentType);
1090     }
1091 
1092     /**
1093      * Sets up an HTTP response to be returned by calls to Apache's {@code HttpClient} implementers.
1094      *
1095      * @param httpResponse the response
1096      */
addPendingHttpResponse(HttpResponse httpResponse)1097     public static void addPendingHttpResponse(HttpResponse httpResponse) {
1098         getFakeHttpLayer().addPendingHttpResponse(httpResponse);
1099     }
1100 
1101     /**
1102      * Sets up an HTTP response to be returned by calls to Apache's {@code HttpClient} implementers.
1103      *
1104      * @param httpResponseGenerator an HttpResponseGenerator that will provide responses
1105      */
addPendingHttpResponse(HttpResponseGenerator httpResponseGenerator)1106     public static void addPendingHttpResponse(HttpResponseGenerator httpResponseGenerator) {
1107         getFakeHttpLayer().addPendingHttpResponse(httpResponseGenerator);
1108     }
1109 
1110     /**
1111      * Accessor to obtain HTTP requests made during the current test in the order in which they were made.
1112      *
1113      * @param index index of the request to retrieve.
1114      * @return the requested request.
1115      */
getSentHttpRequest(int index)1116     public static HttpRequest getSentHttpRequest(int index) {
1117         return ShadowDefaultRequestDirector.getSentHttpRequest(index);
1118     }
1119 
getLatestSentHttpRequest()1120     public static HttpRequest getLatestSentHttpRequest() {
1121         return ShadowDefaultRequestDirector.getLatestSentHttpRequest();
1122     }
1123 
1124     /**
1125      * Accessor to find out if HTTP requests were made during the current test.
1126      *
1127      * @return whether a request was made.
1128      */
httpRequestWasMade()1129     public static boolean httpRequestWasMade() {
1130         return getShadowApplication().getFakeHttpLayer().hasRequestInfos();
1131     }
1132 
httpRequestWasMade(String uri)1133     public static boolean httpRequestWasMade(String uri) {
1134         return getShadowApplication().getFakeHttpLayer().hasRequestMatchingRule(new FakeHttpLayer.UriRequestMatcher(uri));
1135     }
1136 
1137     /**
1138      * Accessor to obtain metadata for an HTTP request made during the current test in the order in which they were made.
1139      *
1140      * @param index index of the request to retrieve.
1141      * @return the requested request metadata.
1142      */
getSentHttpRequestInfo(int index)1143     public static HttpRequestInfo getSentHttpRequestInfo(int index) {
1144         return ShadowDefaultRequestDirector.getSentHttpRequestInfo(index);
1145     }
1146 
1147     /**
1148      * Adds an HTTP response rule. The response will be returned when the rule is matched.
1149      *
1150      * @param method   method to match.
1151      * @param uri      uri to match.
1152      * @param response response to return when a match is found.
1153      */
addHttpResponseRule(String method, String uri, HttpResponse response)1154     public static void addHttpResponseRule(String method, String uri, HttpResponse response) {
1155         getFakeHttpLayer().addHttpResponseRule(method, uri, response);
1156     }
1157 
1158     /**
1159      * Adds an HTTP response rule with a default method of GET. The response will be returned when the rule is matched.
1160      *
1161      * @param uri      uri to match.
1162      * @param response response to return when a match is found.
1163      */
addHttpResponseRule(String uri, HttpResponse response)1164     public static void addHttpResponseRule(String uri, HttpResponse response) {
1165         getFakeHttpLayer().addHttpResponseRule(uri, response);
1166     }
1167 
1168     /**
1169      * Adds an HTTP response rule. The response will be returned when the rule is matched.
1170      *
1171      * @param uri      uri to match.
1172      * @param response response to return when a match is found.
1173      */
addHttpResponseRule(String uri, String response)1174     public static void addHttpResponseRule(String uri, String response) {
1175         getFakeHttpLayer().addHttpResponseRule(uri, response);
1176     }
1177 
1178     /**
1179      * Adds an HTTP response rule. The response will be returned when the rule is matched.
1180      *
1181      * @param requestMatcher custom {@code RequestMatcher}.
1182      * @param response       response to return when a match is found.
1183      */
addHttpResponseRule(RequestMatcher requestMatcher, HttpResponse response)1184     public static void addHttpResponseRule(RequestMatcher requestMatcher, HttpResponse response) {
1185         getFakeHttpLayer().addHttpResponseRule(requestMatcher, response);
1186     }
1187 
1188     /**
1189      * Adds an HTTP response rule. For each time the rule is matched, responses will be shifted
1190      * off the list and returned. When all responses have been given and the rule is matched again,
1191      * an exception will be thrown.
1192      *
1193      * @param requestMatcher custom {@code RequestMatcher}.
1194      * @param responses      responses to return in order when a match is found.
1195      */
addHttpResponseRule(RequestMatcher requestMatcher, List<? extends HttpResponse> responses)1196     public static void addHttpResponseRule(RequestMatcher requestMatcher, List<? extends HttpResponse> responses) {
1197         getFakeHttpLayer().addHttpResponseRule(requestMatcher, responses);
1198     }
1199 
getFakeHttpLayer()1200     public static FakeHttpLayer getFakeHttpLayer() {
1201         return getShadowApplication().getFakeHttpLayer();
1202     }
1203 
setDefaultHttpResponse(int statusCode, String responseBody)1204     public static void setDefaultHttpResponse(int statusCode, String responseBody) {
1205         getFakeHttpLayer().setDefaultHttpResponse(statusCode, responseBody);
1206     }
1207 
setDefaultHttpResponse(HttpResponse defaultHttpResponse)1208     public static void setDefaultHttpResponse(HttpResponse defaultHttpResponse) {
1209         getFakeHttpLayer().setDefaultHttpResponse(defaultHttpResponse);
1210     }
1211 
clearHttpResponseRules()1212     public static void clearHttpResponseRules() {
1213         getFakeHttpLayer().clearHttpResponseRules();
1214     }
1215 
clearPendingHttpResponses()1216     public static void clearPendingHttpResponses() {
1217         getFakeHttpLayer().clearPendingHttpResponses();
1218     }
1219 
pauseLooper(Looper looper)1220     public static void pauseLooper(Looper looper) {
1221         ShadowLooper.pauseLooper(looper);
1222     }
1223 
unPauseLooper(Looper looper)1224     public static void unPauseLooper(Looper looper) {
1225         ShadowLooper.unPauseLooper(looper);
1226     }
1227 
pauseMainLooper()1228     public static void pauseMainLooper() {
1229         ShadowLooper.pauseMainLooper();
1230     }
1231 
unPauseMainLooper()1232     public static void unPauseMainLooper() {
1233         ShadowLooper.unPauseMainLooper();
1234     }
1235 
idleMainLooper(long interval)1236     public static void idleMainLooper(long interval) {
1237         ShadowLooper.idleMainLooper(interval);
1238     }
1239 
getUiThreadScheduler()1240     public static Scheduler getUiThreadScheduler() {
1241         return shadowOf(Looper.getMainLooper()).getScheduler();
1242     }
1243 
getBackgroundScheduler()1244     public static Scheduler getBackgroundScheduler() {
1245         return getShadowApplication().getBackgroundScheduler();
1246     }
1247 
getShadowApplication()1248     public static ShadowApplication getShadowApplication() {
1249         return shadowOf(Robolectric.application);
1250     }
1251 
setDisplayMetricsDensity(float densityMultiplier)1252     public static void setDisplayMetricsDensity(float densityMultiplier) {
1253         shadowOf(getShadowApplication().getResources()).setDensity(densityMultiplier);
1254     }
1255 
setDefaultDisplay(Display display)1256     public static void setDefaultDisplay(Display display) {
1257         shadowOf(getShadowApplication().getResources()).setDisplay(display);
1258     }
1259 
1260     /**
1261      * Calls {@code performClick()} on a {@code View} after ensuring that it and its ancestors are visible and that it
1262      * is enabled.
1263      *
1264      * @param view the view to click on
1265      * @return true if {@code View.OnClickListener}s were found and fired, false otherwise.
1266      * @throws RuntimeException if the preconditions are not met.
1267      */
clickOn(View view)1268     public static boolean clickOn(View view) {
1269         return shadowOf(view).checkedPerformClick();
1270     }
1271 
visualize(View view)1272     public static String visualize(View view) {
1273         Canvas canvas = new Canvas();
1274         view.draw(canvas);
1275         return shadowOf(canvas).getDescription();
1276     }
1277 
visualize(Canvas canvas)1278     public static String visualize(Canvas canvas) {
1279         return shadowOf(canvas).getDescription();
1280     }
1281 
visualize(Bitmap bitmap)1282     public static String visualize(Bitmap bitmap) {
1283         return shadowOf(bitmap).getDescription();
1284     }
1285 
1286     /**
1287      * Reflection helper methods.
1288      */
1289     public static class Reflection {
newInstanceOf(Class<T> clazz)1290         public static <T> T newInstanceOf(Class<T> clazz) {
1291             return Robolectric.newInstanceOf(clazz);
1292         }
1293 
newInstanceOf(String className)1294         public static Object newInstanceOf(String className) {
1295             return Robolectric.newInstanceOf(className);
1296         }
1297 
setFinalStaticField(Class classWhichContainsField, String fieldName, Object newValue)1298         public static void setFinalStaticField(Class classWhichContainsField, String fieldName, Object newValue) {
1299             try {
1300                 Field field = classWhichContainsField.getDeclaredField(fieldName);
1301                 field.setAccessible(true);
1302 
1303                 Field modifiersField = Field.class.getDeclaredField("modifiers");
1304                 modifiersField.setAccessible(true);
1305                 modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
1306 
1307                 field.set(null, newValue);
1308             } catch (NoSuchFieldException e) {
1309                 throw new RuntimeException(e);
1310             } catch (IllegalAccessException e) {
1311                 throw new RuntimeException(e);
1312             }
1313         }
1314     }
1315 
1316 }
1317