Skip to content

Commit 4298bb7

Browse files
hoisieglide-copybara-robot
authored andcommitted
Remove custom Bitmap shadows from Glide Robolectric tests
These custom shadows are not needed any more. PiperOrigin-RevId: 482877761
1 parent e1366e5 commit 4298bb7

File tree

3 files changed

+3
-76
lines changed

3 files changed

+3
-76
lines changed

library/test/src/test/java/com/bumptech/glide/GlideTest.java

-26
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import android.graphics.drawable.Drawable;
2929
import android.media.MediaMetadataRetriever;
3030
import android.net.Uri;
31-
import android.os.Handler;
3231
import android.os.ParcelFileDescriptor;
3332
import android.view.ViewGroup;
3433
import android.widget.ImageView;
@@ -90,7 +89,6 @@
9089
import org.robolectric.annotation.LooperMode;
9190
import org.robolectric.annotation.Resetter;
9291
import org.robolectric.shadow.api.Shadow;
93-
import org.robolectric.shadows.ShadowBitmap;
9492

9593
/** Tests for the {@link Glide} interface and singleton. */
9694
@LooperMode(LEGACY)
@@ -100,7 +98,6 @@
10098
shadows = {
10199
GlideTest.ShadowFileDescriptorContentResolver.class,
102100
GlideTest.ShadowMediaMetadataRetriever.class,
103-
GlideTest.MutableShadowBitmap.class
104101
})
105102
@SuppressWarnings("unchecked")
106103
public class GlideTest {
@@ -116,7 +113,6 @@ public class GlideTest {
116113
@Mock private DiskCache.Factory diskCacheFactory;
117114
@Mock private DiskCache diskCache;
118115
@Mock private MemoryCache memoryCache;
119-
@Mock private Handler bgHandler;
120116
@Mock private Lifecycle lifecycle;
121117
@Mock private RequestManagerTreeNode treeNode;
122118
@Mock private BitmapPool bitmapPool;
@@ -155,17 +151,6 @@ public void setUp() {
155151
imageView.layout(0, 0, 100, 100);
156152
doAnswer(new CallSizeReady()).when(target).getSize(isA(SizeReadyCallback.class));
157153

158-
when(bgHandler.post(isA(Runnable.class)))
159-
.thenAnswer(
160-
new Answer<Boolean>() {
161-
@Override
162-
public Boolean answer(InvocationOnMock invocation) {
163-
Runnable runnable = (Runnable) invocation.getArguments()[0];
164-
runnable.run();
165-
return true;
166-
}
167-
});
168-
169154
requestManager = new RequestManager(Glide.get(context), lifecycle, treeNode, context);
170155
requestManager.resumeRequests();
171156
}
@@ -878,17 +863,6 @@ public AssetFileDescriptor openAssetFileDescriptor(Uri uri, String type) {
878863
}
879864
}
880865

881-
@Implements(Bitmap.class)
882-
public static class MutableShadowBitmap extends ShadowBitmap {
883-
884-
@Implementation
885-
public static Bitmap createBitmap(int width, int height, Bitmap.Config config) {
886-
Bitmap bitmap = ShadowBitmap.createBitmap(width, height, config);
887-
Shadows.shadowOf(bitmap).setMutable(true);
888-
return bitmap;
889-
}
890-
}
891-
892866
@Implements(MediaMetadataRetriever.class)
893867
public static class ShadowMediaMetadataRetriever {
894868

library/test/src/test/java/com/bumptech/glide/load/resource/bitmap/TransformationUtilsTest.java

+1-19
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import androidx.exifinterface.media.ExifInterface;
1818
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
1919
import com.bumptech.glide.tests.Util;
20-
import com.bumptech.glide.util.Preconditions;
2120
import com.google.common.collect.Range;
2221
import org.junit.Before;
2322
import org.junit.Test;
@@ -27,14 +26,9 @@
2726
import org.robolectric.RobolectricTestRunner;
2827
import org.robolectric.Shadows;
2928
import org.robolectric.annotation.Config;
30-
import org.robolectric.annotation.Implementation;
31-
import org.robolectric.annotation.Implements;
32-
import org.robolectric.shadows.ShadowBitmap;
3329

3430
@RunWith(RobolectricTestRunner.class)
35-
@Config(
36-
sdk = 28,
37-
shadows = {TransformationUtilsTest.AlphaShadowBitmap.class})
31+
@Config(sdk = 28)
3832
public class TransformationUtilsTest {
3933

4034
@Mock private BitmapPool bitmapPool;
@@ -449,16 +443,4 @@ public void testInitializeMatrixSetsRotateOnRotation() {
449443
TransformationUtils.initializeMatrixForRotation(ExifInterface.ORIENTATION_ROTATE_270, matrix);
450444
verify(matrix).setRotate(-90);
451445
}
452-
453-
@Implements(Bitmap.class)
454-
public static class AlphaShadowBitmap extends ShadowBitmap {
455-
456-
@Implementation
457-
public static Bitmap createBitmap(int width, int height, Bitmap.Config config) {
458-
// Robolectric doesn't match the framework behavior with null configs, so we have to do so
459-
// here.
460-
Preconditions.checkNotNull("Config must not be null");
461-
return ShadowBitmap.createBitmap(width, height, config);
462-
}
463-
}
464446
}

third_party/gif_decoder/src/test/java/com/bumptech/glide/gifdecoder/GifDecoderTest.java

+2-31
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,17 @@
33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertNotNull;
55
import static org.junit.Assert.assertTrue;
6-
import static org.robolectric.Shadows.shadowOf;
76

87
import android.graphics.Bitmap;
98
import androidx.annotation.NonNull;
109
import com.bumptech.glide.testutil.TestUtil;
1110
import java.io.IOException;
12-
import java.util.Arrays;
1311
import org.junit.Before;
1412
import org.junit.Test;
1513
import org.junit.runner.RunWith;
1614
import org.robolectric.RobolectricTestRunner;
1715
import org.robolectric.Shadows;
1816
import org.robolectric.annotation.Config;
19-
import org.robolectric.annotation.Implementation;
20-
import org.robolectric.annotation.Implements;
21-
import org.robolectric.shadows.ShadowBitmap;
2217

2318
/** Tests for {@link com.bumptech.glide.gifdecoder.GifDecoder}. */
2419
@RunWith(RobolectricTestRunner.class)
@@ -141,7 +136,6 @@ public void testSettingDataResetsFramePointer() {
141136
}
142137

143138
@Test
144-
@Config(shadows = {CustomShadowBitmap.class})
145139
public void testFirstFrameMustClearBeforeDrawingWhenLastFrameIsDisposalBackground()
146140
throws IOException {
147141
byte[] data = TestUtil.resourceToBytes(getClass(), "transparent_disposal_background.gif");
@@ -156,12 +150,10 @@ public void testFirstFrameMustClearBeforeDrawingWhenLastFrameIsDisposalBackgroun
156150
decoder.getNextFrame();
157151
decoder.advance();
158152
Bitmap firstFrameTwice = decoder.getNextFrame();
159-
assertTrue(Arrays.equals((((CustomShadowBitmap) shadowOf(firstFrame))).getPixels(),
160-
(((CustomShadowBitmap) shadowOf(firstFrameTwice))).getPixels()));
153+
assertTrue(firstFrame.sameAs(firstFrameTwice));
161154
}
162155

163156
@Test
164-
@Config(shadows = {CustomShadowBitmap.class})
165157
public void testFirstFrameMustClearBeforeDrawingWhenLastFrameIsDisposalNone() throws IOException {
166158
byte[] data = TestUtil.resourceToBytes(getClass(), "transparent_disposal_none.gif");
167159
GifHeaderParser headerParser = new GifHeaderParser();
@@ -175,28 +167,7 @@ public void testFirstFrameMustClearBeforeDrawingWhenLastFrameIsDisposalNone() th
175167
decoder.getNextFrame();
176168
decoder.advance();
177169
Bitmap firstFrameTwice = decoder.getNextFrame();
178-
assertTrue(Arrays.equals((((CustomShadowBitmap) shadowOf(firstFrame))).getPixels(),
179-
(((CustomShadowBitmap) shadowOf(firstFrameTwice))).getPixels()));
180-
}
181-
182-
/**
183-
* Preserve generated bitmap data for checking.
184-
*/
185-
@Implements(Bitmap.class)
186-
public static class CustomShadowBitmap extends ShadowBitmap {
187-
188-
private int[] pixels;
189-
190-
@Implementation
191-
public void setPixels(int[] pixels, int offset, int stride,
192-
int x, int y, int width, int height) {
193-
this.pixels = new int[pixels.length];
194-
System.arraycopy(pixels, 0, this.pixels, 0, this.pixels.length);
195-
}
196-
197-
public int[] getPixels() {
198-
return pixels;
199-
}
170+
assertTrue(firstFrame.sameAs(firstFrameTwice));
200171
}
201172

202173
private static class MockProvider implements GifDecoder.BitmapProvider {

0 commit comments

Comments
 (0)