ImageCacher { boolean cacheImage(Photo photo)throws IOException { int photoId = photo.getId(); if (isCached(photoId)) { File filePath = getImageFilePathForPhotoId(photoId); String imageFilePath = filePath.getAbsolutePath(); injectImageFilePath(photo, imageFilePath); return true; } else { String imageFilePath = photo.getImageFilePath(); return cacheImage(photo, Base64.decode(imageFilePath, Base64.DEFAULT)); } } ImageCacher(Context context);   }
@Test public void detectImageAlreadyCached() { photo = buildPhotoForImageCacher(); educateMock(String.format("%s.jpg", photo.getId())); try { assertTrue(imageCacher.cacheImage(photo)); assertTrue(imageCacher.cacheImage(photo)); } catch (IOException e) { fail(e.toString()); } }
@Test public void cacheImageWithBytes() { Gson gson = new Gson(); photo = gson.fromJson(Fakes.PHOTO_RESULT, Photo.class); educateMock(String.format("%s.jpg", photo.getId())); String base64Bytes = photo.getImageFilePath(); byte[] data = Base64.decode(base64Bytes, Base64.DEFAULT); try { assertTrue(imageCacher.cacheImage(photo, data)); } catch (IOException e) { fail(e.toString()); } }