mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

* Revert "Revert "Move mockito to 3.0.0-alpha. (#15949)" (#15979)" This reverts commite59651f925
. * More thenReturn to thenAnswer when mocking Futures * Revert "More thenReturn to thenAnswer when mocking Futures" This reverts commit194d2cf417
as we are reverting engine roll. * Revert "Revert "More thenReturn to thenAnswer when mocking Futures"" This reverts commit52c9e96b30
. * Add dependency override * Fix issue
35 lines
1.7 KiB
Dart
35 lines
1.7 KiB
Dart
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:mockito/mockito.dart';
|
|
|
|
import '../../../packages/flutter/test/painting/image_data.dart';
|
|
|
|
// Returns a mock HTTP client that responds with an image to all requests.
|
|
MockHttpClient createMockImageHttpClient(SecurityContext _) {
|
|
final MockHttpClient client = new MockHttpClient();
|
|
final MockHttpClientRequest request = new MockHttpClientRequest();
|
|
final MockHttpClientResponse response = new MockHttpClientResponse();
|
|
final MockHttpHeaders headers = new MockHttpHeaders();
|
|
when(client.getUrl(typed(any))).thenAnswer((_) => new Future<HttpClientRequest>.value(request));
|
|
when(request.headers).thenReturn(headers);
|
|
when(request.close()).thenAnswer((_) => new Future<HttpClientResponse>.value(response));
|
|
when(response.contentLength).thenReturn(kTransparentImage.length);
|
|
when(response.statusCode).thenReturn(HttpStatus.OK);
|
|
when(response.listen(typed(any))).thenAnswer((Invocation invocation) {
|
|
final void Function(List<int>) onData = invocation.positionalArguments[0];
|
|
final void Function() onDone = invocation.namedArguments[#onDone];
|
|
final void Function(Object, [StackTrace]) onError = invocation.namedArguments[#onError];
|
|
final bool cancelOnError = invocation.namedArguments[#cancelOnError];
|
|
return new Stream<List<int>>.fromIterable(<List<int>>[kTransparentImage]).listen(onData, onDone: onDone, onError: onError, cancelOnError: cancelOnError);
|
|
});
|
|
return client;
|
|
}
|
|
|
|
class MockHttpClient extends Mock implements HttpClient {}
|
|
|
|
class MockHttpClientRequest extends Mock implements HttpClientRequest {}
|
|
|
|
class MockHttpClientResponse extends Mock implements HttpClientResponse {}
|
|
|
|
class MockHttpHeaders extends Mock implements HttpHeaders {} |