Home | History | Annotate | Download | only in shadows
      1 package org.robolectric.shadows;
      2 
      3 import static android.os.Build.VERSION_CODES.M;
      4 import static com.google.common.truth.Truth.assertThat;
      5 import static org.robolectric.Shadows.shadowOf;
      6 
      7 import android.graphics.Bitmap;
      8 import android.graphics.drawable.Icon;
      9 import android.net.Uri;
     10 import androidx.test.core.app.ApplicationProvider;
     11 import androidx.test.ext.junit.runners.AndroidJUnit4;
     12 import org.junit.Test;
     13 import org.junit.runner.RunWith;
     14 import org.robolectric.annotation.Config;
     15 
     16 @RunWith(AndroidJUnit4.class)
     17 @Config(minSdk = M)
     18 public class ShadowIconTest {
     19   public static final int TYPE_BITMAP = 1;
     20   public static final int TYPE_RESOURCE = 2;
     21   public static final int TYPE_DATA = 3;
     22   public static final int TYPE_URI = 4;
     23 
     24   @Test
     25   public void testGetRes() {
     26     Icon icon =
     27         Icon.createWithResource(
     28             ApplicationProvider.getApplicationContext(), android.R.drawable.ic_delete);
     29     assertThat(shadowOf(icon).getType()).isEqualTo(TYPE_RESOURCE);
     30     assertThat(shadowOf(icon).getResId()).isEqualTo(android.R.drawable.ic_delete);
     31   }
     32 
     33   @Test
     34   public void testGetBitmap() {
     35     Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
     36     Icon icon = Icon.createWithBitmap(bitmap);
     37     assertThat(shadowOf(icon).getType()).isEqualTo(TYPE_BITMAP);
     38     assertThat(shadowOf(icon).getBitmap()).isEqualTo(bitmap);
     39   }
     40 
     41   @Test
     42   public void testGetData() {
     43     byte[] data = new byte[1000];
     44     Icon icon = Icon.createWithData(data, 100, 200);
     45     assertThat(shadowOf(icon).getType()).isEqualTo(TYPE_DATA);
     46     assertThat(shadowOf(icon).getDataBytes()).isEqualTo(data);
     47     assertThat(shadowOf(icon).getDataOffset()).isEqualTo(100);
     48     assertThat(shadowOf(icon).getDataLength()).isEqualTo(200);
     49   }
     50 
     51   @Test
     52   public void testGetUri() {
     53     Uri uri = Uri.parse("content://icons/icon");
     54     Icon icon = Icon.createWithContentUri(uri);
     55     assertThat(shadowOf(icon).getType()).isEqualTo(TYPE_URI);
     56     assertThat(shadowOf(icon).getUri()).isEqualTo(uri);
     57   }
     58 }
     59