stubOpenUrlCallsWithTransparentImage method

void stubOpenUrlCallsWithTransparentImage()

Stubs calls to HttpClient.openUrl on the client to return a transparent image.

Implementation

void stubOpenUrlCallsWithTransparentImage() {
  when(client.openUrl(any, any)).thenAnswer((invocation) {
    final body = kTransparentImage;

    final request = MockHttpClientRequest();
    final response = MockHttpClientResponse();

    when(request.close()).thenAnswer((_) => Future.value(response));
    when(request.addStream(any)).thenAnswer((_) async => null);
    when(request.headers).thenReturn(MockHttpHeaders());

    when(response.headers).thenReturn(MockHttpHeaders());
    when(response.handleError(any, test: anyNamed('test')))
        .thenAnswer((_) => Stream.value(body));
    when(response.statusCode).thenReturn(200);
    when(response.reasonPhrase).thenReturn('OK');
    when(response.contentLength).thenReturn(body.length);
    when(response.isRedirect).thenReturn(false);
    when(response.persistentConnection).thenReturn(false);
    when(response.redirects).thenReturn([]);

    return Future.value(request);
  });
}