use of com.squareup.picasso3.RequestHandler.Result in project picasso by square.
the class NetworkRequestHandlerTest method noCacheAndKnownContentLengthDispatchToStats.
@Test
public void noCacheAndKnownContentLengthDispatchToStats() throws Exception {
responses.add(responseOf(ResponseBody.create(null, new byte[10])));
Action action = TestUtils.mockAction(URI_KEY_1, URI_1);
final CountDownLatch latch = new CountDownLatch(1);
networkHandler.load(picasso, action.request, new RequestHandler.Callback() {
@Override
public void onSuccess(Result result) {
verify(picasso).downloadFinished(10);
latch.countDown();
}
@Override
public void onError(@NonNull Throwable t) {
throw new AssertionError(t);
}
});
assertThat(latch.await(10, SECONDS)).isTrue();
}
use of com.squareup.picasso3.RequestHandler.Result in project picasso by square.
the class BitmapHunterTest method keepsAspectRationWhileResizingWhenDesiredHeightIs0.
@Test
public void keepsAspectRationWhileResizingWhenDesiredHeightIs0() {
Request request = new Request.Builder(URI_1).resize(0, 10).build();
Bitmap source = Bitmap.createBitmap(40, 20, ARGB_8888);
Bitmap result = transformResult(request, source, 0);
ShadowBitmap shadowBitmap = shadowOf(result);
Matrix matrix = shadowBitmap.getCreatedFromMatrix();
ShadowMatrix shadowMatrix = shadowOf(matrix);
assertThat(shadowMatrix.getPreOperations()).containsExactly("scale 0.5 0.5");
}
use of com.squareup.picasso3.RequestHandler.Result in project picasso by square.
the class BitmapHunterTest method centerInsideWideTooLarge.
@Test
public void centerInsideWideTooLarge() {
Bitmap source = Bitmap.createBitmap(50, 100, ARGB_8888);
Request data = new Request.Builder(URI_1).resize(50, 50).centerInside().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.5 0.5");
}
use of com.squareup.picasso3.RequestHandler.Result in project picasso by square.
the class BitmapHunterTest method centerCropWithGravityHorizontalRight.
@Test
public void centerCropWithGravityHorizontalRight() {
Bitmap source = Bitmap.createBitmap(20, 10, ARGB_8888);
Request data = new Request.Builder(URI_1).resize(40, 40).centerCrop(Gravity.RIGHT).build();
Bitmap result = transformResult(data, source, 0);
ShadowBitmap shadowBitmap = shadowOf(result);
assertThat(shadowBitmap.getCreatedFromBitmap()).isSameInstanceAs(source);
assertThat(shadowBitmap.getCreatedFromX()).isEqualTo(10);
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");
}
use of com.squareup.picasso3.RequestHandler.Result in project picasso by square.
the class NetworkRequestHandlerTest method doesNotForceLocalCacheOnlyWithAirplaneModeOffAndRetryCount.
@Test
public void doesNotForceLocalCacheOnlyWithAirplaneModeOffAndRetryCount() throws Exception {
responses.add(responseOf(ResponseBody.create(null, new byte[10])));
Action action = TestUtils.mockAction(URI_KEY_1, URI_1);
final CountDownLatch latch = new CountDownLatch(1);
networkHandler.load(picasso, action.request, new RequestHandler.Callback() {
@Override
public void onSuccess(Result result) {
try {
assertThat(requests.takeFirst().cacheControl().toString()).isEmpty();
latch.countDown();
} catch (InterruptedException e) {
throw new AssertionError(e);
}
}
@Override
public void onError(@NonNull Throwable t) {
throw new AssertionError(t);
}
});
assertThat(latch.await(10, SECONDS)).isTrue();
}
Aggregations