当前位置: 首页>>代码示例>>Java>>正文


Java ShadowExtractor类代码示例

本文整理汇总了Java中org.robolectric.internal.ShadowExtractor的典型用法代码示例。如果您正苦于以下问题:Java ShadowExtractor类的具体用法?Java ShadowExtractor怎么用?Java ShadowExtractor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ShadowExtractor类属于org.robolectric.internal包,在下文中一共展示了ShadowExtractor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRefresh

import org.robolectric.internal.ShadowExtractor; //导入依赖的package包/类
@Test
public void testRefresh() {
    Bundle args = new Bundle();
    args.putString(ListFragment.EXTRA_ITEM_MANAGER, HackerNewsClient.class.getName());
    args.putString(ListFragment.EXTRA_FILTER, ItemManager.TOP_FETCH_MODE);
    activity.getSupportFragmentManager()
            .beginTransaction()
            .add(android.R.id.list,
                    Fragment.instantiate(activity, ListFragment.class.getName(), args))
            .commit();
    ShadowSwipeRefreshLayout shadowSwipeRefreshLayout = (ShadowSwipeRefreshLayout)
            ShadowExtractor.extract(activity.findViewById(R.id.swipe_layout));
    shadowSwipeRefreshLayout.getOnRefreshListener().onRefresh();
    // should trigger another data request
    verify(itemManager).getStories(any(String.class),
            eq(ItemManager.MODE_DEFAULT),
            any(ResponseListener.class));
    verify(itemManager).getStories(any(String.class),
            eq(ItemManager.MODE_NETWORK),
            any(ResponseListener.class));
    controller.pause().stop().destroy();
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:23,代码来源:ListFragmentTest.java

示例2: testRefresh

import org.robolectric.internal.ShadowExtractor; //导入依赖的package包/类
@Test
public void testRefresh() {
    WebItem webItem = mock(WebItem.class);
    when(webItem.getId()).thenReturn("1");
    Bundle args = new Bundle();
    args.putParcelable(ItemFragment.EXTRA_ITEM, webItem);
    Fragment fragment = Fragment.instantiate(RuntimeEnvironment.application,
            ItemFragment.class.getName(), args);
    makeVisible(fragment);
    ShadowSwipeRefreshLayout shadowSwipeRefreshLayout = (ShadowSwipeRefreshLayout)
            ShadowExtractor.extract(fragment.getView().findViewById(R.id.swipe_layout));
    shadowSwipeRefreshLayout.getOnRefreshListener().onRefresh();
    verify(hackerNewsClient).getItem(eq("1"),
            eq(ItemManager.MODE_DEFAULT),
            listener.capture());
    verify(hackerNewsClient).getItem(eq("1"),
            eq(ItemManager.MODE_NETWORK),
            listener.capture());
    listener.getAllValues().get(1).onResponse(new TestHnItem(1L));
    assertThat((SwipeRefreshLayout) fragment.getView().findViewById(R.id.swipe_layout))
            .isNotRefreshing();
    verify(((TestItemActivity) fragment.getActivity()).itemChangedListener)
            .onItemChanged(any(Item.class));
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:25,代码来源:ItemFragmentMultiPageTest.java

示例3: testRefreshFailed

import org.robolectric.internal.ShadowExtractor; //导入依赖的package包/类
@Test
public void testRefreshFailed() {
    WebItem webItem = mock(WebItem.class);
    when(webItem.getId()).thenReturn("1");
    Bundle args = new Bundle();
    args.putParcelable(ItemFragment.EXTRA_ITEM, webItem);
    Fragment fragment = Fragment.instantiate(RuntimeEnvironment.application,
            ItemFragment.class.getName(), args);
    makeVisible(fragment);
    ShadowSwipeRefreshLayout shadowSwipeRefreshLayout = (ShadowSwipeRefreshLayout)
            ShadowExtractor.extract(fragment.getView().findViewById(R.id.swipe_layout));
    shadowSwipeRefreshLayout.getOnRefreshListener().onRefresh();
    verify(hackerNewsClient).getItem(eq("1"),
            eq(ItemManager.MODE_DEFAULT),
            listener.capture());
    verify(hackerNewsClient).getItem(eq("1"),
            eq(ItemManager.MODE_NETWORK),
            listener.capture());
    listener.getAllValues().get(1).onError(null);
    assertThat((SwipeRefreshLayout) fragment.getView().findViewById(R.id.swipe_layout))
            .isNotRefreshing();
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:23,代码来源:ItemFragmentMultiPageTest.java

示例4: testDownloadContent

import org.robolectric.internal.ShadowExtractor; //导入依赖的package包/类
@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();
    RobolectricPackageManager rpm = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
    final String url = "http://example.com/file.doc";
    rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), resolverInfo);

    WebView webView = (WebView) activity.findViewById(R.id.web_view);
    ShadowWebView shadowWebView = (ShadowWebView) ShadowExtractor.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());
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:21,代码来源:WebFragmentTest.java

示例5: testDownloadPdf

import org.robolectric.internal.ShadowExtractor; //导入依赖的package包/类
@Test
public void testDownloadPdf() throws InterruptedException {
    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();
    RobolectricPackageManager rpm = (RobolectricPackageManager) 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 = (ShadowWebView) ShadowExtractor.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));
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:23,代码来源:WebFragmentTest.java

示例6: testWebControls

import org.robolectric.internal.ShadowExtractor; //导入依赖的package包/类
@SuppressLint("NewApi")
@Test
public void testWebControls() {
    ShadowLocalBroadcastManager.getInstance(activity)
            .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN)
                    .putExtra(WebFragment.EXTRA_FULLSCREEN, true));
    ShadowWebView shadowWebView = (ShadowWebView) ShadowExtractor
            .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);
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:22,代码来源:WebFragmentTest.java

示例7: testFullScroll

import org.robolectric.internal.ShadowExtractor; //导入依赖的package包/类
@Test
public void testFullScroll() {
    ShadowLocalBroadcastManager.getInstance(activity)
            .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN)
                    .putExtra(WebFragment.EXTRA_FULLSCREEN, true));
    ShadowWebView shadowWebView = (ShadowWebView) ShadowExtractor
            .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());
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:17,代码来源:WebFragmentTest.java

示例8: testAddAccount

import org.robolectric.internal.ShadowExtractor; //导入依赖的package包/类
@Test
public void testAddAccount() {
    ShadowAccountManager.get(activity).addAccountExplicitly(new Account("existing",
            BuildConfig.APPLICATION_ID), "password", null);
    drawerAccount.performClick();
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    assertThat(alertDialog.getListView().getAdapter()).hasCount(1);
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
    assertThat(alertDialog).isNotShowing();
    ((ShadowSupportDrawerLayout) ShadowExtractor.extract(activity.findViewById(R.id.drawer_layout)))
            .getDrawerListeners().get(0)
            .onDrawerClosed(activity.findViewById(R.id.drawer));
    assertThat(shadowOf(activity).getNextStartedActivity())
            .hasComponent(activity, LoginActivity.class);
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:17,代码来源:DrawerActivityLoginTest.java

示例9: testNewStory

import org.robolectric.internal.ShadowExtractor; //导入依赖的package包/类
@Test
public void testNewStory() {
    reset(itemManager);
    ShadowSwipeRefreshLayout shadowSwipeRefreshLayout = (ShadowSwipeRefreshLayout)
            ShadowExtractor.extract(activity.findViewById(R.id.swipe_layout));
    shadowSwipeRefreshLayout.getOnRefreshListener().onRefresh();
    verify(itemManager).getStories(any(),
            eq(ItemManager.MODE_NETWORK),
            storiesListener.capture());
    storiesListener.getValue().onResponse(new Item[]{new TestHnItem(2) {
        @Override
        public int getRank() {
            return 46;
        }
    }});
    ShadowSnackbar.getLatestView().findViewById(R.id.snackbar_action).performClick();
    verify(itemManager, atLeastOnce()).getItem(any(),
            eq(ItemManager.MODE_NETWORK),
            itemListener.capture());
    itemListener.getValue().onResponse(new PopulatedStory(2));
    RecyclerView.ViewHolder holder = adapter.getViewHolder(0);
    assertThat((TextView) holder.itemView.findViewById(R.id.rank)).hasTextString("46*");
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:24,代码来源:ListFragmentViewHolderTest.java

示例10: testPromoted

import org.robolectric.internal.ShadowExtractor; //导入依赖的package包/类
@Test
public void testPromoted() {
    reset(itemManager);
    ShadowSwipeRefreshLayout shadowSwipeRefreshLayout = (ShadowSwipeRefreshLayout)
            ShadowExtractor.extract(activity.findViewById(R.id.swipe_layout));
    shadowSwipeRefreshLayout.getOnRefreshListener().onRefresh();
    verify(itemManager).getStories(any(),
            eq(ItemManager.MODE_NETWORK),
            storiesListener.capture());
    storiesListener.getValue().onResponse(new Item[]{new TestHnItem(1) {
        @Override
        public int getRank() {
            return 45;
        }
    }});
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_NETWORK), itemListener.capture());
    itemListener.getValue().onResponse(new PopulatedStory(1));
    RecyclerView.ViewHolder holder = adapter.getViewHolder(0);
    assertThat((TextView) holder.itemView.findViewById(R.id.rank)).containsText("+1");
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:21,代码来源:ListFragmentViewHolderTest.java

示例11: testNewComments

import org.robolectric.internal.ShadowExtractor; //导入依赖的package包/类
@Test
public void testNewComments() {
    reset(itemManager);
    ShadowSwipeRefreshLayout shadowSwipeRefreshLayout = (ShadowSwipeRefreshLayout)
            ShadowExtractor.extract(activity.findViewById(R.id.swipe_layout));
    shadowSwipeRefreshLayout.getOnRefreshListener().onRefresh();
    verify(itemManager).getStories(any(),
            eq(ItemManager.MODE_NETWORK),
            storiesListener.capture());
    storiesListener.getValue().onResponse(new Item[]{new TestHnItem(1)});
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_NETWORK), itemListener.capture());
    itemListener.getValue().onResponse(new PopulatedStory(1) {
        @Override
        public int getDescendants() {
            return 2;
        }

        @Override
        public long[] getKids() {
            return new long[]{2, 3};
        }
    });
    RecyclerView.ViewHolder holder = adapter.getViewHolder(0);
    assertThat((TextView) holder.itemView.findViewById(R.id.comment)).hasTextString("2*");
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:26,代码来源:ListFragmentViewHolderTest.java

示例12: testPreferenceChange

import org.robolectric.internal.ShadowExtractor; //导入依赖的package包/类
@Test
public void testPreferenceChange() {
    reset(itemManager);
    ShadowSwipeRefreshLayout shadowSwipeRefreshLayout = (ShadowSwipeRefreshLayout)
            ShadowExtractor.extract(activity.findViewById(R.id.swipe_layout));
    shadowSwipeRefreshLayout.getOnRefreshListener().onRefresh();
    verify(itemManager).getStories(any(),
            eq(ItemManager.MODE_NETWORK),
            storiesListener.capture());
    storiesListener.getValue().onResponse(new Item[]{new TestHnItem(2) {
        @Override
        public int getRank() {
            return 46;
        }
    }});
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_NETWORK), itemListener.capture());
    itemListener.getValue().onResponse(new PopulatedStory(2));
    RecyclerView.ViewHolder holder = adapter.getViewHolder(0);
    assertThat((TextView) holder.itemView.findViewById(R.id.rank)).hasTextString("46*");
    PreferenceManager.getDefaultSharedPreferences(activity)
            .edit()
            .putBoolean(activity.getString(R.string.pref_highlight_updated), false)
            .apply();
    holder = adapter.getViewHolder(0);
    assertThat((TextView) holder.itemView.findViewById(R.id.rank)).hasTextString("46");
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:27,代码来源:ListFragmentViewHolderTest.java

示例13: searchFromBfsNodeMatchesChild_shouldReturnChild

import org.robolectric.internal.ShadowExtractor; //导入依赖的package包/类
@Test
public void searchFromBfsNodeMatchesChild_shouldReturnChild() {
    AccessibilityNodeInfo parent = AccessibilityNodeInfo.obtain();
    AccessibilityNodeInfo child = AccessibilityNodeInfo.obtain();
    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(parent)).addChild(child);

    AccessibilityNodeInfoCompat parentCompat = new AccessibilityNodeInfoCompat(parent);
    AccessibilityNodeInfoCompat childCompat = new AccessibilityNodeInfoCompat(child);
    parent.setFocusable(false);
    child.setFocusable(true);
    AccessibilityNodeInfoCompat returned =
            AccessibilityNodeInfoUtils.searchFromBfs(parentCompat, focusableFilter);
    assertEquals(childCompat, returned);
    parentCompat.recycle();
    childCompat.recycle();
    returned.recycle();
}
 
开发者ID:google,项目名称:talkback,代码行数:18,代码来源:AccessibilityNodeInfoUtilsTest.java

示例14: getRootForNonRootNode_shouldReturnRootNode

import org.robolectric.internal.ShadowExtractor; //导入依赖的package包/类
@Test
public void getRootForNonRootNode_shouldReturnRootNode() {
    AccessibilityNodeInfo level1Node = AccessibilityNodeInfo.obtain();
    AccessibilityNodeInfo level2Node = AccessibilityNodeInfo.obtain();
    AccessibilityNodeInfo level3Node = AccessibilityNodeInfo.obtain();
    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(level1Node)).addChild(level2Node);
    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(level2Node)).addChild(level3Node);

    AccessibilityNodeInfoCompat startNode = new AccessibilityNodeInfoCompat(level3Node);
    AccessibilityNodeInfoCompat targetNode = new AccessibilityNodeInfoCompat(level1Node);
    AccessibilityNodeInfoCompat rootNode = AccessibilityNodeInfoUtils.getRoot(startNode);
    assertEquals(targetNode, rootNode);
    level1Node.recycle();
    level2Node.recycle();
    level3Node.recycle();
    rootNode.recycle();
}
 
开发者ID:google,项目名称:talkback,代码行数:18,代码来源:AccessibilityNodeInfoUtilsTest.java

示例15: getRootForNodeWithLoop_shouldReturnNull

import org.robolectric.internal.ShadowExtractor; //导入依赖的package包/类
@Test
public void getRootForNodeWithLoop_shouldReturnNull() {
    AccessibilityNodeInfo level1Node = AccessibilityNodeInfo.obtain();
    AccessibilityNodeInfo level2Node = AccessibilityNodeInfo.obtain();
    AccessibilityNodeInfo level3Node = AccessibilityNodeInfo.obtain();

    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(level1Node)).addChild(level2Node);
    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(level2Node)).addChild(level3Node);
    ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(level3Node)).addChild(level1Node);

    AccessibilityNodeInfoCompat startNode = new AccessibilityNodeInfoCompat(level3Node);
    AccessibilityNodeInfoCompat rootNode = AccessibilityNodeInfoUtils.getRoot(startNode);
    assertNull(rootNode);
    level1Node.recycle();
    level2Node.recycle();
    level3Node.recycle();
}
 
开发者ID:google,项目名称:talkback,代码行数:18,代码来源:AccessibilityNodeInfoUtilsTest.java


注:本文中的org.robolectric.internal.ShadowExtractor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。