use of com.squareup.picasso3.TestUtils.mockAction in project picasso by square.
the class NetworkRequestHandlerTest method cachedResponseDoesNotDispatchToStats.
@Test
public void cachedResponseDoesNotDispatchToStats() throws Exception {
responses.add(responseOf(ResponseBody.create(null, new byte[10])).newBuilder().cacheResponse(responseOf(null)).build());
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, never()).downloadFinished(anyInt());
latch.countDown();
}
@Override
public void onError(@NonNull Throwable t) {
throw new AssertionError(t);
}
});
assertThat(latch.await(10, SECONDS)).isTrue();
}
use of com.squareup.picasso3.TestUtils.mockAction in project picasso by square.
the class NetworkRequestHandlerTest method unknownContentLengthFromDiskThrows.
@Test
public void unknownContentLengthFromDiskThrows() throws Exception {
final AtomicBoolean closed = new AtomicBoolean();
ResponseBody body = new ResponseBody() {
@Override
public MediaType contentType() {
return null;
}
@Override
public long contentLength() {
return 0;
}
@Override
public BufferedSource source() {
return new Buffer();
}
@Override
public void close() {
closed.set(true);
super.close();
}
};
responses.add(responseOf(body).newBuilder().cacheResponse(responseOf(null)).build());
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) {
throw new AssertionError();
}
@Override
public void onError(@NonNull Throwable t) {
verify(picasso, never()).downloadFinished(anyInt());
assertTrue(closed.get());
latch.countDown();
}
});
assertThat(latch.await(10, SECONDS)).isTrue();
}
use of com.squareup.picasso3.TestUtils.mockAction 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.TestUtils.mockAction 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