本文整理汇总了Java中org.robolectric.internal.ShadowExtractor.extract方法的典型用法代码示例。如果您正苦于以下问题:Java ShadowExtractor.extract方法的具体用法?Java ShadowExtractor.extract怎么用?Java ShadowExtractor.extract使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.robolectric.internal.ShadowExtractor
的用法示例。
在下文中一共展示了ShadowExtractor.extract方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testScrollWithParent_shouldScrollAndClearFocus
import org.robolectric.internal.ShadowExtractor; //导入方法依赖的package包/类
@Test
public void testScrollWithParent_shouldScrollAndClearFocus() {
AccessibilityNodeInfoCompat parent = AccessibilityNodeInfoCompat.obtain();
ShadowAccessibilityNodeInfo shadowParent =
(ShadowAccessibilityNodeInfo) ShadowExtractor.extract(parent.getInfo());
shadowParent.addChild((AccessibilityNodeInfo) mCompat1.getInfo());
parent.setScrollable(true);
mActionNode1.recycle();
mActionNode1 = new AccessibilityNodeActionNode(mCompat1,
new AccessibilityNodeInfoCompat.AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_CLICK, "label1"));
mSelectionNode = new OptionScanSelectionNode(mActionNode1, mActionNode2);
mOptionManager.clearFocusIfNewTree(mSelectionNode);
mOptionManager.selectOption(0);
mOptionManager.performScrollAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD);
assertEquals(0, mShadowInfo1.getPerformedActions().size());
List<Integer> parentActions = shadowParent.getPerformedActions();
assertEquals(1, parentActions.size());
assertEquals(new Integer(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD),
parentActions.get(0));
verify(mOverlayController, times(3)).clearOverlay();
parent.recycle();
}
示例2: 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));
}
示例3: areThereUnrecycledNodes
import org.robolectric.internal.ShadowExtractor; //导入方法依赖的package包/类
/**
* Check for leaked objects that were {@code obtain}ed but never
* {@code recycle}d.
*
* @param printUnrecycledNodesToSystemErr - if true, stack traces of calls
* to {@code obtain} that lack matching calls to {@code recycle} are
* dumped to System.err.
* @return {@code true} if there are unrecycled nodes
*/
public static boolean areThereUnrecycledNodes(boolean printUnrecycledNodesToSystemErr) {
if (printUnrecycledNodesToSystemErr) {
for (final StrictEqualityNodeWrapper wrapper : obtainedInstances.keySet()) {
final ShadowAccessibilityNodeInfo shadow =
((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(wrapper.mInfo));
System.err.println(String.format(
"Leaked contentDescription = %s. Stack trace:", shadow.getContentDescription()));
for (final StackTraceElement stackTraceElement : obtainedInstances.get(wrapper)) {
System.err.println(stackTraceElement.toString());
}
}
}
return (obtainedInstances.size() != 0);
}
示例4: 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*");
}
示例5: 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*");
}
示例6: setup
import org.robolectric.internal.ShadowExtractor; //导入方法依赖的package包/类
@Before
public void setup() {
// Print out everything from logcat to the console instead
ShadowLog.stream = System.out;
// Setup variables
mContext = RuntimeEnvironment.application;
mEditText = new ContactEditText(mContext);
// Update the owner's contact in TextManager
ShadowTextManager shadowTextManager = (ShadowTextManager) ShadowExtractor.extract(TextManager.getInstance(mContext));
shadowTextManager.setSelf(ME);
shadowTextManager.addContact(NAMELESS);
shadowTextManager.addContact(ALICE);
shadowTextManager.addContact(BOB);
shadowTextManager.addContact(CHARLIE);
shadowTextManager.addContact(DEBRA);
}
示例7: createBitmap
import org.robolectric.internal.ShadowExtractor; //导入方法依赖的package包/类
@Implementation
public static Bitmap createBitmap(int width, int height, Bitmap.Config config) {
Bitmap bitmap = Shadow.newInstanceOf(Bitmap.class);
MyShadowBitmap shadowBitmap = (MyShadowBitmap) ShadowExtractor.extract(bitmap);
shadowBitmap.width = width;
shadowBitmap.height = height;
shadowBitmap.mPixels = new int[width * height];
return bitmap;
}
示例8: testOnRecyclerViewScroll_ShouldChangeScrollPosition
import org.robolectric.internal.ShadowExtractor; //导入方法依赖的package包/类
@Test
public void testOnRecyclerViewScroll_ShouldChangeScrollPosition() throws Exception {
int scrollPosition = 1;
RecyclerView recyclerView = (RecyclerView)activity.findViewById(R.id.recyclerView);
ShadowRecyclerView shadowRecyclerView = (ShadowRecyclerView) ShadowExtractor.extract(recyclerView);
recyclerView.smoothScrollToPosition(scrollPosition);
assertEquals(scrollPosition, shadowRecyclerView.getSmoothScrollPosition());
}
示例9: testOnToolbarClicked_RecyclerViewShouldScrollToTop
import org.robolectric.internal.ShadowExtractor; //导入方法依赖的package包/类
@Test
public void testOnToolbarClicked_RecyclerViewShouldScrollToTop() throws Exception {
int scrollPosition = 1;
int topScrollPosition = 0;
Toolbar toolbar = (Toolbar)activity.findViewById(R.id.toolbar);
RecyclerView recyclerView = (RecyclerView)activity.findViewById(R.id.recyclerView);
ShadowRecyclerView shadowRecyclerView = (ShadowRecyclerView) ShadowExtractor.extract(recyclerView);
recyclerView.smoothScrollToPosition(scrollPosition);
toolbar.performClick();
assertEquals(topScrollPosition, shadowRecyclerView.getSmoothScrollPosition());
}
示例10: setUpShadowAdapter
import org.robolectric.internal.ShadowExtractor; //导入方法依赖的package包/类
private void setUpShadowAdapter(int positionToClick){
when(recipe.getSourceURL()).thenReturn("http://galileo.edu");
when(recipeList.get(positionToClick)).thenReturn(recipe);
RecyclerView recyclerView = (RecyclerView)activity.findViewById(R.id.recyclerView);
RecipesAdapter adapterPopulated = new RecipesAdapter(recipeList, imageLoader, onItemClickListener);
recyclerView.setAdapter(adapterPopulated);
shadowAdapter = (ShadowRecyclerViewAdapter) ShadowExtractor.extract(recyclerView.getAdapter());
}
示例11: setUp
import org.robolectric.internal.ShadowExtractor; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
URL = "http://galileo.edu";
when(recipe.getSourceURL()).thenReturn(URL);
adapter = new RecipesAdapter(recipeList, imageLoader, onItemClickListener);
shadowAdapter = (ShadowRecyclerViewAdapter) ShadowExtractor.extract(adapter);
Activity activity = Robolectric.setupActivity(Activity.class);
RecyclerView recyclerView = new RecyclerView(activity);
recyclerView.setLayoutManager(new LinearLayoutManager(activity));
recyclerView.setAdapter(adapter);
}
示例12: testOnSwipeToKeep_ShouldSaveRecipe
import org.robolectric.internal.ShadowExtractor; //导入方法依赖的package包/类
@Test
public void testOnSwipeToKeep_ShouldSaveRecipe() throws Exception {
activity.setRecipe(currentRecipe);
ImageView imgRecipe = (ImageView) activity.findViewById(R.id.imgRecipe);
ShadowImageView shadowImage = (ShadowImageView) ShadowExtractor.extract(imgRecipe);
shadowImage.performSwipe(200, 200, 500, 250, 50);
verify(presenter).saveRecipe(currentRecipe);
}
示例13: testOnSwipeToDismiss_ShouldDiscardRecipe
import org.robolectric.internal.ShadowExtractor; //导入方法依赖的package包/类
@Test
public void testOnSwipeToDismiss_ShouldDiscardRecipe() throws Exception {
ImageView imgRecipe = (ImageView) activity.findViewById(R.id.imgRecipe);
ShadowImageView shadowImage = (ShadowImageView) ShadowExtractor.extract(imgRecipe);
shadowImage.performSwipe(200, 200, -500, 250, 50);
verify(presenter).dismissRecipe();
}
示例14: connectGatt
import org.robolectric.internal.ShadowExtractor; //导入方法依赖的package包/类
/**
* 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 =
((BluetoothGattShadow)ShadowExtractor.extract(mGattConnection));
shadowGatt.setGattCallBack(callback);
shadowGatt.setServices(mServices);
mGattConnection.connect();
return mGattConnection;
}
示例15: testNoFocusedWindowGetCurrent_returnNull
import org.robolectric.internal.ShadowExtractor; //导入方法依赖的package包/类
@Test
public void testNoFocusedWindowGetCurrent_returnNull() {
List<AccessibilityWindowInfo> windows = new ArrayList<>();
for (int i = 0; i < 3; i++) {
windows.add(AccessibilityWindowInfo.obtain());
ShadowAccessibilityWindowInfo shadowWindow =
(ShadowAccessibilityWindowInfo) ShadowExtractor.extract(windows.get(i));
shadowWindow.setId(i);
shadowWindow.setType(AccessibilityWindowInfo.TYPE_APPLICATION);
}
WindowManager manager = new WindowManager(false /* isInRTL */);
manager.setWindows(windows);
assertNull(manager.getCurrentWindow(false /* useInputFocus */));
}