PhotoCaptureHelper extends CaptureHelper { protected void save(Bitmap bitmap, String fileNameWithoutExtension, int quality, String key) throws IOException, GeneralSecurityException { fileNameWithoutExtension = fileNameWithoutExtension.contains(".jpg")? fileNameWithoutExtension : fileNameWithoutExtension + ".jpg"; File file = new File(getDir(), fileNameWithoutExtension); if (!file.exists()) file.createNewFile(); @Cleanup OutputStream outputStream = getCipherOutputStream(file, key); saveImage(bitmap, outputStream, quality); } PhotoCaptureHelper(RapidFtrApplication context); File getTempCaptureFile(); Calendar getCaptureTime(); void setCaptureTime(); Bitmap getCapture(); void deleteCaptures(); Bitmap getDefaultThumbnail(); void savePhoto(Bitmap original, int rotationDegree, String fileNameWithoutExtension); void saveThumbnail(Bitmap original, int rotationDegree, String fileNameWithoutExtension); Bitmap loadThumbnail(String fileNameWithoutExtension); Bitmap loadPhoto(String fileNameWithoutExtension); InputStream getDecodedImageStream(String fileNameWithoutExtension); Bitmap getThumbnailOrDefault(String fileNameWithoutExtension); int getPictureRotation(); void convertPhoto(String photo, String existingKey, String newKey); static final int THUMBNAIL_WIDTH; static final int THUMBNAIL_HEIGHT; static final int JPEG_QUALITY; static final int PHOTO_WIDTH; static final int PHOTO_HEIGHT; static final int QUALITY; }
@Test public void testSavePhotoAndCompress() throws Exception { Bitmap bitmap = mock(Bitmap.class); File file = new File(photoCaptureHelper.getDir(), "random_file.jpg"); OutputStream out = mock(OutputStream.class); doReturn(out).when(photoCaptureHelper).getCipherOutputStream(eq(file), anyString()); doReturn(mock(User.class)).when(application).getCurrentUser(); photoCaptureHelper.save(bitmap, "random_file", QUALITY, "key"); verify(bitmap).compress(Bitmap.CompressFormat.JPEG, 85, out); verify(out).close(); }