diff --git a/example/android/local.properties b/example/android/local.properties index 02a5a1e..5004041 100644 --- a/example/android/local.properties +++ b/example/android/local.properties @@ -1,4 +1,4 @@ -sdk.dir=/Users/ironman/Library/Android/sdk -flutter.sdk=/Users/ironman/flutter +sdk.dir=/Users/michaelgobbers/Library/Developer/Xamarin/android-sdk-macosx +flutter.sdk=/Users/michaelgobbers/Library/Developer/flutter flutter.versionName=1.0.0 flutter.versionCode=1 \ No newline at end of file diff --git a/example/ios/Runner/GeneratedPluginRegistrant.h b/example/ios/Runner/GeneratedPluginRegistrant.h index 3b700eb..ed9a5c6 100644 --- a/example/ios/Runner/GeneratedPluginRegistrant.h +++ b/example/ios/Runner/GeneratedPluginRegistrant.h @@ -7,8 +7,11 @@ #import +NS_ASSUME_NONNULL_BEGIN + @interface GeneratedPluginRegistrant : NSObject + (void)registerWithRegistry:(NSObject*)registry; @end +NS_ASSUME_NONNULL_END #endif /* GeneratedPluginRegistrant_h */ diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 95e5eb4..f746fad 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -3,7 +3,7 @@ description: A new Flutter application. version: 1.0.0+1 environment: - sdk: ">=2.0.0-dev.68.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: diff --git a/lib/image_test_utils.dart b/lib/image_test_utils.dart index 5fa03ff..bfcd379 100644 --- a/lib/image_test_utils.dart +++ b/lib/image_test_utils.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'dart:io'; -import 'package:mockito/mockito.dart'; +import 'package:mocktail/mocktail.dart'; /// Runs [body] in a fresh [Zone] that provides mocked responses for [Image.network] widgets. /// @@ -42,7 +42,8 @@ import 'package:mockito/mockito.dart'; /// /// The underlying code is taken from the Flutter repo: /// https://github.com/flutter/flutter/blob/master/dev/manual_tests/test/mock_image_http.dart -R provideMockedNetworkImages(R body(), {List imageBytes = _transparentImage}) { +R provideMockedNetworkImages(R body(), + {List imageBytes = _transparentImage}) { return HttpOverrides.runZoned( body, createHttpClient: (_) => _createMockImageHttpClient(_, imageBytes), @@ -50,39 +51,116 @@ R provideMockedNetworkImages(R body(), {List imageBytes = _transparentIm } class MockHttpClient extends Mock implements HttpClient {} + class MockHttpClientRequest extends Mock implements HttpClientRequest {} + class MockHttpClientResponse extends Mock implements HttpClientResponse {} + class MockHttpHeaders extends Mock implements HttpHeaders {} // Returns a mock HTTP client that responds with an image to all requests. -MockHttpClient _createMockImageHttpClient(SecurityContext _, List imageBytes) { +MockHttpClient _createMockImageHttpClient( + SecurityContext? _, List imageBytes) { final MockHttpClient client = MockHttpClient(); final MockHttpClientRequest request = MockHttpClientRequest(); final MockHttpClientResponse response = MockHttpClientResponse(); final MockHttpHeaders headers = MockHttpHeaders(); - when(client.getUrl(any)).thenAnswer((_) => Future.value(request)); - when(request.headers).thenReturn(headers); - when(request.close()).thenAnswer((_) => Future.value(response)); - when(response.contentLength).thenReturn(_transparentImage.length); - when(response.statusCode).thenReturn(HttpStatus.ok); - when(response.listen(any)).thenAnswer((Invocation invocation) { - final void Function(List) 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]; + when(() => client.getUrl(any())) + .thenAnswer((_) => Future.value(request)); + when(() => client.getUrl(any())) + .thenAnswer((_) => Future.value(request)); + when(() => request.headers).thenReturn(headers); + when(() => request.close()) + .thenAnswer((_) => Future.value(response)); + when(() => response.contentLength).thenReturn(_transparentImage.length); + when(() => response.compressionState) + .thenReturn(HttpClientResponseCompressionState.notCompressed); + when(() => response.statusCode).thenReturn(HttpStatus.ok); + when(() => response.listen(any(), + onError: any(named: "onError"), + onDone: any(named: "onDone"), + cancelOnError: any(named: "cancelOnError"))) + .thenAnswer((Invocation invocation) { + final void Function(List)? 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 Stream>.fromIterable(>[imageBytes]) - .listen(onData, onDone: onDone, onError: onError, cancelOnError: cancelOnError); + return Stream>.fromIterable(>[imageBytes]).listen( + onData, + onDone: onDone, + onError: onError, + cancelOnError: cancelOnError); }); return client; } const List _transparentImage = const [ - 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, - 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x06, - 0x00, 0x00, 0x00, 0x1F, 0x15, 0xC4, 0x89, 0x00, 0x00, 0x00, 0x0A, 0x49, 0x44, - 0x41, 0x54, 0x78, 0x9C, 0x63, 0x00, 0x01, 0x00, 0x00, 0x05, 0x00, 0x01, 0x0D, - 0x0A, 0x2D, 0xB4, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, + 0x89, + 0x50, + 0x4E, + 0x47, + 0x0D, + 0x0A, + 0x1A, + 0x0A, + 0x00, + 0x00, + 0x00, + 0x0D, + 0x49, + 0x48, + 0x44, + 0x52, + 0x00, + 0x00, + 0x00, + 0x01, + 0x00, + 0x00, + 0x00, + 0x01, + 0x08, + 0x06, + 0x00, + 0x00, + 0x00, + 0x1F, + 0x15, + 0xC4, + 0x89, + 0x00, + 0x00, + 0x00, + 0x0A, + 0x49, + 0x44, + 0x41, + 0x54, + 0x78, + 0x9C, + 0x63, + 0x00, + 0x01, + 0x00, + 0x00, + 0x05, + 0x00, + 0x01, + 0x0D, + 0x0A, + 0x2D, + 0xB4, + 0x00, + 0x00, + 0x00, + 0x00, + 0x49, + 0x45, + 0x4E, + 0x44, + 0xAE, ]; diff --git a/pubspec.yaml b/pubspec.yaml index e291ee3..e1d4731 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://github.com/roughike/image_test_utils author: Iiro Krankka environment: - sdk: '>=2.0.0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dependencies: - mockito: ^3.0.0 + mocktail: ^0.1.4