Java Code Examples for org.robolectric.shadow.api.Shadow#extract()
The following examples show how to use
org.robolectric.shadow.api.Shadow#extract() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FragmentsSelectTest.java From itag with GNU General Public License v3.0 | 6 votes |
@Before public void setupActivity() { Application application = ApplicationProvider.getApplicationContext(); ShadowApplication shadowApplication = shadowOf(application); shadowApplication.grantPermissions(Manifest.permission.ACCESS_FINE_LOCATION); Intent intent = new Intent(application, ITagsService.class); ITagsService iTagsService = new ITagsService(); shadowApplication.setComponentNameAndServiceForBindServiceForIntent( intent, new ComponentName(ITagApplication.class.getPackage().getName(),ITagsService.class.getName()), iTagsService.onBind(null) ); mockBluetoothManager = Mockito.mock(BluetoothManager.class); ShadowContextImpl shadowContext = Shadow.extract(application.getBaseContext()); shadowContext.setSystemService(Context.BLUETOOTH_SERVICE, mockBluetoothManager); }
Example 2
Source File: WebFragmentTest.java From materialistic with Apache License 2.0 | 6 votes |
@SuppressLint("NewApi") @Test public void testWebControls() { LocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); ShadowWebView shadowWebView = Shadow.extract(activity.findViewById(R.id.web_view)); activity.findViewById(R.id.button_more).performClick(); shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_zoom_in)); assertThat(shadowWebView.getZoomDegree()).isEqualTo(1); activity.findViewById(R.id.button_more).performClick(); shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_zoom_out)); assertThat(shadowWebView.getZoomDegree()).isEqualTo(0); activity.findViewById(R.id.button_forward).performClick(); assertThat(shadowWebView.getPageIndex()).isEqualTo(1); activity.findViewById(R.id.button_back).performClick(); assertThat(shadowWebView.getPageIndex()).isEqualTo(0); }
Example 3
Source File: WebFragmentTest.java From materialistic with Apache License 2.0 | 6 votes |
@Test public void testDownloadPdf() { ResolveInfo resolverInfo = new ResolveInfo(); resolverInfo.activityInfo = new ActivityInfo(); resolverInfo.activityInfo.applicationInfo = new ApplicationInfo(); resolverInfo.activityInfo.applicationInfo.packageName = ListActivity.class.getPackage().getName(); resolverInfo.activityInfo.name = ListActivity.class.getName(); ShadowPackageManager rpm = shadowOf(RuntimeEnvironment.application.getPackageManager()); when(item.getUrl()).thenReturn("http://example.com/file.pdf"); rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(item.getUrl())), resolverInfo); WebView webView = activity.findViewById(R.id.web_view); ShadowWebView shadowWebView = Shadow.extract(webView); WebFragment fragment = (WebFragment) activity.getSupportFragmentManager() .findFragmentByTag(WebFragment.class.getName()); shadowWebView.getDownloadListener().onDownloadStart(item.getUrl(), "", "", "application/pdf", 0L); shadowWebView.getWebViewClient().onPageFinished(webView, PDF_LOADER_URL); verify(fragment.mFileDownloader).downloadFile( eq(item.getUrl()), eq("application/pdf"), any(FileDownloader.FileDownloaderCallback.class)); }
Example 4
Source File: WebFragmentTest.java From materialistic with Apache License 2.0 | 6 votes |
@Test public void testDownloadContent() { ResolveInfo resolverInfo = new ResolveInfo(); resolverInfo.activityInfo = new ActivityInfo(); resolverInfo.activityInfo.applicationInfo = new ApplicationInfo(); resolverInfo.activityInfo.applicationInfo.packageName = ListActivity.class.getPackage().getName(); resolverInfo.activityInfo.name = ListActivity.class.getName(); ShadowPackageManager rpm = shadowOf(RuntimeEnvironment.application.getPackageManager()); final String url = "http://example.com/file.doc"; rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), resolverInfo); WebView webView = activity.findViewById(R.id.web_view); ShadowWebView shadowWebView = Shadow.extract(webView); when(item.getUrl()).thenReturn(url); shadowWebView.getDownloadListener().onDownloadStart(url, "", "", "", 0L); assertThat((View) activity.findViewById(R.id.empty)).isVisible(); activity.findViewById(R.id.download_button).performClick(); assertNotNull(shadowOf(activity).getNextStartedActivity()); }
Example 5
Source File: AnimationViewBehaviorTest.java From simple-view-behavior with MIT License | 6 votes |
@Test public void animations() { ScaleAnimation animation = new ScaleAnimation(1f, 0f, 1f, 0f); AnimationViewBehavior behavior = new AnimationViewBehavior.Builder() .dependsOn(firstView.getId(), SimpleViewBehavior.DEPEND_TYPE_Y) .targetValue(100) .animation(animation) .build(); CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(320, 200); params.setBehavior(behavior); secondView.setLayoutParams(params); ShadowAnimation shadowAnimation = Shadow.extract(animation); firstView.setY(50); coordinatorLayout.requestLayout(); assertEquals(500L, shadowAnimation.getLastTimeGetTransform()); firstView.setY(100); coordinatorLayout.requestLayout(); assertEquals(1000L, shadowAnimation.getLastTimeGetTransform()); }
Example 6
Source File: WebFragmentTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testFullScroll() { LocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); ShadowWebView shadowWebView = Shadow.extract(activity.findViewById(R.id.web_view)); WebFragment fragment = (WebFragment) activity.getSupportFragmentManager() .findFragmentByTag(WebFragment.class.getName()); fragment.scrollToTop(); assertEquals(0, shadowWebView.getScrollY()); fragment.scrollToNext(); assertEquals(1, shadowWebView.getScrollY()); fragment.scrollToPrevious(); assertEquals(0, shadowWebView.getScrollY()); }
Example 7
Source File: BluetoothDeviceShadow.java From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * open a connection with the device the returning connection is a shadow object that can be * queue with the mockito framework * @param c * @param b * @param callback * @return */ @Implementation public BluetoothGatt connectGatt(Context c,boolean b,BluetoothGattCallback callback){ mGattConnection = spy(Shadow.newInstanceOf(BluetoothGatt.class)); BluetoothGattShadow shadowGatt = Shadow.extract(mGattConnection); shadowGatt.setGattCallBack(callback); shadowGatt.setServices(mServices); mGattConnection.connect(); return mGattConnection; }
Example 8
Source File: WebFragmentTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testRefresh() { LocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); ShadowWebView.lastGlobalLoadedUrl = null; ShadowWebView shadowWebView = Shadow.extract(activity.findViewById(R.id.web_view)); shadowWebView.setProgress(20); activity.findViewById(R.id.button_refresh).performClick(); assertThat(ShadowWebView.getLastGlobalLoadedUrl()).isNullOrEmpty(); shadowWebView.setProgress(100); activity.findViewById(R.id.button_refresh).performClick(); assertThat(ShadowWebView.getLastGlobalLoadedUrl()).isEqualTo(ShadowWebView.RELOADED); }
Example 9
Source File: WebFragmentTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testSearch() { LocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); activity.findViewById(R.id.button_find).performClick(); ViewSwitcher controlSwitcher = activity.findViewById(R.id.control_switcher); assertThat(controlSwitcher.getDisplayedChild()).isEqualTo(1); ShadowWebView shadowWebView = Shadow.extract(activity.findViewById(R.id.web_view)); // no query EditText editText = activity.findViewById(R.id.edittext); shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null); assertThat((View) activity.findViewById(R.id.button_next)).isDisabled(); // with results shadowWebView.setFindCount(1); editText.setText("abc"); shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null); assertThat((View) activity.findViewById(R.id.button_next)).isEnabled(); activity.findViewById(R.id.button_next).performClick(); assertThat(shadowWebView.getFindIndex()).isEqualTo(1); activity.findViewById(R.id.button_clear).performClick(); assertThat(editText).isEmpty(); assertThat(controlSwitcher.getDisplayedChild()).isEqualTo(0); // with no results shadowWebView.setFindCount(0); editText.setText("abc"); shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null); assertThat((View) activity.findViewById(R.id.button_next)).isDisabled(); assertThat(ShadowToast.getTextOfLatestToast()).contains(activity.getString(R.string.no_matches)); }
Example 10
Source File: SnackbarTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Before public void createActivityAndShadow() { ApplicationProvider.getApplicationContext() .setTheme(R.style.Theme_MaterialComponents_Light_NoActionBar); activity = Robolectric.buildActivity(AppCompatActivity.class).create().get(); accessibilityManager = Shadow. extract(activity.getSystemService(Context.ACCESSIBILITY_SERVICE)); }
Example 11
Source File: NodeTest.java From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void connectNodeWithDebug(){ BluetoothDevice device = spy(Shadow.newInstanceOf(BluetoothDevice.class)); BluetoothDeviceShadow shadowDevice = Shadow.extract(device); BluetoothGattService debugService = new BluetoothGattService(BLENodeDefines.Services .Debug.DEBUG_SERVICE_UUID,BluetoothGattService.SERVICE_TYPE_PRIMARY); debugService.addCharacteristic( new BluetoothGattCharacteristic(BLENodeDefines.Services.Debug.DEBUG_STDERR_UUID, BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PERMISSION_WRITE, BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic .PROPERTY_NOTIFY)); debugService.addCharacteristic( new BluetoothGattCharacteristic(BLENodeDefines.Services.Debug.DEBUG_TERM_UUID, BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PERMISSION_WRITE, BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic .PROPERTY_NOTIFY) ); shadowDevice.addService(debugService); Node node = createNode(device); Assert.assertEquals(Node.State.Idle, node.getState()); node.connect(RuntimeEnvironment.application); TestUtil.execAllAsyncTask(); verify(device).connectGatt(eq(RuntimeEnvironment.application), eq(false), any(BluetoothGattCallback.class)); Assert.assertEquals(Node.State.Connected, node.getState()); Assert.assertTrue(node.getDebug()!=null); }
Example 12
Source File: NodeTest.java From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void enableDisableNotificationForFeature(){ SparseArray <Class <? extends Feature> > temp = new SparseArray<>(); temp.append(0x01,FakeFeature.class); try { Manager.addFeatureToNode((byte)0x00,temp); } catch (InvalidFeatureBitMaskException e) { Assert.fail("Impossible add the FakeFeature"); } BluetoothDevice device = spy(Shadow.newInstanceOf(BluetoothDevice.class)); BluetoothDeviceShadow shadowDevice = Shadow.extract(device); BluetoothGattService dataService = new BluetoothGattService( UUID.randomUUID(), BluetoothGattService.SERVICE_TYPE_PRIMARY); dataService.addCharacteristic(createReadNotifyChar( UUID.fromString("000000001-"+BLENodeDefines.FeatureCharacteristics.BASE_FEATURE_COMMON_UUID) )); shadowDevice.addService(dataService); Node n = createNode(device); n.connect(RuntimeEnvironment.application); TestUtil.execAllAsyncTask(); Feature f = n.getFeature(FakeFeature.class); Assert.assertFalse(n.isEnableNotification(f)); Assert.assertTrue(n.enableNotification(f)); Assert.assertTrue(n.isEnableNotification(f)); Assert.assertTrue(n.disableNotification(f)); Assert.assertFalse(n.isEnableNotification(f)); }
Example 13
Source File: MarkerTest.java From appinventor-extensions with Apache License 2.0 | 5 votes |
@Test public void testVisibleInvalidate() { ShadowMapView mapView = Shadow.extract(((ViewGroup) getMap().getView()).getChildAt(0)); Marker marker = new Marker(getMap()); mapView.clearWasInvalidated(); marker.Visible(true); marker.Visible(false); assertFalse(getMap().getController().isFeatureVisible(marker)); assertTrue(mapView.wasInvalidated()); }
Example 14
Source File: MarkerTest.java From appinventor-extensions with Apache License 2.0 | 5 votes |
@Test public void testVisibleNoInvalidate() { ShadowMapView mapView = Shadow.extract(((ViewGroup) getMap().getView()).getChildAt(0)); Marker marker = new Marker(getMap()); mapView.clearWasInvalidated(); marker.Visible(true); assertTrue(getMap().getController().isFeatureVisible(marker)); assertFalse(mapView.wasInvalidated()); // Marker is visible by default }
Example 15
Source File: ItemActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Config(shadows = {ShadowFloatingActionButton.class}) @Test public void testFullscreen() { Intent intent = new Intent(); WebItem webItem = new TestWebItem() { @Override public String getUrl() { return "http://example.com"; } @Override public String getId() { return "1"; } }; intent.putExtra(ItemActivity.EXTRA_ITEM, webItem); controller = Robolectric.buildActivity(ItemActivity.class, intent); controller.create().start().resume().visible(); activity = controller.get(); ShadowFloatingActionButton shadowFab = Shadow.extract(activity.findViewById(R.id.reply_button)); assertTrue(shadowFab.isVisible()); LocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); assertFalse(shadowFab.isVisible()); LocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, false)); assertTrue(shadowFab.isVisible()); }
Example 16
Source File: FeatureCollectionTest.java From appinventor-extensions with Apache License 2.0 | 5 votes |
@Test public void testFeatureSetter() { Marker marker = new Marker(getMap()); collection.removeFeature(marker); assertEquals(0, collection.Features().size()); ShadowView view = Shadow.extract(getMap().getView()); view.clearWasInvalidated(); collection.Features(YailList.makeList(Collections.singletonList(marker))); assertTrue(view.wasInvalidated()); assertEquals(1, collection.Features().size()); assertEquals(marker, collection.Features().get(1)); }
Example 17
Source File: MapTest.java From appinventor-extensions with Apache License 2.0 | 4 votes |
private static ShadowView shadowOf(View view) { return (ShadowView) Shadow.extract(view); }
Example 18
Source File: CustomShadows.java From materialistic with Apache License 2.0 | 4 votes |
public static ShadowRecyclerView customShadowOf(RecyclerView recyclerView) { return Shadow.extract(recyclerView); }
Example 19
Source File: ShadowJobParameters.java From JobSchedulerCompat with MIT License | 4 votes |
public static JobParameters newInstance(JobStatus jobStatus) { JobParameters jobParameters = Shadow.newInstanceOf(JobParameters.class); ShadowJobParameters shadowJobParameters = Shadow.extract(jobParameters); shadowJobParameters.setJobStatus(jobStatus); return jobParameters; }
Example 20
Source File: CustomShadows.java From materialistic with Apache License 2.0 | 4 votes |
public static ShadowRecyclerViewAdapter customShadowOf(RecyclerView.Adapter adapter) { return Shadow.extract(adapter); }