From 8e6eadf1b9ff667b411c83d4337f8dbd598aa8bb Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Sat, 11 Feb 2023 13:50:33 +0100 Subject: [PATCH] Annotate the needed mocks for each test This makes it clear where they are loaded from --- test/gallery/gallery_form_test.dart | 5 +- test/gallery/gallery_form_test.mocks.dart | 324 ++++++++++++++++++++++ test/gallery/gallery_provider_test.dart | 11 +- test/user/provider_test.dart | 5 +- test/user/provider_test.mocks.dart | 213 ++++++++++++++ 5 files changed, 550 insertions(+), 8 deletions(-) create mode 100644 test/gallery/gallery_form_test.mocks.dart create mode 100644 test/user/provider_test.mocks.dart diff --git a/test/gallery/gallery_form_test.dart b/test/gallery/gallery_form_test.dart index 259c2a7db..fcf26cf77 100644 --- a/test/gallery/gallery_form_test.dart +++ b/test/gallery/gallery_form_test.dart @@ -19,6 +19,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:network_image_mock/network_image_mock.dart'; import 'package:provider/provider.dart'; @@ -26,10 +27,10 @@ import 'package:wger/helpers/consts.dart'; import 'package:wger/models/gallery/image.dart' as gallery; import 'package:wger/providers/gallery.dart'; import 'package:wger/widgets/gallery/forms.dart'; - -import './gallery_screen_test.mocks.dart'; import '../../test_data/gallery.dart'; +import 'gallery_form_test.mocks.dart'; +@GenerateMocks([GalleryProvider]) void main() { late gallery.Image image; final mockGalleryProvider = MockGalleryProvider(); diff --git a/test/gallery/gallery_form_test.mocks.dart b/test/gallery/gallery_form_test.mocks.dart new file mode 100644 index 000000000..510d8453f --- /dev/null +++ b/test/gallery/gallery_form_test.mocks.dart @@ -0,0 +1,324 @@ +// Mocks generated by Mockito 5.3.2 from annotations +// in wger/test/gallery/gallery_form_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i6; +import 'dart:ui' as _i8; + +import 'package:http/http.dart' as _i3; +import 'package:image_picker/image_picker.dart' as _i7; +import 'package:mockito/mockito.dart' as _i1; +import 'package:wger/models/gallery/image.dart' as _i5; +import 'package:wger/providers/auth.dart' as _i2; +import 'package:wger/providers/gallery.dart' as _i4; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider { + _FakeAuthProvider_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeClient_1 extends _i1.SmartFake implements _i3.Client { + _FakeClient_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeUri_2 extends _i1.SmartFake implements Uri { + _FakeUri_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response { + _FakeResponse_3( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [GalleryProvider]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockGalleryProvider extends _i1.Mock implements _i4.GalleryProvider { + MockGalleryProvider() { + _i1.throwOnMissingStub(this); + } + + @override + List<_i5.Image> get images => (super.noSuchMethod( + Invocation.getter(#images), + returnValue: <_i5.Image>[], + ) as List<_i5.Image>); + @override + set images(List<_i5.Image>? _images) => super.noSuchMethod( + Invocation.setter( + #images, + _images, + ), + returnValueForMissingStub: null, + ); + @override + _i2.AuthProvider get auth => (super.noSuchMethod( + Invocation.getter(#auth), + returnValue: _FakeAuthProvider_0( + this, + Invocation.getter(#auth), + ), + ) as _i2.AuthProvider); + @override + set auth(_i2.AuthProvider? _auth) => super.noSuchMethod( + Invocation.setter( + #auth, + _auth, + ), + returnValueForMissingStub: null, + ); + @override + _i3.Client get client => (super.noSuchMethod( + Invocation.getter(#client), + returnValue: _FakeClient_1( + this, + Invocation.getter(#client), + ), + ) as _i3.Client); + @override + set client(_i3.Client? _client) => super.noSuchMethod( + Invocation.setter( + #client, + _client, + ), + returnValueForMissingStub: null, + ); + @override + bool get hasListeners => (super.noSuchMethod( + Invocation.getter(#hasListeners), + returnValue: false, + ) as bool); + @override + void clear() => super.noSuchMethod( + Invocation.method( + #clear, + [], + ), + returnValueForMissingStub: null, + ); + @override + _i6.Future fetchAndSetGallery() => (super.noSuchMethod( + Invocation.method( + #fetchAndSetGallery, + [], + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); + @override + _i6.Future addImage( + _i5.Image? image, + _i7.XFile? imageFile, + ) => + (super.noSuchMethod( + Invocation.method( + #addImage, + [ + image, + imageFile, + ], + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); + @override + _i6.Future editImage( + _i5.Image? image, + _i7.XFile? imageFile, + ) => + (super.noSuchMethod( + Invocation.method( + #editImage, + [ + image, + imageFile, + ], + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); + @override + _i6.Future deleteImage(_i5.Image? image) => (super.noSuchMethod( + Invocation.method( + #deleteImage, + [image], + ), + returnValue: _i6.Future.value(), + returnValueForMissingStub: _i6.Future.value(), + ) as _i6.Future); + @override + Map getDefaultHeaders({dynamic includeAuth = false}) => (super.noSuchMethod( + Invocation.method( + #getDefaultHeaders, + [], + {#includeAuth: includeAuth}, + ), + returnValue: {}, + ) as Map); + @override + Uri makeUrl( + String? path, { + int? id, + String? objectMethod, + Map? query, + }) => + (super.noSuchMethod( + Invocation.method( + #makeUrl, + [path], + { + #id: id, + #objectMethod: objectMethod, + #query: query, + }, + ), + returnValue: _FakeUri_2( + this, + Invocation.method( + #makeUrl, + [path], + { + #id: id, + #objectMethod: objectMethod, + #query: query, + }, + ), + ), + ) as Uri); + @override + _i6.Future> fetch(Uri? uri) => (super.noSuchMethod( + Invocation.method( + #fetch, + [uri], + ), + returnValue: _i6.Future>.value({}), + ) as _i6.Future>); + @override + _i6.Future> fetchPaginated(Uri? uri) => (super.noSuchMethod( + Invocation.method( + #fetchPaginated, + [uri], + ), + returnValue: _i6.Future>.value([]), + ) as _i6.Future>); + @override + _i6.Future> post( + Map? data, + Uri? uri, + ) => + (super.noSuchMethod( + Invocation.method( + #post, + [ + data, + uri, + ], + ), + returnValue: _i6.Future>.value({}), + ) as _i6.Future>); + @override + _i6.Future> patch( + Map? data, + Uri? uri, + ) => + (super.noSuchMethod( + Invocation.method( + #patch, + [ + data, + uri, + ], + ), + returnValue: _i6.Future>.value({}), + ) as _i6.Future>); + @override + _i6.Future<_i3.Response> deleteRequest( + String? url, + int? id, + ) => + (super.noSuchMethod( + Invocation.method( + #deleteRequest, + [ + url, + id, + ], + ), + returnValue: _i6.Future<_i3.Response>.value(_FakeResponse_3( + this, + Invocation.method( + #deleteRequest, + [ + url, + id, + ], + ), + )), + ) as _i6.Future<_i3.Response>); + @override + void addListener(_i8.VoidCallback? listener) => super.noSuchMethod( + Invocation.method( + #addListener, + [listener], + ), + returnValueForMissingStub: null, + ); + @override + void removeListener(_i8.VoidCallback? listener) => super.noSuchMethod( + Invocation.method( + #removeListener, + [listener], + ), + returnValueForMissingStub: null, + ); + @override + void dispose() => super.noSuchMethod( + Invocation.method( + #dispose, + [], + ), + returnValueForMissingStub: null, + ); + @override + void notifyListeners() => super.noSuchMethod( + Invocation.method( + #notifyListeners, + [], + ), + returnValueForMissingStub: null, + ); +} diff --git a/test/gallery/gallery_provider_test.dart b/test/gallery/gallery_provider_test.dart index c74b1b426..9750866eb 100644 --- a/test/gallery/gallery_provider_test.dart +++ b/test/gallery/gallery_provider_test.dart @@ -19,9 +19,10 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:http/http.dart' as http; import 'package:mockito/mockito.dart'; -import 'package:wger/providers/gallery.dart'; -import '../other/base_provider_test.mocks.dart'; import 'package:wger/models/gallery/image.dart' as gallery; +import 'package:wger/providers/gallery.dart'; + +import '../other/base_provider_test.mocks.dart'; import '../utils.dart'; void main() { @@ -41,7 +42,7 @@ void main() { '"height":1280,"width":960}]}', 200)); - GalleryProvider galleryProvider = GalleryProvider(testAuthProvider, [], client); + final galleryProvider = GalleryProvider(testAuthProvider, [], client); await galleryProvider.fetchAndSetGallery(); @@ -63,9 +64,9 @@ void main() { '"height":1280,"width":960}', 200)); - GalleryProvider galleryProvider = GalleryProvider(testAuthProvider, [], client); + final galleryProvider = GalleryProvider(testAuthProvider, [], client); - gallery.Image image = gallery.Image( + final image = gallery.Image( id: 58, date: DateTime(2022, 01, 09), url: "https://wger.de/media/gallery/170335/d2b9c9e0-d541-41ae-8786-a2ab459e3538.jpg", diff --git a/test/user/provider_test.dart b/test/user/provider_test.dart index 395b8576c..6d13688cc 100644 --- a/test/user/provider_test.dart +++ b/test/user/provider_test.dart @@ -19,12 +19,15 @@ import 'dart:convert'; import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; +import 'package:wger/providers/base_provider.dart'; import 'package:wger/providers/user.dart'; import '../fixtures/fixture_reader.dart'; -import '../measurements/measurement_provider_test.mocks.dart'; +import 'provider_test.mocks.dart'; +@GenerateMocks([WgerBaseProvider]) void main() { late UserProvider userProvider; late MockWgerBaseProvider mockWgerBaseProvider; diff --git a/test/user/provider_test.mocks.dart b/test/user/provider_test.mocks.dart new file mode 100644 index 000000000..361839534 --- /dev/null +++ b/test/user/provider_test.mocks.dart @@ -0,0 +1,213 @@ +// Mocks generated by Mockito 5.3.2 from annotations +// in wger/test/user/provider_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i5; + +import 'package:http/http.dart' as _i3; +import 'package:mockito/mockito.dart' as _i1; +import 'package:wger/providers/auth.dart' as _i2; +import 'package:wger/providers/base_provider.dart' as _i4; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakeAuthProvider_0 extends _i1.SmartFake implements _i2.AuthProvider { + _FakeAuthProvider_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeClient_1 extends _i1.SmartFake implements _i3.Client { + _FakeClient_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeUri_2 extends _i1.SmartFake implements Uri { + _FakeUri_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeResponse_3 extends _i1.SmartFake implements _i3.Response { + _FakeResponse_3( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [WgerBaseProvider]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockWgerBaseProvider extends _i1.Mock implements _i4.WgerBaseProvider { + MockWgerBaseProvider() { + _i1.throwOnMissingStub(this); + } + + @override + _i2.AuthProvider get auth => (super.noSuchMethod( + Invocation.getter(#auth), + returnValue: _FakeAuthProvider_0( + this, + Invocation.getter(#auth), + ), + ) as _i2.AuthProvider); + @override + set auth(_i2.AuthProvider? _auth) => super.noSuchMethod( + Invocation.setter( + #auth, + _auth, + ), + returnValueForMissingStub: null, + ); + @override + _i3.Client get client => (super.noSuchMethod( + Invocation.getter(#client), + returnValue: _FakeClient_1( + this, + Invocation.getter(#client), + ), + ) as _i3.Client); + @override + set client(_i3.Client? _client) => super.noSuchMethod( + Invocation.setter( + #client, + _client, + ), + returnValueForMissingStub: null, + ); + @override + Map getDefaultHeaders({dynamic includeAuth = false}) => (super.noSuchMethod( + Invocation.method( + #getDefaultHeaders, + [], + {#includeAuth: includeAuth}, + ), + returnValue: {}, + ) as Map); + @override + Uri makeUrl( + String? path, { + int? id, + String? objectMethod, + Map? query, + }) => + (super.noSuchMethod( + Invocation.method( + #makeUrl, + [path], + { + #id: id, + #objectMethod: objectMethod, + #query: query, + }, + ), + returnValue: _FakeUri_2( + this, + Invocation.method( + #makeUrl, + [path], + { + #id: id, + #objectMethod: objectMethod, + #query: query, + }, + ), + ), + ) as Uri); + @override + _i5.Future> fetch(Uri? uri) => (super.noSuchMethod( + Invocation.method( + #fetch, + [uri], + ), + returnValue: _i5.Future>.value({}), + ) as _i5.Future>); + @override + _i5.Future> fetchPaginated(Uri? uri) => (super.noSuchMethod( + Invocation.method( + #fetchPaginated, + [uri], + ), + returnValue: _i5.Future>.value([]), + ) as _i5.Future>); + @override + _i5.Future> post( + Map? data, + Uri? uri, + ) => + (super.noSuchMethod( + Invocation.method( + #post, + [ + data, + uri, + ], + ), + returnValue: _i5.Future>.value({}), + ) as _i5.Future>); + @override + _i5.Future> patch( + Map? data, + Uri? uri, + ) => + (super.noSuchMethod( + Invocation.method( + #patch, + [ + data, + uri, + ], + ), + returnValue: _i5.Future>.value({}), + ) as _i5.Future>); + @override + _i5.Future<_i3.Response> deleteRequest( + String? url, + int? id, + ) => + (super.noSuchMethod( + Invocation.method( + #deleteRequest, + [ + url, + id, + ], + ), + returnValue: _i5.Future<_i3.Response>.value(_FakeResponse_3( + this, + Invocation.method( + #deleteRequest, + [ + url, + id, + ], + ), + )), + ) as _i5.Future<_i3.Response>); +}