Search in sources :

Example 11 with Result

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

the class BitmapHunterTest method onlyScaleDownOriginalBiggerHeightIs0.

@Test
public void onlyScaleDownOriginalBiggerHeightIs0() {
    Bitmap source = Bitmap.createBitmap(50, 50, ARGB_8888);
    Request data = new Request.Builder(URI_1).resize(40, 0).onlyScaleDown().build();
    Bitmap result = transformResult(data, source, 0);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isSameInstanceAs(source);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPreOperations()).containsExactly("scale 0.8 0.8");
}
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 12 with Result

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

the class BitmapHunterTest method crashingOnTransformationThrows.

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

        @Override
        public RequestHandler.Result.Bitmap transform(RequestHandler.Result.Bitmap source) {
            throw new NullPointerException("hello");
        }

        @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() + " crashed with exception.");
    }
}
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)

Example 13 with Result

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

the class BitmapHunterTest method exifRotation.

@Test
public void exifRotation() {
    Request data = new Request.Builder(URI_1).rotate(-45).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()).containsExactly("rotate 90.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 14 with Result

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

the class BitmapHunterTest method centerCropWideTooLarge.

@Test
public void centerCropWideTooLarge() {
    Bitmap source = Bitmap.createBitmap(200, 100, ARGB_8888);
    Request data = new Request.Builder(URI_1).resize(50, 50).centerCrop().build();
    Bitmap result = transformResult(data, source, 0);
    ShadowBitmap shadowBitmap = shadowOf(result);
    assertThat(shadowBitmap.getCreatedFromBitmap()).isSameInstanceAs(source);
    assertThat(shadowBitmap.getCreatedFromX()).isEqualTo(50);
    assertThat(shadowBitmap.getCreatedFromY()).isEqualTo(0);
    assertThat(shadowBitmap.getCreatedFromWidth()).isEqualTo(100);
    assertThat(shadowBitmap.getCreatedFromHeight()).isEqualTo(100);
    Matrix matrix = shadowBitmap.getCreatedFromMatrix();
    ShadowMatrix shadowMatrix = shadowOf(matrix);
    assertThat(shadowMatrix.getPreOperations()).containsExactly("scale 0.5 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 15 with Result

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

the class BitmapHunterTest method centerCropResultMatchesTargetSize.

@Test
public void centerCropResultMatchesTargetSize() {
    Request request = new Request.Builder(URI_1).resize(1080, 642).centerCrop().build();
    Bitmap source = Bitmap.createBitmap(640, 640, ARGB_8888);
    Bitmap result = transformResult(request, source, 0);
    assertThat(result.getWidth()).isEqualTo(1080);
    assertThat(result.getHeight()).isEqualTo(642);
}
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) 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