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