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