@Test public void getDrawableResourceId_shouldWorkWhenTheDrawableWasCreatedFromAResource() throws Exception { Resources resources = ApplicationProvider.getApplicationContext().getResources(); Bitmap bitmap = BitmapFactory.decodeResource(resources, R.drawable.an_image); ImageView imageView = new ImageView(ApplicationProvider.getApplicationContext()); imageView.setImageBitmap(bitmap); imageView.setImageResource(R.drawable.an_image); assertThat(shadowOf(imageView.getDrawable()).getCreatedFromResId()).isEqualTo(R.drawable.an_image); } }
@Test public void shouldStillHaveShadow() throws Exception { Drawable drawable = resources.getDrawable(R.drawable.an_image); assertThat(Shadows.shadowOf(drawable).getCreatedFromResId()).isEqualTo(R.drawable.an_image); }
@Test public void testTextViewCompoundDrawablesAreSet() throws Exception { View mediaView = inflate(layout.main); TextView view = mediaView.findViewById(R.id.title); Drawable[] drawables = view.getCompoundDrawables(); assertThat(shadowOf(drawables[0]).getCreatedFromResId()).isEqualTo(R.drawable.fourth_image); assertThat(shadowOf(drawables[1]).getCreatedFromResId()).isEqualTo(R.drawable.an_image); assertThat(shadowOf(drawables[2]).getCreatedFromResId()).isEqualTo(R.drawable.an_other_image); assertThat(shadowOf(drawables[3]).getCreatedFromResId()).isEqualTo(R.drawable.third_image); }
@Test public void intoImageViewSetsPlaceholderWithResourceId() { PlatformLruCache cache = new PlatformLruCache(0); Picasso picasso = spy(new Picasso(RuntimeEnvironment.application, mock(Dispatcher.class), UNUSED_CALL_FACTORY, null, cache, null, NO_TRANSFORMERS, NO_HANDLERS, mock(Stats.class), ARGB_8888, false, false)); ImageView target = mockImageViewTarget(); new RequestCreator(picasso, URI_1, 0).placeholder(android.R.drawable.picture_frame) .into(target); ArgumentCaptor<Drawable> drawableCaptor = ArgumentCaptor.forClass(Drawable.class); verify(target).setImageDrawable(drawableCaptor.capture()); assertThat(shadowOf(drawableCaptor.getValue()).getCreatedFromResId()) .isEqualTo(android.R.drawable.picture_frame); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); assertThat(actionCaptor.getValue()).isInstanceOf(ImageViewAction.class); }
@Test public void getIcon_shouldReturnDrawableFromSetIconResourceId() throws Exception { assertThat(item.getIcon()).isNull(); item.setIcon(R.drawable.an_other_image); assertThat(shadowOf(item.getIcon()).getCreatedFromResId()).isEqualTo(R.drawable.an_other_image); }
@Test public void testViewBackgroundIdIsSet() throws Exception { View mediaView = inflate(layout.main); ImageView imageView = mediaView.findViewById(R.id.image); assertThat(shadowOf(imageView.getBackground()).getCreatedFromResId()) .isEqualTo(R.drawable.image_background); }
@Test public void setIcon_shouldNullifyOnZero() throws Exception { assertThat(item.getIcon()).isNull(); item.setIcon(R.drawable.an_image); assertThat(shadowOf(item.getIcon()).getCreatedFromResId()).isEqualTo(R.drawable.an_image); item.setIcon(0); assertThat(item.getIcon()).isNull(); }
@Test public void testGetLoadedFromResourceId_shouldDefaultToNegativeOne() throws Exception { Drawable drawable = new TestDrawable(); assertThat(shadowOf(drawable).getCreatedFromResId()).isEqualTo(-1); }
@Test public void testCreateFromResourceId_shouldSetTheId() throws Exception { Drawable drawable = ShadowDrawable.createFromResourceId(34758); ShadowDrawable shadowDrawable = shadowOf(drawable); assertThat(shadowDrawable.getCreatedFromResId()).isEqualTo(34758); }
@Test public void testSetCompountDrawablesWithIntrinsicBounds_int_shouldCreateDrawablesWithResourceIds() throws Exception { textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.an_image, R.drawable.an_other_image, R.drawable.third_image, R.drawable.fourth_image); assertEquals(R.drawable.an_image, shadowOf(textView.getCompoundDrawables()[0]).getCreatedFromResId()); assertEquals(R.drawable.an_other_image, shadowOf(textView.getCompoundDrawables()[1]).getCreatedFromResId()); assertEquals(R.drawable.third_image, shadowOf(textView.getCompoundDrawables()[2]).getCreatedFromResId()); assertEquals(R.drawable.fourth_image, shadowOf(textView.getCompoundDrawables()[3]).getCreatedFromResId()); }
@Test public void testSetDrawableByLayerId1() throws Exception { LayerDrawable layerDrawable = new LayerDrawable(drawables); int index = 1; int layerId = 345; layerDrawable.setId(index, layerId); layerDrawable.setDrawableByLayerId(layerId, drawable4000); assertEquals(shadowOf(drawable4000).getCreatedFromResId(), shadowOf(layerDrawable.getDrawable(index)).getCreatedFromResId()); }
@Test public void testSetDrawableByLayerId2() throws Exception { LayerDrawable layerDrawable = new LayerDrawable(drawables); int index = 0; int layerId = 345; layerDrawable.setId(index, layerId); layerDrawable.setDrawableByLayerId(layerId, drawable4000); assertEquals(shadowOf(drawable4000).getCreatedFromResId(), shadowOf(layerDrawable.getDrawable(index)).getCreatedFromResId()); }
assertEquals(R.drawable.ic_work_white_18dp, shadowOf(((TextView) activity.findViewById(R.id.posted)) .getCompoundDrawables()[0]).getCreatedFromResId()); assertThat((TextView) activity.findViewById(R.id.source)).hasText("http://example.com"); reset(hackerNewsClient);
ImageView imageView = (ImageView) activity.findViewById(R.id.imageview); ShadowDrawable shadowDrawable = Robolectric.shadowOf(imageView.getDrawable()); assertEquals(R.drawable.expected, shadowDrawable.getCreatedFromResId());
@Test public void testPoll() { Intent intent = new Intent(); intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() { @NonNull @Override public String getType() { return POLL_TYPE; } @Override public boolean isStoryType() { return true; } @Override public String getUrl() { return "http://example.com"; } }); controller = Robolectric.buildActivity(ItemActivity.class, intent); controller.create().start().resume(); activity = controller.get(); assertThat((View) activity.findViewById(R.id.source)).isNotVisible(); assertEquals(R.drawable.ic_poll_white_18dp, shadowOf(((TextView) activity.findViewById(R.id.posted)) .getCompoundDrawables()[0]).getCreatedFromResId()); }
ShadowDrawable background = Robolectric.shadowOf(viewHolder.container.getBackground()); Assert.assertEquals(R.drawable.X, background.getCreatedFromResId());
/** * @deprecated Prefer shadowOf(realImageView.getDrawable()).getCreatedFromResId() * - this method will be removed in the future. */ @Deprecated public int getImageResourceId() { return shadowOf(realImageView.getDrawable()).getCreatedFromResId(); }
private static void assertBitmapsEqual(Drawable expected, Drawable actual) { if (expected == null || actual == null) { assertEquals(expected, actual); } else { assertEquals(shadowOf(expected).getCreatedFromResId(), shadowOf(actual).getCreatedFromResId()); } } }
private void assertDrawableIsFromResource(int view, int resourceId) { Drawable drawable = ((ImageView) mCardForm.findViewById(view)).getDrawable(); assertEquals(resourceId, shadowOf(drawable).getCreatedFromResId()); } }