AndroidUtil { public static Picture fromBitmap(Bitmap bitmap, ColorSpace colorSpace) { return inst().fromBitmapImpl(bitmap, colorSpace); } AndroidUtil(BitmapUtil bitmapUtil); static Bitmap toBitmap(Picture pic); static void toBitmap(Picture pic, Bitmap out); static Picture fromBitmap(Bitmap bitmap, ColorSpace colorSpace); static Picture fromBitmap(Bitmap bitmap, VideoEncoder encoder); static void fromBitmap(Bitmap bitmap, Picture out); Bitmap toBitmapImpl(Picture pic); void toBitmapImpl(Picture pic, Bitmap out); Picture fromBitmapImpl(Bitmap bitmap, ColorSpace colorSpace); Picture fromBitmapImpl(Bitmap bitmap, VideoEncoder encoder); void fromBitmapImpl(Bitmap bitmap, Picture out);  }
@Test public void testFromBitmap() { BitmapUtil bitmapUtil = mock(BitmapUtil.class); Picture src = Picture.create(16, 16, ColorSpace.RGB); for (int i = 0; i < 256 * 3; i += 3) { src.getPlaneData(0)[i] = (byte) (134 - 128); src.getPlaneData(0)[i + 1] = (byte) (215 - 128); src.getPlaneData(0)[i + 2] = (byte) (22 - 128); } when(bitmapUtil.fromBitmapImpl(any(Bitmap.class))).thenReturn(src); Picture expected = Picture.create(16, 16, ColorSpace.YUV420J); Arrays.fill(expected.getPlaneData(0), (byte) (168 - 128)); Arrays.fill(expected.getPlaneData(1), (byte) (45 - 128)); Arrays.fill(expected.getPlaneData(2), (byte) (103 - 128)); AndroidUtil util = new AndroidUtil(bitmapUtil); Bitmap mock = mock(Bitmap.class); when(mock.getConfig()).thenReturn(Bitmap.Config.ARGB_8888); when(mock.getWidth()).thenReturn(16); when(mock.getHeight()).thenReturn(16); Picture res = util.fromBitmapImpl(mock, ColorSpace.YUV420J); Assert.assertEquals(expected, res); }