Search in sources :

Example 31 with Result

use of com.squareup.picasso3.RequestHandler.Result in project picasso by square.

the class BitmapHunterTest method exifRotationSizing.

@Test
public void exifRotationSizing() {
    Request data = new Request.Builder(URI_1).resize(5, 10).build();
    Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888);
    Bitmap result = transformResult(data, source, ORIENTATION_ROTATE_90);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isSameInstanceAs(source);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPreOperations()).contains("scale 1.0 0.5");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso3.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso3.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Example 32 with Result

use of com.squareup.picasso3.RequestHandler.Result in project picasso by square.

the class BitmapHunterTest method huntDecodesWithRequestHandler.

@Test
public void huntDecodesWithRequestHandler() throws Exception {
    Action action = mockAction(CUSTOM_URI_KEY, CUSTOM_URI);
    BitmapHunter hunter = forRequest(mockPicasso(new CustomRequestHandler()), dispatcher, cache, action);
    RequestHandler.Result.Bitmap result = hunter.hunt();
    assertThat(result.getBitmap()).isEqualTo(bitmap);
}
Also used : TestUtils.mockAction(com.squareup.picasso3.TestUtils.mockAction) MatrixTransformation.transformResult(com.squareup.picasso3.MatrixTransformation.transformResult) Test(org.junit.Test)

Example 33 with Result

use of com.squareup.picasso3.RequestHandler.Result in project picasso by square.

the class BitmapHunterTest method huntReturnsWhenResultInCache.

@Test
public void huntReturnsWhenResultInCache() throws Exception {
    cache.set(URI_KEY_1 + KEY_SEPARATOR, bitmap);
    Action action = mockAction(URI_KEY_1, URI_1, mockImageViewTarget());
    TestableBitmapHunter hunter = new TestableBitmapHunter(picasso, dispatcher, cache, action, bitmap);
    RequestHandler.Result.Bitmap result = hunter.hunt();
    assertThat(cache.hitCount()).isEqualTo(1);
    assertThat(result).isNotNull();
    assertThat(result.getBitmap()).isEqualTo(bitmap);
    assertThat(result.loadedFrom).isEqualTo(MEMORY);
    verify(picasso, never()).bitmapDecoded(bitmap);
}
Also used : TestUtils.mockAction(com.squareup.picasso3.TestUtils.mockAction) MatrixTransformation.transformResult(com.squareup.picasso3.MatrixTransformation.transformResult) Test(org.junit.Test)

Example 34 with Result

use of com.squareup.picasso3.RequestHandler.Result in project picasso by square.

the class BitmapHunterTest method huntDecodesWhenNotInCache.

@Test
public void huntDecodesWhenNotInCache() throws Exception {
    Action action = mockAction(URI_KEY_1, URI_1, mockImageViewTarget());
    TestableBitmapHunter hunter = new TestableBitmapHunter(picasso, dispatcher, cache, action, bitmap);
    RequestHandler.Result.Bitmap result = hunter.hunt();
    assertThat(cache.missCount()).isEqualTo(1);
    assertThat(result).isNotNull();
    assertThat(result.getBitmap()).isEqualTo(bitmap);
    assertThat(result.loadedFrom).isEqualTo(NETWORK);
    verify(picasso).bitmapDecoded(bitmap);
}
Also used : TestUtils.mockAction(com.squareup.picasso3.TestUtils.mockAction) MatrixTransformation.transformResult(com.squareup.picasso3.MatrixTransformation.transformResult) Test(org.junit.Test)

Example 35 with Result

use of com.squareup.picasso3.RequestHandler.Result in project picasso by square.

the class BitmapHunterTest method centerCropWithGravityVerticalTop.

@Test
public void centerCropWithGravityVerticalTop() {
    Bitmap source = Bitmap.createBitmap(10, 20, ARGB_8888);
    Request data = new Request.Builder(URI_1).resize(40, 40).centerCrop(Gravity.TOP).build();
    Bitmap result = transformResult(data, source, 0);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isSameInstanceAs(source);
    assertThat(shadowBitmap.getCreatedFromX()).isEqualTo(0);
    assertThat(shadowBitmap.getCreatedFromY()).isEqualTo(0);
    assertThat(shadowBitmap.getCreatedFromWidth()).isEqualTo(10);
    assertThat(shadowBitmap.getCreatedFromHeight()).isEqualTo(10);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPreOperations()).containsExactly("scale 4.0 4.0");
}
Also used : TestUtils.makeBitmap(com.squareup.picasso3.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) BitmapHunter.forRequest(com.squareup.picasso3.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) ShadowMatrix(org.robolectric.shadows.ShadowMatrix) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)52 Bitmap (android.graphics.Bitmap)46 TestUtils.makeBitmap (com.squareup.picasso3.TestUtils.makeBitmap)44 BitmapHunter.forRequest (com.squareup.picasso3.BitmapHunter.forRequest)42 ShadowBitmap (org.robolectric.shadows.ShadowBitmap)42 Matrix (android.graphics.Matrix)31 ShadowMatrix (org.robolectric.shadows.ShadowMatrix)31 Result (com.squareup.picasso3.RequestHandler.Result)7 TestUtils.mockAction (com.squareup.picasso3.TestUtils.mockAction)6 MatrixTransformation.transformResult (com.squareup.picasso3.MatrixTransformation.transformResult)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 FakeAction (com.squareup.picasso3.TestUtils.FakeAction)2 Uri (android.net.Uri)1 Message (android.os.Message)1 IOException (java.io.IOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ResponseBody (okhttp3.ResponseBody)1 Buffer (okio.Buffer)1