use of org.robolectric.shadows.ShadowContentObserver in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testSaveItem.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testSaveItem() {
ShadowContentObserver observer = shadowOf(shadowOf(activity.getContentResolver()).getContentObservers(MaterialisticProvider.URI_FAVORITE).iterator().next());
verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
itemListener.getValue().onResponse(item);
adapter.getViewHolder(0).itemView.performLongClick();
PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
assertNotNull(popupMenu);
assertThat(popupMenu.getMenu().findItem(R.id.menu_contextual_save).isVisible()).isFalse();
shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_save));
verify(favoriteManager).add(any(Context.class), eq(item));
observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("add").appendPath("1").build());
assertTrue(item.isFavorite());
View snackbarView = ShadowSnackbar.getLatestView();
assertThat((TextView) snackbarView.findViewById(R.id.snackbar_text)).isNotNull().containsText(R.string.toast_saved);
snackbarView.findViewById(R.id.snackbar_action).performClick();
verify(favoriteManager).remove(any(Context.class), eq("1"));
observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("remove").appendPath("1").build());
assertFalse(item.isFavorite());
}
use of org.robolectric.shadows.ShadowContentObserver in project materialistic by hidroh.
the class ItemActivityTest method testFavoriteStory.
@Test
public void testFavoriteStory() {
Intent intent = new Intent();
TestHnItem item = new TestHnItem(1L) {
@NonNull
@Override
public String getType() {
return STORY_TYPE;
}
};
item.setFavorite(true);
intent.putExtra(ItemActivity.EXTRA_ITEM, item);
controller.withIntent(intent).create().start().resume();
assertTrue(item.isFavorite());
ShadowContentObserver observer = shadowOf(shadowOf(activity.getContentResolver()).getContentObservers(MaterialisticProvider.URI_FAVORITE).iterator().next());
activity.findViewById(R.id.bookmarked).performClick();
verify(favoriteManager).remove(any(Context.class), eq("1"));
observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("remove").appendPath("1").build());
assertFalse(item.isFavorite());
assertThat((TextView) activity.findViewById(R.id.snackbar_text)).isNotNull().containsText(R.string.toast_removed);
activity.findViewById(R.id.snackbar_action).performClick();
observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("add").appendPath("1").build());
assertTrue(item.isFavorite());
}
use of org.robolectric.shadows.ShadowContentObserver in project materialistic by hidroh.
the class ItemActivityTest method testNonFavoriteStory.
@Test
public void testNonFavoriteStory() {
TestHnItem item = new TestHnItem(1L) {
@NonNull
@Override
public String getType() {
return STORY_TYPE;
}
};
Intent intent = new Intent();
intent.putExtra(ItemActivity.EXTRA_ITEM, item);
controller.withIntent(intent).create().start().resume();
assertFalse(item.isFavorite());
activity.findViewById(R.id.bookmarked).performClick();
ShadowContentObserver observer = shadowOf(shadowOf(activity.getContentResolver()).getContentObservers(MaterialisticProvider.URI_FAVORITE).iterator().next());
observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("add").appendPath("1").build());
assertTrue(item.isFavorite());
}
use of org.robolectric.shadows.ShadowContentObserver in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testFavoriteObserver.
@Test
public void testFavoriteObserver() {
verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
item.setFavorite(true);
itemListener.getValue().onResponse(item);
assertTrue(item.isFavorite());
controller.pause();
ShadowContentObserver observer = shadowOf(shadowOf(activity.getContentResolver()).getContentObservers(MaterialisticProvider.URI_FAVORITE).iterator().next());
// observed clear
observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("clear").build());
RecyclerView.ViewHolder viewHolder = adapter.getViewHolder(0);
assertFalse(item.isFavorite());
assertThat(viewHolder.itemView.findViewById(R.id.bookmarked)).isNotVisible();
// observed add
observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("add").appendPath("1").build());
assertTrue(item.isFavorite());
// observed remove
observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("remove").appendPath("1").build());
assertFalse(item.isFavorite());
controller.resume();
}
use of org.robolectric.shadows.ShadowContentObserver in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testViewedObserver.
@Test
public void testViewedObserver() {
verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
itemListener.getValue().onResponse(item);
assertNotViewed();
controller.pause();
ShadowContentObserver observer = shadowOf(shadowOf(activity.getContentResolver()).getContentObservers(MaterialisticProvider.URI_VIEWED).iterator().next());
observer.dispatchChange(false, MaterialisticProvider.URI_VIEWED.buildUpon().appendPath("2").build());
observer.dispatchChange(false, MaterialisticProvider.URI_VIEWED.buildUpon().appendPath("1").build());
controller.resume();
assertViewed();
}
Aggregations