Skip to content

Commit

Permalink
Update two Glide tests to use public Bitmap APIs instead of shadow APIs
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 486721523
  • Loading branch information
hoisie authored and glide-copybara-robot committed Nov 7, 2022
1 parent 37bc006 commit 330b9a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
Expand Down Expand Up @@ -52,8 +51,9 @@ public void testICanAddAndGetABitmap() {
@Test
public void testImmutableBitmapsAreNotAdded() {
Bitmap bitmap = createMutableBitmap();
Shadows.shadowOf(bitmap).setMutable(false);
pool.put(bitmap);
Bitmap immutable = bitmap.copy(Bitmap.Config.ARGB_8888, /*isMutable=*/ false);
assertThat(immutable.isMutable()).isFalse();
pool.put(immutable);
assertThat(strategy.bitmaps).isEmpty();
}

Expand Down Expand Up @@ -249,7 +249,7 @@ private Bitmap createMutableBitmap() {

private Bitmap createMutableBitmap(Bitmap.Config config) {
Bitmap bitmap = Bitmap.createBitmap(100, 100, config);
Shadows.shadowOf(bitmap).setMutable(true);
assertThat(bitmap.isMutable()).isTrue();
return bitmap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static org.mockito.Mockito.when;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Matrix;
import androidx.exifinterface.media.ExifInterface;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
Expand Down Expand Up @@ -350,12 +351,20 @@ public void testGetExifOrientationDegrees() {
@Test
public void testRotateImage() {
Bitmap toRotate = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888);

toRotate.setPixel(0, 0, Color.BLUE);
toRotate.setPixel(0, 1, Color.RED);
Bitmap zero = TransformationUtils.rotateImage(toRotate, 0);
assertTrue(toRotate == zero);

Bitmap ninety = TransformationUtils.rotateImage(toRotate, 90);
assertThat(Shadows.shadowOf(ninety).getDescription()).contains("rotate=90.0");
// Checks if native graphics is enabled.
if (Boolean.getBoolean("robolectric.nativeruntime.enableGraphics")) {
assertThat(ninety.getPixel(0, 0)).isEqualTo(Color.RED);
assertThat(ninety.getPixel(1, 0)).isEqualTo(Color.BLUE);
} else {
// Use legacy shadow APIs
assertThat(Shadows.shadowOf(ninety).getDescription()).contains("rotate=90.0");
}
assertEquals(toRotate.getWidth(), toRotate.getHeight());
}

Expand Down

0 comments on commit 330b9a8

Please sign in to comment.