diff --git a/library/test/src/test/java/com/bumptech/glide/GlideTest.java b/library/test/src/test/java/com/bumptech/glide/GlideTest.java index 6d65e0e454..28cde95952 100644 --- a/library/test/src/test/java/com/bumptech/glide/GlideTest.java +++ b/library/test/src/test/java/com/bumptech/glide/GlideTest.java @@ -28,7 +28,6 @@ import android.graphics.drawable.Drawable; import android.media.MediaMetadataRetriever; import android.net.Uri; -import android.os.Handler; import android.os.ParcelFileDescriptor; import android.view.ViewGroup; import android.widget.ImageView; @@ -90,7 +89,6 @@ import org.robolectric.annotation.LooperMode; import org.robolectric.annotation.Resetter; import org.robolectric.shadow.api.Shadow; -import org.robolectric.shadows.ShadowBitmap; /** Tests for the {@link Glide} interface and singleton. */ @LooperMode(LEGACY) @@ -100,7 +98,6 @@ shadows = { GlideTest.ShadowFileDescriptorContentResolver.class, GlideTest.ShadowMediaMetadataRetriever.class, - GlideTest.MutableShadowBitmap.class }) @SuppressWarnings("unchecked") public class GlideTest { @@ -116,7 +113,6 @@ public class GlideTest { @Mock private DiskCache.Factory diskCacheFactory; @Mock private DiskCache diskCache; @Mock private MemoryCache memoryCache; - @Mock private Handler bgHandler; @Mock private Lifecycle lifecycle; @Mock private RequestManagerTreeNode treeNode; @Mock private BitmapPool bitmapPool; @@ -155,17 +151,6 @@ public void setUp() { imageView.layout(0, 0, 100, 100); doAnswer(new CallSizeReady()).when(target).getSize(isA(SizeReadyCallback.class)); - when(bgHandler.post(isA(Runnable.class))) - .thenAnswer( - new Answer() { - @Override - public Boolean answer(InvocationOnMock invocation) { - Runnable runnable = (Runnable) invocation.getArguments()[0]; - runnable.run(); - return true; - } - }); - requestManager = new RequestManager(Glide.get(context), lifecycle, treeNode, context); requestManager.resumeRequests(); } @@ -878,17 +863,6 @@ public AssetFileDescriptor openAssetFileDescriptor(Uri uri, String type) { } } - @Implements(Bitmap.class) - public static class MutableShadowBitmap extends ShadowBitmap { - - @Implementation - public static Bitmap createBitmap(int width, int height, Bitmap.Config config) { - Bitmap bitmap = ShadowBitmap.createBitmap(width, height, config); - Shadows.shadowOf(bitmap).setMutable(true); - return bitmap; - } - } - @Implements(MediaMetadataRetriever.class) public static class ShadowMediaMetadataRetriever { diff --git a/library/test/src/test/java/com/bumptech/glide/load/resource/bitmap/TransformationUtilsTest.java b/library/test/src/test/java/com/bumptech/glide/load/resource/bitmap/TransformationUtilsTest.java index 51d7a96f66..bfbd22c5ca 100644 --- a/library/test/src/test/java/com/bumptech/glide/load/resource/bitmap/TransformationUtilsTest.java +++ b/library/test/src/test/java/com/bumptech/glide/load/resource/bitmap/TransformationUtilsTest.java @@ -17,7 +17,6 @@ import androidx.exifinterface.media.ExifInterface; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; import com.bumptech.glide.tests.Util; -import com.bumptech.glide.util.Preconditions; import com.google.common.collect.Range; import org.junit.Before; import org.junit.Test; @@ -27,14 +26,9 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.Shadows; import org.robolectric.annotation.Config; -import org.robolectric.annotation.Implementation; -import org.robolectric.annotation.Implements; -import org.robolectric.shadows.ShadowBitmap; @RunWith(RobolectricTestRunner.class) -@Config( - sdk = 28, - shadows = {TransformationUtilsTest.AlphaShadowBitmap.class}) +@Config(sdk = 28) public class TransformationUtilsTest { @Mock private BitmapPool bitmapPool; @@ -449,16 +443,4 @@ public void testInitializeMatrixSetsRotateOnRotation() { TransformationUtils.initializeMatrixForRotation(ExifInterface.ORIENTATION_ROTATE_270, matrix); verify(matrix).setRotate(-90); } - - @Implements(Bitmap.class) - public static class AlphaShadowBitmap extends ShadowBitmap { - - @Implementation - public static Bitmap createBitmap(int width, int height, Bitmap.Config config) { - // Robolectric doesn't match the framework behavior with null configs, so we have to do so - // here. - Preconditions.checkNotNull("Config must not be null"); - return ShadowBitmap.createBitmap(width, height, config); - } - } } diff --git a/third_party/gif_decoder/src/test/java/com/bumptech/glide/gifdecoder/GifDecoderTest.java b/third_party/gif_decoder/src/test/java/com/bumptech/glide/gifdecoder/GifDecoderTest.java index 5f16febb54..4972f44ec9 100644 --- a/third_party/gif_decoder/src/test/java/com/bumptech/glide/gifdecoder/GifDecoderTest.java +++ b/third_party/gif_decoder/src/test/java/com/bumptech/glide/gifdecoder/GifDecoderTest.java @@ -3,22 +3,17 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.robolectric.Shadows.shadowOf; import android.graphics.Bitmap; import androidx.annotation.NonNull; import com.bumptech.glide.testutil.TestUtil; import java.io.IOException; -import java.util.Arrays; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.Shadows; import org.robolectric.annotation.Config; -import org.robolectric.annotation.Implementation; -import org.robolectric.annotation.Implements; -import org.robolectric.shadows.ShadowBitmap; /** Tests for {@link com.bumptech.glide.gifdecoder.GifDecoder}. */ @RunWith(RobolectricTestRunner.class) @@ -141,7 +136,6 @@ public void testSettingDataResetsFramePointer() { } @Test - @Config(shadows = {CustomShadowBitmap.class}) public void testFirstFrameMustClearBeforeDrawingWhenLastFrameIsDisposalBackground() throws IOException { byte[] data = TestUtil.resourceToBytes(getClass(), "transparent_disposal_background.gif"); @@ -156,12 +150,10 @@ public void testFirstFrameMustClearBeforeDrawingWhenLastFrameIsDisposalBackgroun decoder.getNextFrame(); decoder.advance(); Bitmap firstFrameTwice = decoder.getNextFrame(); - assertTrue(Arrays.equals((((CustomShadowBitmap) shadowOf(firstFrame))).getPixels(), - (((CustomShadowBitmap) shadowOf(firstFrameTwice))).getPixels())); + assertTrue(firstFrame.sameAs(firstFrameTwice)); } @Test - @Config(shadows = {CustomShadowBitmap.class}) public void testFirstFrameMustClearBeforeDrawingWhenLastFrameIsDisposalNone() throws IOException { byte[] data = TestUtil.resourceToBytes(getClass(), "transparent_disposal_none.gif"); GifHeaderParser headerParser = new GifHeaderParser(); @@ -175,28 +167,7 @@ public void testFirstFrameMustClearBeforeDrawingWhenLastFrameIsDisposalNone() th decoder.getNextFrame(); decoder.advance(); Bitmap firstFrameTwice = decoder.getNextFrame(); - assertTrue(Arrays.equals((((CustomShadowBitmap) shadowOf(firstFrame))).getPixels(), - (((CustomShadowBitmap) shadowOf(firstFrameTwice))).getPixels())); - } - - /** - * Preserve generated bitmap data for checking. - */ - @Implements(Bitmap.class) - public static class CustomShadowBitmap extends ShadowBitmap { - - private int[] pixels; - - @Implementation - public void setPixels(int[] pixels, int offset, int stride, - int x, int y, int width, int height) { - this.pixels = new int[pixels.length]; - System.arraycopy(pixels, 0, this.pixels, 0, this.pixels.length); - } - - public int[] getPixels() { - return pixels; - } + assertTrue(firstFrame.sameAs(firstFrameTwice)); } private static class MockProvider implements GifDecoder.BitmapProvider {