@NonNull @Override public Bitmap get(int width, int height, Bitmap.Config config) { return Bitmap.createBitmap(width, height, config); }
private Bitmap createRect(int color, int width, int height, Bitmap.Config config) { final Bitmap result = Bitmap.createBitmap(width, height, config); Canvas canvas = new Canvas(result); canvas.drawColor(color); return result; } }
@Override public Bitmap answer(InvocationOnMock invocation) throws Throwable { int width = (Integer) invocation.getArguments()[0]; int height = (Integer) invocation.getArguments()[1]; Bitmap.Config config = (Bitmap.Config) invocation.getArguments()[2]; return Bitmap.createBitmap(width, height, config); } }
private static InputStream openBitmapStream(CompressFormat format, int width, int height) { Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); ByteArrayOutputStream os = new ByteArrayOutputStream(); bitmap.compress(format, 100 /*quality*/, os); bitmap.recycle(); byte[] data = os.toByteArray(); return new ByteArrayInputStream(data); }
private Bitmap createSolidRedBitmap(int width, int height) { Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setColor(Color.RED); Rect rect = new Rect(0, 0, width, height); canvas.drawRect(rect, paint); return result; } }
@Test public void testLoadBitmap_asDrawable() { Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); requestManager .load(bitmap) .into(target); ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class); verify(target).onResourceReady(captor.capture(), any(Transition.class)); BitmapDrawable drawable = (BitmapDrawable) captor.getValue(); assertThat(drawable.getBitmap()).isEqualTo(bitmap); }
@Test public void testReturnsCurrentTransformationInGetFrameTransformation() { @SuppressWarnings("unchecked") Transformation<Bitmap> newTransformation = mock(Transformation.class); Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); drawable.setFrameTransformation(newTransformation, bitmap); verify(frameLoader).setFrameTransformation(eq(newTransformation), eq(bitmap)); }
@Test public void testSetsFrameTransformationOnFrameManager() { Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); drawable.setFrameTransformation(transformation, bitmap); verify(frameLoader).setFrameTransformation(eq(transformation), eq(bitmap)); }
@Test public void decodeFrame_withTargetSizeOriginalWidthOnly_onApi27_doesNotThrow() throws IOException { Bitmap expected = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); when(retriever.getFrameAtTime(-1, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)) .thenReturn(expected); verify(retriever, never()).getScaledFrameAtTime(anyLong(), anyInt(), anyInt(), anyInt()); assertThat(decoder.decode(resource, Target.SIZE_ORIGINAL, 100, options).get()) .isSameAs(expected); }
@Test public void testICanAddAndGetABitmapOfTheSameSizeAndDimensions() { Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); strategy.put(bitmap); assertEquals(bitmap, strategy.get(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888)); }
@Test public void testReturnsTargetForBitmaps() { Bitmap bitmap = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888); Target<Bitmap> target = factory.buildTarget(view, Bitmap.class); target.onResourceReady(bitmap, null); assertThat(target).isInstanceOf(BitmapImageViewTarget.class); }
@Test public void testCenterCropSetsOutBitmapToHaveAlphaIfInBitmapHasAlpha() { Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); toTransform.setHasAlpha(true); Bitmap result = TransformationUtils.centerCrop(bitmapPool, toTransform, toTransform.getWidth() / 2, toTransform.getHeight() / 2); assertTrue(result.hasAlpha()); }
@Test public void testRotateImageExifReturnsGivenBitmapIfRotationIsNormal() { Bitmap toRotate = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_4444); // Use assertTrue because Robolectric incorrectly implements equality for Bitmaps. We want // not just an identical Bitmap, but our original Bitmap object back. Bitmap rotated = TransformationUtils.rotateImageExif(bitmapPool, toRotate, ExifInterface.ORIENTATION_NORMAL); assertTrue(toRotate == rotated); }
@Test public void testDoesNotReturnResourceForCompletedFrameInGetCurrentFrameIfLoadCompletesWhileCleared() { loader.clear(); DelayTarget delayTarget = mock(DelayTarget.class); Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); when(delayTarget.getResource()).thenReturn(bitmap); loader.onFrameReady(delayTarget); assertNull(loader.getCurrentFrame()); }
@Test public void testTransform_reusesBitmap() { Bitmap toReuse = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888); when(bitmapPool.get(50, 50, Bitmap.Config.ARGB_8888)).thenReturn(toReuse); Bitmap redSquare = createSolidRedBitmap(50, 50); Bitmap result = circleCrop.transform(bitmapPool, redSquare, 50, 50); assertEquals(toReuse, result); }
@Test public void testMultipleBitmapsOfDifferentAttributesCanBeAddedAtOnce() { Bitmap first = Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565); Bitmap second = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); Bitmap third = Bitmap.createBitmap(120, 120, Bitmap.Config.RGB_565); strategy.put(first); strategy.put(second); strategy.put(third); assertEquals(first, strategy.get(100, 100, Bitmap.Config.RGB_565)); assertEquals(second, strategy.get(100, 100, Bitmap.Config.ARGB_8888)); assertEquals(third, strategy.get(120, 120, Bitmap.Config.RGB_565)); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); bitmapWidth = 100; bitmapHeight = 100; Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888); when(resource.get()).thenReturn(bitmap); BitmapPool pool = new BitmapPoolAdapter(); context = RuntimeEnvironment.application; Glide.init(context, new GlideBuilder().setBitmapPool(pool)); fitCenter = new FitCenter(); }
@Test public void testICantGetABitmapOfTheSameDimensionsButDifferentConfigs() { Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); strategy.put(bitmap); assertNull(strategy.get(100, 100, Bitmap.Config.RGB_565)); }
@Test public void testICantGetABitmapOfTheSameDimensionsAndSizeButDifferentConfigs() { Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_4444); strategy.put(bitmap); assertNull(strategy.get(100, 100, Bitmap.Config.RGB_565)); }
@Test public void testDelayTargetSetsResourceOnResourceReady() { DelayTarget delayTarget = new DelayTarget(handler, 1, 1); Bitmap expected = Bitmap.createBitmap(100, 200, Bitmap.Config.RGB_565); delayTarget.onResourceReady(expected, null /*glideAnimation*/); assertEquals(expected, delayTarget.getResource()); }