Home | History | Annotate | Download | only in shadows
      1 package org.robolectric.shadows;
      2 
      3 import static org.assertj.core.api.Assertions.assertThat;
      4 import static org.robolectric.Shadows.shadowOf;
      5 
      6 import android.content.res.Resources;
      7 import android.graphics.Bitmap;
      8 import android.graphics.BitmapFactory;
      9 import android.widget.ImageView;
     10 import org.junit.Test;
     11 import org.junit.runner.RunWith;
     12 import org.robolectric.R;
     13 import org.robolectric.RobolectricTestRunner;
     14 import org.robolectric.RuntimeEnvironment;
     15 
     16 @RunWith(RobolectricTestRunner.class)
     17 public class ShadowImageViewTest {
     18 
     19   @Test
     20   public void getDrawableResourceId_shouldWorkWhenTheDrawableWasCreatedFromAResource() throws Exception {
     21 
     22     Resources resources = RuntimeEnvironment.application.getResources();
     23     Bitmap bitmap = BitmapFactory.decodeResource(resources, R.drawable.an_image);
     24     ImageView imageView = new ImageView(RuntimeEnvironment.application);
     25     imageView.setImageBitmap(bitmap);
     26 
     27     imageView.setImageResource(R.drawable.an_image);
     28     assertThat(shadowOf(imageView.getDrawable()).getCreatedFromResId()).isEqualTo(R.drawable.an_image);
     29   }
     30 }
     31