@Override public Resources getResources() { Resources resources = super.getResources(); if (applicationLike != null) { return invokeAppLikeGetResources(applicationLike, resources); } return resources; }
BitmapDrawableResource create() { return new BitmapDrawableResource( new BitmapDrawable(RuntimeEnvironment.application.getResources(), bitmap), bitmapPool); } }
@Before public void setUp() { MockitoAnnotations.initMocks(this); bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); when(bitmapResource.get()).thenReturn(bitmap); resources = RuntimeEnvironment.application.getResources(); resource = (LazyBitmapDrawableResource) LazyBitmapDrawableResource.obtain(resources, bitmapResource); }
@Test @Config(minSdk = LOLLIPOP) public void testGetBitmapOrVectorDrawableAt21() { final Drawable aDrawable = context.getResources().getDrawable(R.drawable.an_image_or_vector); assertThat(aDrawable).isInstanceOf(VectorDrawable.class); }
@Test @Config(maxSdk = KITKAT_WATCH) public void testGetBitmapOrVectorDrawableAt19() { // at API 21+ and mdpi, the drawable-anydpi-v21/image_or_vector.xml should be loaded instead // of drawable/image_or_vector.png final Drawable aDrawable = context.getResources().getDrawable(R.drawable.an_image_or_vector); assertThat(aDrawable).isInstanceOf(BitmapDrawable.class); }
@Test @Config(qualifiers = "mdpi") public void drawableShouldLoadImageOfCorrectSizeWithMdpiQualifier() { final Drawable anImage = context.getResources().getDrawable(R.drawable.robolectric); assertThat(anImage.getIntrinsicHeight()).isEqualTo(167); assertThat(anImage.getIntrinsicWidth()).isEqualTo(198); }
@Test @Config(qualifiers = "hdpi") public void drawableShouldLoadImageOfCorrectSizeWithHdpiQualifier() { final Drawable anImage = context.getResources().getDrawable(R.drawable.robolectric); assertThat(anImage.getIntrinsicHeight()).isEqualTo(251); assertThat(anImage.getIntrinsicWidth()).isEqualTo(297); }
@Test public void drawableIntrinsicWidthAndHeightShouldBeCorrect() { final Drawable anImage = context.getResources().getDrawable(R.drawable.an_image); assertThat(anImage.getIntrinsicHeight()).isEqualTo(53); assertThat(anImage.getIntrinsicWidth()).isEqualTo(64); }
@Before public void setUp() { transcoder = new BitmapDrawableTranscoder(RuntimeEnvironment.application.getResources()); }
@Test public void testReturnsTargetForBitmapDrawables() { BitmapDrawable drawable = new BitmapDrawable(RuntimeEnvironment.application.getResources(), Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_4444)); Target<BitmapDrawable> target = factory.buildTarget(view, BitmapDrawable.class); target.onResourceReady(drawable, null); assertThat(target).isInstanceOf(DrawableImageViewTarget.class); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); options = new Options(); loader = new ResourceLoader<>(RuntimeEnvironment.application.getResources(), uriLoader); }
@Test public void createFromResourceStream_shouldWorkWithoutSourceName() { Drawable drawable = Drawable.createFromResourceStream( context.getResources(), null, new ByteArrayInputStream(new byte[0]), null, new BitmapFactory.Options()); assertNotNull(drawable); }
@Test public void decodeResource_canTakeOptions() { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 100; Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.an_image, options); assertEquals(true, shadowOf(bitmap).getDescription().contains("inSampleSize=100")); }
@Test public void decodeResourceStream_canTakeOptions() throws Exception { BitmapFactory.Options options = new BitmapFactory.Options(); InputStream inputStream = context.getContentResolver().openInputStream(Uri.parse("content:/path")); options.inSampleSize = 100; Bitmap bitmap = BitmapFactory.decodeResourceStream( context.getResources(), null, inputStream, null, options); assertEquals(true, shadowOf(bitmap).getDescription().contains("inSampleSize=100")); }
@Before public void setUp() throws Exception { context = ApplicationProvider.getApplicationContext(); parser = context.getResources().getXml(R.xml.preferences); }
@Test public void decodeResource_shouldGetWidthAndHeightFromHints() { ShadowBitmapFactory.provideWidthAndHeightHints(R.drawable.an_image, 123, 456); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.an_image); assertEquals("Bitmap for resource:org.robolectric:drawable/an_image", shadowOf(bitmap).getDescription()); assertEquals(123, bitmap.getWidth()); assertEquals(456, bitmap.getHeight()); }
@Test public void getStyleAttribute_allowStyleAttrReference() throws Exception { parser = context.getResources().getXml(R.xml.has_style_attribute_reference); parseUntilNext(XmlResourceParser.START_TAG); assertThat(parser.getStyleAttribute()).isEqualTo(R.attr.parentStyleReference); }
@Test public void decodeResource_shouldSetDescriptionAndCreatedFrom() { Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.an_image); ShadowBitmap shadowBitmap = shadowOf(bitmap); assertEquals("Bitmap for resource:org.robolectric:drawable/an_image", shadowBitmap.getDescription()); assertEquals(R.drawable.an_image, shadowBitmap.getCreatedFromResId()); assertEquals(64, bitmap.getWidth()); assertEquals(53, bitmap.getHeight()); }
@Test public void testGetAttributeResourceValueStringStringInt() throws Exception { parser = context.getResources().getXml(R.xml.has_attribute_resource_value); parseUntilNext(XmlResourceParser.START_TAG); assertThat(parser.getAttributeResourceValue(RES_AUTO_NS, "bar", 42)).isEqualTo(R.layout.main); assertThat(parser.getAttributeResourceValue(RES_AUTO_NS, "foo", 42)).isEqualTo(42); }
@Test public void testReturnsNewDrawableFromConstantState() { Bitmap firstFrame = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); drawable = new GifDrawable( RuntimeEnvironment.application, mock(GifDecoder.class), transformation, 100, 100, firstFrame); assertNotNull(Preconditions.checkNotNull(drawable.getConstantState()).newDrawable()); assertNotNull( drawable.getConstantState().newDrawable(RuntimeEnvironment.application.getResources())); }