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);
}
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);
}
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();
}
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");
}
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.");
}
}
Aggregations