@Test public void cachedResponseDoesNotDispatchToStats() throws Exception { Response response = new Response(mockInputStream(), true, 1024); when(downloader.load(any(Uri.class), anyInt())).thenReturn(response); Action action = TestUtils.mockAction(URI_KEY_1, URI_1); networkHandler.load(action.getRequest(), 0); verifyZeroInteractions(stats); }
@Override @Nullable public Result load(Request request, int networkPolicy) throws IOException { Response response = downloader.load(request.uri, request.networkPolicy); if (response == null) { return null; } Picasso.LoadedFrom loadedFrom = response.cached ? DISK : NETWORK; InputStream is = response.getInputStream(); if (loadedFrom == DISK && response.getContentLength() == 0) { Utils.closeQuietly(is); throw new ContentLengthException("Received response with 0 content-length header."); } if (loadedFrom == NETWORK && response.getContentLength() > 0) { stats.dispatchDownloadFinished(response.getContentLength()); } return new Result(is, loadedFrom); }
NetworkRequestHandler extends RequestHandler { @Override @Nullable public Result load(Request request, int networkPolicy) throws IOException { Response response = downloader.load(request.uri, request.networkPolicy); if (response == null) { return null; } Picasso.LoadedFrom loadedFrom = response.cached ? DISK : NETWORK; InputStream is = response.getInputStream(); if (loadedFrom == DISK && response.getContentLength() == 0) { Utils.closeQuietly(is); throw new ContentLengthException("Received response with 0 content-length header."); } if (loadedFrom == NETWORK && response.getContentLength() > 0) { stats.dispatchDownloadFinished(response.getContentLength()); } return new Result(is, loadedFrom); } }
NetworkRequestHandler extends RequestHandler { @Override @Nullable public Result load(Request request, int networkPolicy) throws IOException { Response response = downloader.load(request.uri, request.networkPolicy); if (response == null) { return null; } Picasso.LoadedFrom loadedFrom = response.cached ? DISK : NETWORK; InputStream is = response.getInputStream(); if (loadedFrom == DISK && response.getContentLength() == 0) { Utils.closeQuietly(is); throw new ContentLengthException("Received response with 0 content-length header."); } if (loadedFrom == NETWORK && response.getContentLength() > 0) { stats.dispatchDownloadFinished(response.getContentLength()); } return new Result(is, loadedFrom); } NetworkRequestHandler(Downloader downloader, Stats stats); }
NetworkRequestHandler extends RequestHandler { @Override @Nullable public Result load(Request request, int networkPolicy) throws IOException { Response response = downloader.load(request.uri, request.networkPolicy); if (response == null) { return null; } Picasso.LoadedFrom loadedFrom = response.cached ? DISK : NETWORK; InputStream is = response.getInputStream(); if (loadedFrom == DISK && response.getContentLength() == 0) { Utils.closeQuietly(is); throw new ContentLengthException("Received response with 0 content-length header."); } if (loadedFrom == NETWORK && response.getContentLength() > 0) { stats.dispatchDownloadFinished(response.getContentLength()); } return new Result(is, loadedFrom); } NetworkRequestHandler(Downloader downloader, Stats stats); @Override boolean canHandleRequest(Request data); @Override @Nullable Result load(Request request, int networkPolicy); }
NetworkRequestHandler extends RequestHandler { @Override @Nullable public Result load(Request request, int networkPolicy) throws IOException { Response response = downloader.load(request.uri, request.networkPolicy); if (response == null) { return null; } Picasso.LoadedFrom loadedFrom = response.cached ? DISK : NETWORK; InputStream is = response.getInputStream(); if (loadedFrom == DISK && response.getContentLength() == 0) { Utils.closeQuietly(is); throw new ContentLengthException("Received response with 0 content-length header."); } if (loadedFrom == NETWORK && response.getContentLength() > 0) { stats.dispatchDownloadFinished(response.getContentLength()); } return new Result(is, loadedFrom); } NetworkRequestHandler(Downloader downloader, Stats stats); @Override boolean canHandleRequest(Request data); @Override @Nullable Result load(Request request, int networkPolicy);  }