@Test
public void testLoads_savesSource() throws IOException {

    MirageRequest request = mock(MirageRequest.class);
    UrlFactory factory = mock(UrlFactory.class);
    InputStream inputStream = mock(InputStream.class);
    when(factory.getStream(any(Uri.class))).thenReturn(inputStream);
    when(request.urlFactory()).thenReturn(factory);
    when(request.uri()).thenReturn(Uri.parse("http://www.sample.com/"));
    when(request.isRequestShouldSaveSource()).thenReturn(true);
    when(request.keyMaker()).thenReturn(new SimpleKeyMaker());
    DiskCache diskCache = mock(DiskCache.class);
    MemoryCache<String, Bitmap> memCache = mock(MemoryCache.class);
    when(request.diskCache()).thenReturn(diskCache);
    when(request.memoryCache()).thenReturn(memCache);
    SavingStreamProvider provider = new SavingStreamProvider(request) {
        @Override
        protected InputStream stream() throws IOException {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            Bitmap bitmap = Bitmap.createBitmap(400, 600, Bitmap.Config.ARGB_8888);
            bitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
            byte[] bitmapdata = bos.toByteArray();
            ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata);
            return bs;
        }
    };
    when(request.provider()).thenReturn(provider);
    Bitmap bitmap = provider.load();
    verify(diskCache, times(1)).put(anyString(), any(DiskCache.Writer.class));
    verify(diskCache, times(1)).get(anyString());
}