ScreenshotAxeImage extends AxeImage { @Override public String toBase64Png() { ByteArrayOutputStream byteArrayOutputStream = byteArrayOutputStreamProvider.get(); screenshot.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); byte[] byteArray = byteArrayOutputStream.toByteArray(); return Base64.encodeToString(byteArray, Base64.NO_WRAP); } ScreenshotAxeImage(
      Bitmap screenshot, ByteArrayOutputStreamProvider byteArrayOutputStreamProvider); @Override AxeRect frame(); @Override AxeColor pixel(int x, int y); @Override String toBase64Png();  }
@Test public void toBase64PngReturnsCorrectString() { byte[] byteArrayStub = new byte[1]; String expectedString = "some string"; PowerMockito.mockStatic(Base64.class); when(byteArrayOutputStreamProviderMock.get()).thenReturn(byteArrayOutputStreamMock); when(byteArrayOutputStreamMock.toByteArray()).thenReturn(byteArrayStub); when(Base64.encodeToString(byteArrayStub, Base64.NO_WRAP)).thenReturn(expectedString); Assert.assertEquals(testSubject.toBase64Png(), expectedString); verify(bitmapMock, times(1)) .compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStreamMock); }