Code example for BitmapDrawable

Methods: getBitmap

0
    public void constructors_shouldSetBitmap() throws Exception { 
        Bitmap bitmap = Robolectric.newInstanceOf(Bitmap.class);
        BitmapDrawable drawable = new BitmapDrawable(bitmap);
        assertEquals(bitmap, drawable.getBitmap());
 
        drawable = new BitmapDrawable(resources, bitmap);
        assertEquals(bitmap, drawable.getBitmap());
    } 
 
    @Test 
    public void getBitmap_shouldReturnBitmapUsedToDraw() throws Exception { 
        BitmapDrawable drawable = (BitmapDrawable) resources.getDrawable(R.drawable.an_image);
        assertEquals("Bitmap for resource:org.robolectric:drawable/an_image", shadowOf(drawable.getBitmap()).getDescription());
    } 
 
    @Test 
    public void mutate_createsDeepCopy() throws Exception { 
        BitmapDrawable original = (BitmapDrawable) resources.getDrawable(R.drawable.an_image);
        Drawable mutated = original.mutate();
        assertNotSame(original, mutated);
        assertTrue(mutated instanceof BitmapDrawable);