Search in sources :

Example 26 with Result

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

the class PicassoTest method resumeActionTriggersSubmitOnPausedAction.

@Test
public void resumeActionTriggersSubmitOnPausedAction() {
    Request request = new Request.Builder(URI_1, 0, ARGB_8888).build();
    Action action = new Action(mockPicasso(), request) {

        @Override
        public void complete(RequestHandler.Result result) {
            fail("Test execution should not call this method");
        }

        @Override
        public void error(Exception e) {
            fail("Test execution should not call this method");
        }

        @NonNull
        @Override
        public Object getTarget() {
            return this;
        }
    };
    picasso.resumeAction(action);
    verify(dispatcher).dispatchSubmit(action);
}
Also used : FakeAction(com.squareup.picasso3.TestUtils.FakeAction) TestUtils.mockAction(com.squareup.picasso3.TestUtils.mockAction) Test(org.junit.Test)

Example 27 with Result

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

the class DispatcherTest method performCompleteSetsResultInCache.

@Test
public void performCompleteSetsResultInCache() {
    Request data = new Request.Builder(URI_1).build();
    Action action = noopAction(data);
    BitmapHunter hunter = mockHunter(new RequestHandler.Result.Bitmap(bitmap1, MEMORY), action);
    hunter.run();
    assertThat(cache.size()).isEqualTo(0);
    dispatcher.performComplete(hunter);
    assertThat(hunter.getResult()).isInstanceOf(RequestHandler.Result.Bitmap.class);
    RequestHandler.Result.Bitmap result = (RequestHandler.Result.Bitmap) hunter.getResult();
    assertThat(result.getBitmap()).isEqualTo(bitmap1);
    assertThat(result.loadedFrom).isEqualTo(NETWORK);
    assertThat(cache.get(hunter.getKey())).isSameInstanceAs(bitmap1);
}
Also used : TestUtils.mockAction(com.squareup.picasso3.TestUtils.mockAction) TestUtils.makeBitmap(com.squareup.picasso3.TestUtils.makeBitmap) Bitmap(android.graphics.Bitmap) Test(org.junit.Test)

Example 28 with Result

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

the class BitmapHunterTest method onlyScaleDownOriginalSmallerHeightIs0.

@Test
public void onlyScaleDownOriginalSmallerHeightIs0() {
    Bitmap source = Bitmap.createBitmap(50, 50, ARGB_8888);
    Request data = new Request.Builder(URI_1).resize(60, 0).onlyScaleDown().build();
    Bitmap result = transformResult(data, source, 0);
    assertThat(result).isSameInstanceAs(source);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isNull();
}
Also used : TestUtils.makeBitmap(com.squareup.picasso3.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) BitmapHunter.forRequest(com.squareup.picasso3.BitmapHunter.forRequest) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Test(org.junit.Test)

Example 29 with Result

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

the class BitmapHunterTest method exifVerticalFlip.

@Test
public void exifVerticalFlip() {
    Request data = new Request.Builder(URI_1).rotate(-45).build();
    Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888);
    Bitmap result = transformResult(data, source, ORIENTATION_FLIP_VERTICAL);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isSameInstanceAs(source);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPostOperations()).containsExactly("scale -1.0 1.0");
    assertThat(shadowMatrix.getPreOperations()).containsExactly("rotate 180.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)

Example 30 with Result

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

the class BitmapHunterTest method recycledTransformationBitmapThrows.

@Test
public void recycledTransformationBitmapThrows() {
    Transformation badTransformation = new Transformation() {

        @Override
        public RequestHandler.Result.Bitmap transform(RequestHandler.Result.Bitmap source) {
            source.getBitmap().recycle();
            return source;
        }

        @Override
        public String key() {
            return "test";
        }
    };
    List<Transformation> transformations = Collections.singletonList(badTransformation);
    Bitmap original = Bitmap.createBitmap(10, 10, ARGB_8888);
    RequestHandler.Result.Bitmap result = new RequestHandler.Result.Bitmap(original, MEMORY, 0);
    Request data = new Request.Builder(URI_1).build();
    try {
        BitmapHunter.applyTransformations(picasso, data, transformations, result);
        shadowOf(getMainLooper()).idle();
        fail("Expected exception to be thrown.");
    } catch (RuntimeException e) {
        assertThat(e).hasMessageThat().isEqualTo("Transformation " + badTransformation.key() + " returned a recycled Bitmap.");
    }
}
Also used : TestUtils.makeBitmap(com.squareup.picasso3.TestUtils.makeBitmap) ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) BitmapHunter.forRequest(com.squareup.picasso3.BitmapHunter.forRequest) MatrixTransformation.transformResult(com.squareup.picasso3.MatrixTransformation.transformResult) 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