From 77f3ad4d0720a09aa04d551993d1b78f2e1e2ff2 Mon Sep 17 00:00:00 2001 From: Dennis Loose Date: Thu, 5 Oct 2023 12:57:28 +0200 Subject: [PATCH 1/3] test: add ratings_service_test --- lib/main.dart | 9 +- lib/src/ratings/ratings_service.dart | 21 +- test/ratings_service_test.dart | 120 ++++ test/test_utils.dart | 22 + test/test_utils.mocks.dart | 837 ++++++++++++++++----------- 5 files changed, 646 insertions(+), 363 deletions(-) create mode 100644 test/ratings_service_test.dart diff --git a/lib/main.dart b/lib/main.dart index aa3ff9c57..61d46a3b8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:io'; +import 'package:app_center_ratings_client/ratings_client.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:github/github.dart'; @@ -44,8 +45,12 @@ Future main(List args) async { final config = ConfigService(); config.load(); - final ratings = - RatingsService(config.ratingServiceUrl, config.ratingsServicePort); + final ratings = RatingsService( + RatingsClient( + config.ratingServiceUrl, + config.ratingsServicePort, + ), + ); registerServiceInstance(config); registerServiceInstance(ratings); diff --git a/lib/src/ratings/ratings_service.dart b/lib/src/ratings/ratings_service.dart index 8a9c10cbb..c8ee71ef9 100644 --- a/lib/src/ratings/ratings_service.dart +++ b/lib/src/ratings/ratings_service.dart @@ -6,15 +6,14 @@ import 'package:crypto/crypto.dart'; import 'package:flutter/material.dart'; import 'package:glib/glib.dart'; import 'package:jwt_decode/jwt_decode.dart'; + import 'exports.dart'; class RatingsService { - RatingsService(String url, int port, - [@visibleForTesting RatingsClient? client]) - : _client = client ?? RatingsClient(url, port), - _id = _generateId(); + RatingsService(this.client, {@visibleForTesting String? id}) + : _id = id ?? _generateId(); - final RatingsClient _client; + final RatingsClient client; String? _jwt; final String _id; @@ -26,32 +25,32 @@ class RatingsService { Future _ensureValidToken() async { if (_jwt == null || Jwt.isExpired(_jwt!)) { - _jwt = await _client.authenticate(_id); + _jwt = await client.authenticate(_id); } } Future getRating(String snapId) async { await _ensureValidToken(); - return _client.getRating(snapId, _jwt!); + return client.getRating(snapId, _jwt!); } Future vote(Vote vote) async { await _ensureValidToken(); - await _client.vote(vote.snapId, vote.snapRevision, vote.voteUp, _jwt!); + await client.vote(vote.snapId, vote.snapRevision, vote.voteUp, _jwt!); } Future delete() async { await _ensureValidToken(); - await _client.delete(_jwt!); + await client.delete(_jwt!); } Future> listMyVotes(String snapFilter) async { await _ensureValidToken(); - return await _client.listMyVotes(snapFilter, _jwt!); + return await client.listMyVotes(snapFilter, _jwt!); } Future> getSnapVotes(String snapId) async { await _ensureValidToken(); - return await _client.getSnapVotes(snapId, _jwt!); + return await client.getSnapVotes(snapId, _jwt!); } } diff --git a/test/ratings_service_test.dart b/test/ratings_service_test.dart new file mode 100644 index 000000000..ef2e24562 --- /dev/null +++ b/test/ratings_service_test.dart @@ -0,0 +1,120 @@ +import 'package:app_center/src/ratings/exports.dart'; +import 'package:app_center/src/ratings/ratings_service.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; + +import 'test_utils.dart'; + +void main() { + test('get rating', () async { + final mockClient = createMockRatingsClient( + token: 'jwt', + rating: const Rating( + snapId: 'firefox', + totalVotes: 1337, + ratingsBand: RatingsBand.veryGood, + ), + ); + final service = RatingsService(mockClient, id: 'myId'); + + final rating = await service.getRating('firefox'); + verify(mockClient.authenticate('myId')).called(1); + expect( + rating, + equals( + const Rating( + snapId: 'firefox', + totalVotes: 1337, + ratingsBand: RatingsBand.veryGood, + ), + ), + ); + }); + + test('vote', () async { + final mockClient = createMockRatingsClient(token: 'jwt'); + final service = RatingsService(mockClient, id: 'myId'); + + await service.vote( + Vote( + snapId: 'thunderbird', + snapRevision: 42, + voteUp: true, + dateTime: DateTime(1970), + ), + ); + verify(mockClient.authenticate('myId')).called(1); + verify(mockClient.vote('thunderbird', 42, true, 'jwt')).called(1); + }); + + test('delete', () async { + final mockClient = createMockRatingsClient(token: 'jwt'); + final service = RatingsService(mockClient, id: 'myId'); + + await service.delete(); + verify(mockClient.authenticate('myId')).called(1); + verify(mockClient.delete('jwt')).called(1); + }); + + test('list my votes', () async { + final mockClient = createMockRatingsClient( + token: 'jwt', + myVotes: [ + Vote( + snapId: 'testsnap', + snapRevision: 1, + voteUp: false, + dateTime: DateTime(1984), + ), + ], + ); + final service = RatingsService(mockClient, id: 'myId'); + + final votes = await service.listMyVotes('testsnap'); + verify(mockClient.authenticate('myId')).called(1); + expect( + votes, + equals( + [ + Vote( + snapId: 'testsnap', + snapRevision: 1, + voteUp: false, + dateTime: DateTime(1984), + ), + ], + ), + ); + }); + + test('snap votes', () async { + final mockClient = createMockRatingsClient( + token: 'jwt', + snapVotes: [ + Vote( + snapId: 'testsnap2', + snapRevision: 2, + voteUp: true, + dateTime: DateTime(1999), + ), + ], + ); + final service = RatingsService(mockClient, id: 'myId'); + + final votes = await service.getSnapVotes('testsnap2'); + verify(mockClient.authenticate('myId')).called(1); + expect( + votes, + equals( + [ + Vote( + snapId: 'testsnap2', + snapRevision: 2, + voteUp: true, + dateTime: DateTime(1999), + ), + ], + ), + ); + }); +} diff --git a/test/test_utils.dart b/test/test_utils.dart index ea711c0bd..b8a40ce03 100644 --- a/test/test_utils.dart +++ b/test/test_utils.dart @@ -7,6 +7,7 @@ import 'package:app_center/ratings.dart'; import 'package:app_center/snapd.dart'; import 'package:app_center/src/deb/deb_model.dart'; import 'package:app_center/src/manage/manage_model.dart'; +import 'package:app_center_ratings_client/ratings_client.dart'; import 'package:appstream/appstream.dart'; import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; @@ -288,6 +289,27 @@ MockRatingsService createMockRatingsService() { return service; } +@GenerateMocks([RatingsClient]) +MockRatingsClient createMockRatingsClient({ + String? token, + Rating? rating, + List? myVotes, + List? snapVotes, +}) { + final client = MockRatingsClient(); + when(client.authenticate(any)).thenAnswer((_) async => token ?? ''); + when(client.getRating(any, any)).thenAnswer((_) async => + rating ?? + const Rating( + snapId: '', + totalVotes: 0, + ratingsBand: RatingsBand.insufficientVotes, + )); + when(client.listMyVotes(any, any)).thenAnswer((_) async => myVotes ?? []); + when(client.getSnapVotes(any, any)).thenAnswer((_) async => snapVotes ?? []); + return client; +} + @GenerateMocks([AppstreamService]) MockAppstreamService createMockAppstreamService({ AppstreamComponent? component, diff --git a/test/test_utils.mocks.dart b/test/test_utils.mocks.dart index 7155478ad..03f1cb9bc 100644 --- a/test/test_utils.mocks.dart +++ b/test/test_utils.mocks.dart @@ -3,22 +3,23 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i13; -import 'dart:ui' as _i14; +import 'dart:async' as _i14; +import 'dart:ui' as _i15; import 'package:app_center/appstream.dart' as _i7; import 'package:app_center/packagekit.dart' as _i8; import 'package:app_center/snapd.dart' as _i6; -import 'package:app_center/src/deb/deb_model.dart' as _i15; -import 'package:app_center/src/manage/manage_model.dart' as _i16; +import 'package:app_center/src/deb/deb_model.dart' as _i16; +import 'package:app_center/src/manage/manage_model.dart' as _i17; import 'package:app_center/src/ratings/exports.dart' as _i12; -import 'package:app_center/src/ratings/ratings_model.dart' as _i11; +import 'package:app_center/src/ratings/ratings_model.dart' as _i13; import 'package:app_center/src/ratings/ratings_service.dart' as _i4; +import 'package:app_center_ratings_client/ratings_client.dart' as _i11; import 'package:appstream/appstream.dart' as _i9; -import 'package:dbus/dbus.dart' as _i19; -import 'package:file/file.dart' as _i17; +import 'package:dbus/dbus.dart' as _i20; +import 'package:file/file.dart' as _i18; import 'package:flutter_riverpod/flutter_riverpod.dart' as _i5; -import 'package:gtk/src/gtk_application_notifier.dart' as _i18; +import 'package:gtk/src/gtk_application_notifier.dart' as _i19; import 'package:mockito/mockito.dart' as _i1; import 'package:packagekit/packagekit.dart' as _i10; import 'package:snapcraft_launcher/snapcraft_launcher.dart' as _i3; @@ -184,6 +185,27 @@ class _FakePackageKitTransaction_13 extends _i1.SmartFake ); } +class _FakeRatingsClient_14 extends _i1.SmartFake + implements _i11.RatingsClient { + _FakeRatingsClient_14( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeRating_15 extends _i1.SmartFake implements _i12.Rating { + _FakeRating_15( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + /// A class which mocks [SnapLauncher]. /// /// See the documentation for Mockito's code generation for more information. @@ -229,7 +251,7 @@ class MockSnapLauncher extends _i1.Mock implements _i6.SnapLauncher { /// A class which mocks [RatingsModel]. /// /// See the documentation for Mockito's code generation for more information. -class MockRatingsModel extends _i1.Mock implements _i11.RatingsModel { +class MockRatingsModel extends _i1.Mock implements _i13.RatingsModel { MockRatingsModel() { _i1.throwOnMissingStub(this); } @@ -280,27 +302,27 @@ class MockRatingsModel extends _i1.Mock implements _i11.RatingsModel { ) as bool); @override - _i13.Future init() => (super.noSuchMethod( + _i14.Future init() => (super.noSuchMethod( Invocation.method( #init, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future castVote(_i11.VoteStatus? castVote) => (super.noSuchMethod( + _i14.Future castVote(_i13.VoteStatus? castVote) => (super.noSuchMethod( Invocation.method( #castVote, [castVote], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - void addListener(_i14.VoidCallback? listener) => super.noSuchMethod( + void addListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #addListener, [listener], @@ -309,7 +331,7 @@ class MockRatingsModel extends _i1.Mock implements _i11.RatingsModel { ); @override - void removeListener(_i14.VoidCallback? listener) => super.noSuchMethod( + void removeListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #removeListener, [listener], @@ -417,10 +439,10 @@ class MockSnapModel extends _i1.Mock implements _i6.SnapModel { ); @override - _i13.Stream<_i2.SnapdException> get errorStream => (super.noSuchMethod( + _i14.Stream<_i2.SnapdException> get errorStream => (super.noSuchMethod( Invocation.getter(#errorStream), - returnValue: _i13.Stream<_i2.SnapdException>.empty(), - ) as _i13.Stream<_i2.SnapdException>); + returnValue: _i14.Stream<_i2.SnapdException>.empty(), + ) as _i14.Stream<_i2.SnapdException>); @override bool get hasListeners => (super.noSuchMethod( @@ -429,67 +451,67 @@ class MockSnapModel extends _i1.Mock implements _i6.SnapModel { ) as bool); @override - _i13.Future init() => (super.noSuchMethod( + _i14.Future init() => (super.noSuchMethod( Invocation.method( #init, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future dispose() => (super.noSuchMethod( + _i14.Future dispose() => (super.noSuchMethod( Invocation.method( #dispose, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future cancel() => (super.noSuchMethod( + _i14.Future cancel() => (super.noSuchMethod( Invocation.method( #cancel, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future install() => (super.noSuchMethod( + _i14.Future install() => (super.noSuchMethod( Invocation.method( #install, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future refresh() => (super.noSuchMethod( + _i14.Future refresh() => (super.noSuchMethod( Invocation.method( #refresh, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future remove() => (super.noSuchMethod( + _i14.Future remove() => (super.noSuchMethod( Invocation.method( #remove, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - void addListener(_i14.VoidCallback? listener) => super.noSuchMethod( + void addListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #addListener, [listener], @@ -498,7 +520,7 @@ class MockSnapModel extends _i1.Mock implements _i6.SnapModel { ); @override - void removeListener(_i14.VoidCallback? listener) => super.noSuchMethod( + void removeListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #removeListener, [listener], @@ -519,7 +541,7 @@ class MockSnapModel extends _i1.Mock implements _i6.SnapModel { /// A class which mocks [DebModel]. /// /// See the documentation for Mockito's code generation for more information. -class MockDebModel extends _i1.Mock implements _i15.DebModel { +class MockDebModel extends _i1.Mock implements _i16.DebModel { MockDebModel() { _i1.throwOnMissingStub(this); } @@ -583,11 +605,11 @@ class MockDebModel extends _i1.Mock implements _i15.DebModel { ) as bool); @override - _i13.Stream<_i10.PackageKitErrorCodeEvent> get errorStream => + _i14.Stream<_i10.PackageKitErrorCodeEvent> get errorStream => (super.noSuchMethod( Invocation.getter(#errorStream), - returnValue: _i13.Stream<_i10.PackageKitErrorCodeEvent>.empty(), - ) as _i13.Stream<_i10.PackageKitErrorCodeEvent>); + returnValue: _i14.Stream<_i10.PackageKitErrorCodeEvent>.empty(), + ) as _i14.Stream<_i10.PackageKitErrorCodeEvent>); @override bool get hasListeners => (super.noSuchMethod( @@ -596,47 +618,47 @@ class MockDebModel extends _i1.Mock implements _i15.DebModel { ) as bool); @override - _i13.Future init() => (super.noSuchMethod( + _i14.Future init() => (super.noSuchMethod( Invocation.method( #init, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future install() => (super.noSuchMethod( + _i14.Future install() => (super.noSuchMethod( Invocation.method( #install, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future remove() => (super.noSuchMethod( + _i14.Future remove() => (super.noSuchMethod( Invocation.method( #remove, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future cancel() => (super.noSuchMethod( + _i14.Future cancel() => (super.noSuchMethod( Invocation.method( #cancel, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - void addListener(_i14.VoidCallback? listener) => super.noSuchMethod( + void addListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #addListener, [listener], @@ -645,7 +667,7 @@ class MockDebModel extends _i1.Mock implements _i15.DebModel { ); @override - void removeListener(_i14.VoidCallback? listener) => super.noSuchMethod( + void removeListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #removeListener, [listener], @@ -675,7 +697,7 @@ class MockDebModel extends _i1.Mock implements _i15.DebModel { /// A class which mocks [ManageModel]. /// /// See the documentation for Mockito's code generation for more information. -class MockManageModel extends _i1.Mock implements _i16.ManageModel { +class MockManageModel extends _i1.Mock implements _i17.ManageModel { MockManageModel() { _i1.throwOnMissingStub(this); } @@ -726,14 +748,14 @@ class MockManageModel extends _i1.Mock implements _i16.ManageModel { ) as bool); @override - _i13.Future init() => (super.noSuchMethod( + _i14.Future init() => (super.noSuchMethod( Invocation.method( #init, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override void dispose() => super.noSuchMethod( @@ -745,7 +767,7 @@ class MockManageModel extends _i1.Mock implements _i16.ManageModel { ); @override - void addListener(_i14.VoidCallback? listener) => super.noSuchMethod( + void addListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #addListener, [listener], @@ -754,7 +776,7 @@ class MockManageModel extends _i1.Mock implements _i16.ManageModel { ); @override - void removeListener(_i14.VoidCallback? listener) => super.noSuchMethod( + void removeListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #removeListener, [listener], @@ -805,25 +827,25 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { ); @override - _i13.Future waitChange(String? changeId) => (super.noSuchMethod( + _i14.Future waitChange(String? changeId) => (super.noSuchMethod( Invocation.method( #waitChange, [changeId], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future loadAuthorization({String? path}) => (super.noSuchMethod( + _i14.Future loadAuthorization({String? path}) => (super.noSuchMethod( Invocation.method( #loadAuthorization, [], {#path: path}, ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override void setAuthorization( @@ -842,12 +864,12 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { ); @override - _i13.Future<_i2.SnapdSystemInfoResponse> systemInfo() => (super.noSuchMethod( + _i14.Future<_i2.SnapdSystemInfoResponse> systemInfo() => (super.noSuchMethod( Invocation.method( #systemInfo, [], ), - returnValue: _i13.Future<_i2.SnapdSystemInfoResponse>.value( + returnValue: _i14.Future<_i2.SnapdSystemInfoResponse>.value( _FakeSnapdSystemInfoResponse_9( this, Invocation.method( @@ -855,34 +877,34 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { [], ), )), - ) as _i13.Future<_i2.SnapdSystemInfoResponse>); + ) as _i14.Future<_i2.SnapdSystemInfoResponse>); @override - _i13.Future> getSnaps() => (super.noSuchMethod( + _i14.Future> getSnaps() => (super.noSuchMethod( Invocation.method( #getSnaps, [], ), - returnValue: _i13.Future>.value(<_i2.Snap>[]), - ) as _i13.Future>); + returnValue: _i14.Future>.value(<_i2.Snap>[]), + ) as _i14.Future>); @override - _i13.Future<_i2.Snap> getSnap(String? name) => (super.noSuchMethod( + _i14.Future<_i2.Snap> getSnap(String? name) => (super.noSuchMethod( Invocation.method( #getSnap, [name], ), - returnValue: _i13.Future<_i2.Snap>.value(_FakeSnap_0( + returnValue: _i14.Future<_i2.Snap>.value(_FakeSnap_0( this, Invocation.method( #getSnap, [name], ), )), - ) as _i13.Future<_i2.Snap>); + ) as _i14.Future<_i2.Snap>); @override - _i13.Future> getApps({ + _i14.Future> getApps({ List? names, _i2.SnapdAppFilter? filter, }) => @@ -895,22 +917,22 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { #filter: filter, }, ), - returnValue: _i13.Future>.value(<_i2.SnapApp>[]), - ) as _i13.Future>); + returnValue: _i14.Future>.value(<_i2.SnapApp>[]), + ) as _i14.Future>); @override - _i13.Future> getCategories() => + _i14.Future> getCategories() => (super.noSuchMethod( Invocation.method( #getCategories, [], ), - returnValue: _i13.Future>.value( + returnValue: _i14.Future>.value( <_i2.SnapdCategoryDetails>[]), - ) as _i13.Future>); + ) as _i14.Future>); @override - _i13.Future<_i2.SnapdConnectionsResponse> getConnections({ + _i14.Future<_i2.SnapdConnectionsResponse> getConnections({ String? snap, String? interface, _i2.SnapdConnectionFilter? filter, @@ -925,7 +947,7 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { #filter: filter, }, ), - returnValue: _i13.Future<_i2.SnapdConnectionsResponse>.value( + returnValue: _i14.Future<_i2.SnapdConnectionsResponse>.value( _FakeSnapdConnectionsResponse_10( this, Invocation.method( @@ -938,19 +960,19 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { }, ), )), - ) as _i13.Future<_i2.SnapdConnectionsResponse>); + ) as _i14.Future<_i2.SnapdConnectionsResponse>); @override - _i13.Future refreshMany(List? names) => (super.noSuchMethod( + _i14.Future refreshMany(List? names) => (super.noSuchMethod( Invocation.method( #refreshMany, [names], ), - returnValue: _i13.Future.value(''), - ) as _i13.Future); + returnValue: _i14.Future.value(''), + ) as _i14.Future); @override - _i13.Future connect( + _i14.Future connect( String? snap, String? plug, String? slotSnap, @@ -966,11 +988,11 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { slot, ], ), - returnValue: _i13.Future.value(''), - ) as _i13.Future); + returnValue: _i14.Future.value(''), + ) as _i14.Future); @override - _i13.Future disconnect( + _i14.Future disconnect( String? plugSnap, String? plug, String? slotSnap, @@ -986,11 +1008,11 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { slot, ], ), - returnValue: _i13.Future.value(''), - ) as _i13.Future); + returnValue: _i14.Future.value(''), + ) as _i14.Future); @override - _i13.Future> find({ + _i14.Future> find({ String? query, String? name, String? category, @@ -1009,11 +1031,11 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { #filter: filter, }, ), - returnValue: _i13.Future>.value(<_i2.Snap>[]), - ) as _i13.Future>); + returnValue: _i14.Future>.value(<_i2.Snap>[]), + ) as _i14.Future>); @override - _i13.Future<_i2.SnapdLoginResponse> login( + _i14.Future<_i2.SnapdLoginResponse> login( String? email, String? password, { String? otp, @@ -1027,7 +1049,7 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { ], {#otp: otp}, ), - returnValue: _i13.Future<_i2.SnapdLoginResponse>.value( + returnValue: _i14.Future<_i2.SnapdLoginResponse>.value( _FakeSnapdLoginResponse_11( this, Invocation.method( @@ -1039,19 +1061,19 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { {#otp: otp}, ), )), - ) as _i13.Future<_i2.SnapdLoginResponse>); + ) as _i14.Future<_i2.SnapdLoginResponse>); @override - _i13.Future logout(int? id) => (super.noSuchMethod( + _i14.Future logout(int? id) => (super.noSuchMethod( Invocation.method( #logout, [id], ), - returnValue: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future install( + _i14.Future install( String? name, { String? channel, String? revision, @@ -1073,11 +1095,11 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { #jailmode: jailmode, }, ), - returnValue: _i13.Future.value(''), - ) as _i13.Future); + returnValue: _i14.Future.value(''), + ) as _i14.Future); @override - _i13.Future refresh( + _i14.Future refresh( String? name, { String? channel, bool? classic = false, @@ -1091,11 +1113,11 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { #classic: classic, }, ), - returnValue: _i13.Future.value(''), - ) as _i13.Future); + returnValue: _i14.Future.value(''), + ) as _i14.Future); @override - _i13.Future remove( + _i14.Future remove( String? name, { bool? purge = false, }) => @@ -1105,44 +1127,44 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { [name], {#purge: purge}, ), - returnValue: _i13.Future.value(''), - ) as _i13.Future); + returnValue: _i14.Future.value(''), + ) as _i14.Future); @override - _i13.Future enable(String? name) => (super.noSuchMethod( + _i14.Future enable(String? name) => (super.noSuchMethod( Invocation.method( #enable, [name], ), - returnValue: _i13.Future.value(''), - ) as _i13.Future); + returnValue: _i14.Future.value(''), + ) as _i14.Future); @override - _i13.Future disable(String? name) => (super.noSuchMethod( + _i14.Future disable(String? name) => (super.noSuchMethod( Invocation.method( #disable, [name], ), - returnValue: _i13.Future.value(''), - ) as _i13.Future); + returnValue: _i14.Future.value(''), + ) as _i14.Future); @override - _i13.Future<_i2.SnapdChange> getChange(String? id) => (super.noSuchMethod( + _i14.Future<_i2.SnapdChange> getChange(String? id) => (super.noSuchMethod( Invocation.method( #getChange, [id], ), - returnValue: _i13.Future<_i2.SnapdChange>.value(_FakeSnapdChange_12( + returnValue: _i14.Future<_i2.SnapdChange>.value(_FakeSnapdChange_12( this, Invocation.method( #getChange, [id], ), )), - ) as _i13.Future<_i2.SnapdChange>); + ) as _i14.Future<_i2.SnapdChange>); @override - _i13.Future> getChanges({ + _i14.Future> getChanges({ _i2.SnapdChangeFilter? filter, String? name, }) => @@ -1156,23 +1178,23 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { }, ), returnValue: - _i13.Future>.value(<_i2.SnapdChange>[]), - ) as _i13.Future>); + _i14.Future>.value(<_i2.SnapdChange>[]), + ) as _i14.Future>); @override - _i13.Future<_i2.SnapdChange> abortChange(String? id) => (super.noSuchMethod( + _i14.Future<_i2.SnapdChange> abortChange(String? id) => (super.noSuchMethod( Invocation.method( #abortChange, [id], ), - returnValue: _i13.Future<_i2.SnapdChange>.value(_FakeSnapdChange_12( + returnValue: _i14.Future<_i2.SnapdChange>.value(_FakeSnapdChange_12( this, Invocation.method( #abortChange, [id], ), )), - ) as _i13.Future<_i2.SnapdChange>); + ) as _i14.Future<_i2.SnapdChange>); @override void close() => super.noSuchMethod( @@ -1184,10 +1206,10 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { ); @override - _i13.Stream> getCategory( + _i14.Stream> getCategory( String? name, { Duration? expiry = const Duration(days: 1), - _i17.FileSystem? fs, + _i18.FileSystem? fs, }) => (super.noSuchMethod( Invocation.method( @@ -1198,14 +1220,14 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { #fs: fs, }, ), - returnValue: _i13.Stream>.empty(), - ) as _i13.Stream>); + returnValue: _i14.Stream>.empty(), + ) as _i14.Stream>); @override - _i13.Stream<_i2.Snap?> getStoreSnap( + _i14.Stream<_i2.Snap?> getStoreSnap( String? name, { Duration? expiry = const Duration(minutes: 1), - _i17.FileSystem? fs, + _i18.FileSystem? fs, }) => (super.noSuchMethod( Invocation.method( @@ -1216,14 +1238,14 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { #fs: fs, }, ), - returnValue: _i13.Stream<_i2.Snap?>.empty(), - ) as _i13.Stream<_i2.Snap?>); + returnValue: _i14.Stream<_i2.Snap?>.empty(), + ) as _i14.Stream<_i2.Snap?>); @override - _i13.Stream> getStoreSnaps( + _i14.Stream> getStoreSnaps( List? names, { Duration? expiry = const Duration(minutes: 1), - _i17.FileSystem? fs, + _i18.FileSystem? fs, }) => (super.noSuchMethod( Invocation.method( @@ -1234,11 +1256,11 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { #fs: fs, }, ), - returnValue: _i13.Stream>.empty(), - ) as _i13.Stream>); + returnValue: _i14.Stream>.empty(), + ) as _i14.Stream>); @override - _i13.Stream<_i2.SnapdChange> watchChange( + _i14.Stream<_i2.SnapdChange> watchChange( String? id, { Duration? interval = const Duration(milliseconds: 100), }) => @@ -1248,11 +1270,11 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { [id], {#interval: interval}, ), - returnValue: _i13.Stream<_i2.SnapdChange>.empty(), - ) as _i13.Stream<_i2.SnapdChange>); + returnValue: _i14.Stream<_i2.SnapdChange>.empty(), + ) as _i14.Stream<_i2.SnapdChange>); @override - _i13.Stream> watchChanges({ + _i14.Stream> watchChanges({ String? name, Duration? interval = const Duration(milliseconds: 100), }) => @@ -1265,8 +1287,8 @@ class MockSnapdService extends _i1.Mock implements _i6.SnapdService { #interval: interval, }, ), - returnValue: _i13.Stream>.empty(), - ) as _i13.Stream>); + returnValue: _i14.Stream>.empty(), + ) as _i14.Stream>); } /// A class which mocks [UpdatesModel]. @@ -1302,10 +1324,10 @@ class MockUpdatesModel extends _i1.Mock implements _i6.UpdatesModel { ) as _i5.AsyncValue); @override - _i13.Stream<_i2.SnapdException> get errorStream => (super.noSuchMethod( + _i14.Stream<_i2.SnapdException> get errorStream => (super.noSuchMethod( Invocation.getter(#errorStream), - returnValue: _i13.Stream<_i2.SnapdException>.empty(), - ) as _i13.Stream<_i2.SnapdException>); + returnValue: _i14.Stream<_i2.SnapdException>.empty(), + ) as _i14.Stream<_i2.SnapdException>); @override bool get hasListeners => (super.noSuchMethod( @@ -1314,14 +1336,14 @@ class MockUpdatesModel extends _i1.Mock implements _i6.UpdatesModel { ) as bool); @override - _i13.Future refresh() => (super.noSuchMethod( + _i14.Future refresh() => (super.noSuchMethod( Invocation.method( #refresh, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override bool hasUpdate(String? snapName) => (super.noSuchMethod( @@ -1333,17 +1355,17 @@ class MockUpdatesModel extends _i1.Mock implements _i6.UpdatesModel { ) as bool); @override - _i13.Future updateAll() => (super.noSuchMethod( + _i14.Future updateAll() => (super.noSuchMethod( Invocation.method( #updateAll, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - void addListener(_i14.VoidCallback? listener) => super.noSuchMethod( + void addListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #addListener, [listener], @@ -1352,7 +1374,7 @@ class MockUpdatesModel extends _i1.Mock implements _i6.UpdatesModel { ); @override - void removeListener(_i14.VoidCallback? listener) => super.noSuchMethod( + void removeListener(_i15.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #removeListener, [listener], @@ -1383,13 +1405,13 @@ class MockUpdatesModel extends _i1.Mock implements _i6.UpdatesModel { /// /// See the documentation for Mockito's code generation for more information. class MockGtkApplicationNotifier extends _i1.Mock - implements _i18.GtkApplicationNotifier { + implements _i19.GtkApplicationNotifier { MockGtkApplicationNotifier() { _i1.throwOnMissingStub(this); } @override - void addCommandLineListener(_i18.GtkCommandLineListener? listener) => + void addCommandLineListener(_i19.GtkCommandLineListener? listener) => super.noSuchMethod( Invocation.method( #addCommandLineListener, @@ -1399,7 +1421,7 @@ class MockGtkApplicationNotifier extends _i1.Mock ); @override - void removeCommandLineListener(_i18.GtkCommandLineListener? listener) => + void removeCommandLineListener(_i19.GtkCommandLineListener? listener) => super.noSuchMethod( Invocation.method( #removeCommandLineListener, @@ -1409,7 +1431,7 @@ class MockGtkApplicationNotifier extends _i1.Mock ); @override - void addOpenListener(_i18.GtkOpenListener? listener) => super.noSuchMethod( + void addOpenListener(_i19.GtkOpenListener? listener) => super.noSuchMethod( Invocation.method( #addOpenListener, [listener], @@ -1418,7 +1440,7 @@ class MockGtkApplicationNotifier extends _i1.Mock ); @override - void removeOpenListener(_i18.GtkOpenListener? listener) => super.noSuchMethod( + void removeOpenListener(_i19.GtkOpenListener? listener) => super.noSuchMethod( Invocation.method( #removeOpenListener, [listener], @@ -1618,30 +1640,30 @@ class MockPackageKitClient extends _i1.Mock implements _i10.PackageKitClient { ) as int); @override - _i13.Stream> get propertiesChanged => (super.noSuchMethod( + _i14.Stream> get propertiesChanged => (super.noSuchMethod( Invocation.getter(#propertiesChanged), - returnValue: _i13.Stream>.empty(), - ) as _i13.Stream>); + returnValue: _i14.Stream>.empty(), + ) as _i14.Stream>); @override - _i13.Future connect() => (super.noSuchMethod( + _i14.Future connect() => (super.noSuchMethod( Invocation.method( #connect, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future<_i10.PackageKitTransaction> getTransaction( - _i19.DBusObjectPath? path) => + _i14.Future<_i10.PackageKitTransaction> getTransaction( + _i20.DBusObjectPath? path) => (super.noSuchMethod( Invocation.method( #getTransaction, [path], ), - returnValue: _i13.Future<_i10.PackageKitTransaction>.value( + returnValue: _i14.Future<_i10.PackageKitTransaction>.value( _FakePackageKitTransaction_13( this, Invocation.method( @@ -1649,16 +1671,16 @@ class MockPackageKitClient extends _i1.Mock implements _i10.PackageKitClient { [path], ), )), - ) as _i13.Future<_i10.PackageKitTransaction>); + ) as _i14.Future<_i10.PackageKitTransaction>); @override - _i13.Future<_i10.PackageKitTransaction> createTransaction() => + _i14.Future<_i10.PackageKitTransaction> createTransaction() => (super.noSuchMethod( Invocation.method( #createTransaction, [], ), - returnValue: _i13.Future<_i10.PackageKitTransaction>.value( + returnValue: _i14.Future<_i10.PackageKitTransaction>.value( _FakePackageKitTransaction_13( this, Invocation.method( @@ -1666,17 +1688,17 @@ class MockPackageKitClient extends _i1.Mock implements _i10.PackageKitClient { [], ), )), - ) as _i13.Future<_i10.PackageKitTransaction>); + ) as _i14.Future<_i10.PackageKitTransaction>); @override - _i13.Future close() => (super.noSuchMethod( + _i14.Future close() => (super.noSuchMethod( Invocation.method( #close, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); } /// A class which mocks [PackageKitTransaction]. @@ -1689,13 +1711,13 @@ class MockPackageKitTransaction extends _i1.Mock } @override - _i13.Stream<_i10.PackageKitEvent> get events => (super.noSuchMethod( + _i14.Stream<_i10.PackageKitEvent> get events => (super.noSuchMethod( Invocation.getter(#events), - returnValue: _i13.Stream<_i10.PackageKitEvent>.empty(), - ) as _i13.Stream<_i10.PackageKitEvent>); + returnValue: _i14.Stream<_i10.PackageKitEvent>.empty(), + ) as _i14.Stream<_i10.PackageKitEvent>); @override - set events(_i13.Stream<_i10.PackageKitEvent>? _events) => super.noSuchMethod( + set events(_i14.Stream<_i10.PackageKitEvent>? _events) => super.noSuchMethod( Invocation.setter( #events, _events, @@ -1777,23 +1799,23 @@ class MockPackageKitTransaction extends _i1.Mock ) as Set<_i10.PackageKitTransactionFlag>); @override - _i13.Stream> get propertiesChanged => (super.noSuchMethod( + _i14.Stream> get propertiesChanged => (super.noSuchMethod( Invocation.getter(#propertiesChanged), - returnValue: _i13.Stream>.empty(), - ) as _i13.Stream>); + returnValue: _i14.Stream>.empty(), + ) as _i14.Stream>); @override - _i13.Future cancel() => (super.noSuchMethod( + _i14.Future cancel() => (super.noSuchMethod( Invocation.method( #cancel, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future dependsOn( + _i14.Future dependsOn( Iterable<_i10.PackageKitPackageId>? packageIds, { Set<_i10.PackageKitFilter>? filter = const {}, bool? recursive = false, @@ -1807,35 +1829,35 @@ class MockPackageKitTransaction extends _i1.Mock #recursive: recursive, }, ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future getDetails( + _i14.Future getDetails( Iterable<_i10.PackageKitPackageId>? packageIds) => (super.noSuchMethod( Invocation.method( #getDetails, [packageIds], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future getDetailsLocal(Iterable? paths) => + _i14.Future getDetailsLocal(Iterable? paths) => (super.noSuchMethod( Invocation.method( #getDetailsLocal, [paths], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future downloadPackages( + _i14.Future downloadPackages( Iterable<_i10.PackageKitPackageId>? packageIds, { bool? storeInCache = false, }) => @@ -1845,34 +1867,34 @@ class MockPackageKitTransaction extends _i1.Mock [packageIds], {#storeInCache: storeInCache}, ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future getFiles(Iterable<_i10.PackageKitPackageId>? packageIds) => + _i14.Future getFiles(Iterable<_i10.PackageKitPackageId>? packageIds) => (super.noSuchMethod( Invocation.method( #getFiles, [packageIds], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future getFilesLocal(Iterable? paths) => + _i14.Future getFilesLocal(Iterable? paths) => (super.noSuchMethod( Invocation.method( #getFilesLocal, [paths], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future getPackages( + _i14.Future getPackages( {Set<_i10.PackageKitFilter>? filter = const {}}) => (super.noSuchMethod( Invocation.method( @@ -1880,12 +1902,12 @@ class MockPackageKitTransaction extends _i1.Mock [], {#filter: filter}, ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future getRepositoryList( + _i14.Future getRepositoryList( {Set<_i10.PackageKitFilter>? filter = const {}}) => (super.noSuchMethod( Invocation.method( @@ -1893,12 +1915,12 @@ class MockPackageKitTransaction extends _i1.Mock [], {#filter: filter}, ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future setRepositoryEnabled( + _i14.Future setRepositoryEnabled( String? id, bool? enabled, ) => @@ -1910,12 +1932,12 @@ class MockPackageKitTransaction extends _i1.Mock enabled, ], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future setRepositoryData( + _i14.Future setRepositoryData( String? id, String? parameter, String? value, @@ -1929,12 +1951,12 @@ class MockPackageKitTransaction extends _i1.Mock value, ], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future removeRepository( + _i14.Future removeRepository( String? id, { bool? autoremovePackages = false, }) => @@ -1944,24 +1966,24 @@ class MockPackageKitTransaction extends _i1.Mock [id], {#autoremovePackages: autoremovePackages}, ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future getUpdateDetail( + _i14.Future getUpdateDetail( Iterable<_i10.PackageKitPackageId>? packageIds) => (super.noSuchMethod( Invocation.method( #getUpdateDetail, [packageIds], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future getUpdates( + _i14.Future getUpdates( {Set<_i10.PackageKitFilter>? filter = const {}}) => (super.noSuchMethod( Invocation.method( @@ -1969,12 +1991,12 @@ class MockPackageKitTransaction extends _i1.Mock [], {#filter: filter}, ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future installFiles( + _i14.Future installFiles( Iterable? paths, { Set<_i10.PackageKitTransactionFlag>? transactionFlags = const {}, }) => @@ -1984,12 +2006,12 @@ class MockPackageKitTransaction extends _i1.Mock [paths], {#transactionFlags: transactionFlags}, ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future installPackages( + _i14.Future installPackages( Iterable<_i10.PackageKitPackageId>? packageIds, { Set<_i10.PackageKitTransactionFlag>? transactionFlags = const {}, }) => @@ -1999,23 +2021,23 @@ class MockPackageKitTransaction extends _i1.Mock [packageIds], {#transactionFlags: transactionFlags}, ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future refreshCache({bool? force = false}) => (super.noSuchMethod( + _i14.Future refreshCache({bool? force = false}) => (super.noSuchMethod( Invocation.method( #refreshCache, [], {#force: force}, ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future removePackages( + _i14.Future removePackages( Iterable<_i10.PackageKitPackageId>? packageIds, { Set<_i10.PackageKitTransactionFlag>? transactionFlags = const {}, bool? allowDeps = false, @@ -2031,12 +2053,12 @@ class MockPackageKitTransaction extends _i1.Mock #autoremove: autoremove, }, ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future resolve( + _i14.Future resolve( Iterable? packages, { Set<_i10.PackageKitTransactionFlag>? transactionFlags = const {}, }) => @@ -2046,12 +2068,12 @@ class MockPackageKitTransaction extends _i1.Mock [packages], {#transactionFlags: transactionFlags}, ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future searchFiles( + _i14.Future searchFiles( Iterable? values, { Set<_i10.PackageKitFilter>? filter = const {}, }) => @@ -2061,12 +2083,12 @@ class MockPackageKitTransaction extends _i1.Mock [values], {#filter: filter}, ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future searchNames( + _i14.Future searchNames( Iterable? values, { Set<_i10.PackageKitFilter>? filter = const {}, }) => @@ -2076,12 +2098,12 @@ class MockPackageKitTransaction extends _i1.Mock [values], {#filter: filter}, ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future updatePackages( + _i14.Future updatePackages( Iterable<_i10.PackageKitPackageId>? packageIds, { Set<_i10.PackageKitTransactionFlag>? transactionFlags = const {}, }) => @@ -2091,12 +2113,12 @@ class MockPackageKitTransaction extends _i1.Mock [packageIds], {#transactionFlags: transactionFlags}, ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future upgradeSystem( + _i14.Future upgradeSystem( String? distroId, _i10.PackageKitDistroUpgrade? upgradeKind, { Set<_i10.PackageKitTransactionFlag>? transactionFlags = const {}, @@ -2110,9 +2132,9 @@ class MockPackageKitTransaction extends _i1.Mock ], {#transactionFlags: transactionFlags}, ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); } /// A class which mocks [RatingsService]. @@ -2124,53 +2146,168 @@ class MockRatingsService extends _i1.Mock implements _i4.RatingsService { } @override - _i13.Future<_i12.Rating?> getRating(String? snapId) => (super.noSuchMethod( + _i11.RatingsClient get client => (super.noSuchMethod( + Invocation.getter(#client), + returnValue: _FakeRatingsClient_14( + this, + Invocation.getter(#client), + ), + ) as _i11.RatingsClient); + + @override + _i14.Future<_i12.Rating?> getRating(String? snapId) => (super.noSuchMethod( Invocation.method( #getRating, [snapId], ), - returnValue: _i13.Future<_i12.Rating?>.value(), - ) as _i13.Future<_i12.Rating?>); + returnValue: _i14.Future<_i12.Rating?>.value(), + ) as _i14.Future<_i12.Rating?>); @override - _i13.Future vote(_i12.Vote? vote) => (super.noSuchMethod( + _i14.Future vote(_i12.Vote? vote) => (super.noSuchMethod( Invocation.method( #vote, [vote], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future delete() => (super.noSuchMethod( + _i14.Future delete() => (super.noSuchMethod( Invocation.method( #delete, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future> listMyVotes(String? snapFilter) => + _i14.Future> listMyVotes(String? snapFilter) => (super.noSuchMethod( Invocation.method( #listMyVotes, [snapFilter], ), - returnValue: _i13.Future>.value(<_i12.Vote>[]), - ) as _i13.Future>); + returnValue: _i14.Future>.value(<_i12.Vote>[]), + ) as _i14.Future>); @override - _i13.Future> getSnapVotes(String? snapId) => + _i14.Future> getSnapVotes(String? snapId) => (super.noSuchMethod( Invocation.method( #getSnapVotes, [snapId], ), - returnValue: _i13.Future>.value(<_i12.Vote>[]), - ) as _i13.Future>); + returnValue: _i14.Future>.value(<_i12.Vote>[]), + ) as _i14.Future>); +} + +/// A class which mocks [RatingsClient]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockRatingsClient extends _i1.Mock implements _i11.RatingsClient { + MockRatingsClient() { + _i1.throwOnMissingStub(this); + } + + @override + _i14.Future<_i12.Rating> getRating( + String? snapId, + String? token, + ) => + (super.noSuchMethod( + Invocation.method( + #getRating, + [ + snapId, + token, + ], + ), + returnValue: _i14.Future<_i12.Rating>.value(_FakeRating_15( + this, + Invocation.method( + #getRating, + [ + snapId, + token, + ], + ), + )), + ) as _i14.Future<_i12.Rating>); + + @override + _i14.Future authenticate(String? id) => (super.noSuchMethod( + Invocation.method( + #authenticate, + [id], + ), + returnValue: _i14.Future.value(''), + ) as _i14.Future); + + @override + _i14.Future> listMyVotes( + String? snapIdFilter, + String? token, + ) => + (super.noSuchMethod( + Invocation.method( + #listMyVotes, + [ + snapIdFilter, + token, + ], + ), + returnValue: _i14.Future>.value(<_i12.Vote>[]), + ) as _i14.Future>); + + @override + _i14.Future vote( + String? snapId, + int? snapRevision, + bool? voteUp, + String? token, + ) => + (super.noSuchMethod( + Invocation.method( + #vote, + [ + snapId, + snapRevision, + voteUp, + token, + ], + ), + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); + + @override + _i14.Future delete(String? token) => (super.noSuchMethod( + Invocation.method( + #delete, + [token], + ), + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); + + @override + _i14.Future> getSnapVotes( + String? snap_id, + String? token, + ) => + (super.noSuchMethod( + Invocation.method( + #getSnapVotes, + [ + snap_id, + token, + ], + ), + returnValue: _i14.Future>.value(<_i12.Vote>[]), + ) as _i14.Future>); } /// A class which mocks [AppstreamService]. @@ -2194,25 +2331,25 @@ class MockAppstreamService extends _i1.Mock implements _i7.AppstreamService { ) as int); @override - _i13.Future init() => (super.noSuchMethod( + _i14.Future init() => (super.noSuchMethod( Invocation.method( #init, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future> search(String? search) => + _i14.Future> search(String? search) => (super.noSuchMethod( Invocation.method( #search, [search], ), - returnValue: _i13.Future>.value( + returnValue: _i14.Future>.value( <_i9.AppstreamComponent>[]), - ) as _i13.Future>); + ) as _i14.Future>); @override _i9.AppstreamComponent getFromId(String? id) => (super.noSuchMethod( @@ -2245,11 +2382,11 @@ class MockPackageKitService extends _i1.Mock implements _i8.PackageKitService { ) as bool); @override - _i13.Stream<_i10.PackageKitErrorCodeEvent> get errorStream => + _i14.Stream<_i10.PackageKitErrorCodeEvent> get errorStream => (super.noSuchMethod( Invocation.getter(#errorStream), - returnValue: _i13.Stream<_i10.PackageKitErrorCodeEvent>.empty(), - ) as _i13.Stream<_i10.PackageKitErrorCodeEvent>); + returnValue: _i14.Stream<_i10.PackageKitErrorCodeEvent>.empty(), + ) as _i14.Stream<_i10.PackageKitErrorCodeEvent>); @override _i10.PackageKitTransaction? getTransaction(int? id) => @@ -2259,72 +2396,72 @@ class MockPackageKitService extends _i1.Mock implements _i8.PackageKitService { )) as _i10.PackageKitTransaction?); @override - _i13.Future activateService() => (super.noSuchMethod( + _i14.Future activateService() => (super.noSuchMethod( Invocation.method( #activateService, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future waitTransaction(int? id) => (super.noSuchMethod( + _i14.Future waitTransaction(int? id) => (super.noSuchMethod( Invocation.method( #waitTransaction, [id], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future cancelTransaction(int? id) => (super.noSuchMethod( + _i14.Future cancelTransaction(int? id) => (super.noSuchMethod( Invocation.method( #cancelTransaction, [id], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); @override - _i13.Future install(_i10.PackageKitPackageId? packageId) => + _i14.Future install(_i10.PackageKitPackageId? packageId) => (super.noSuchMethod( Invocation.method( #install, [packageId], ), - returnValue: _i13.Future.value(0), - ) as _i13.Future); + returnValue: _i14.Future.value(0), + ) as _i14.Future); @override - _i13.Future remove(_i10.PackageKitPackageId? packageId) => + _i14.Future remove(_i10.PackageKitPackageId? packageId) => (super.noSuchMethod( Invocation.method( #remove, [packageId], ), - returnValue: _i13.Future.value(0), - ) as _i13.Future); + returnValue: _i14.Future.value(0), + ) as _i14.Future); @override - _i13.Future<_i10.PackageKitPackageEvent?> resolve(String? name) => + _i14.Future<_i10.PackageKitPackageEvent?> resolve(String? name) => (super.noSuchMethod( Invocation.method( #resolve, [name], ), - returnValue: _i13.Future<_i10.PackageKitPackageEvent?>.value(), - ) as _i13.Future<_i10.PackageKitPackageEvent?>); + returnValue: _i14.Future<_i10.PackageKitPackageEvent?>.value(), + ) as _i14.Future<_i10.PackageKitPackageEvent?>); @override - _i13.Future dispose() => (super.noSuchMethod( + _i14.Future dispose() => (super.noSuchMethod( Invocation.method( #dispose, [], ), - returnValue: _i13.Future.value(), - returnValueForMissingStub: _i13.Future.value(), - ) as _i13.Future); + returnValue: _i14.Future.value(), + returnValueForMissingStub: _i14.Future.value(), + ) as _i14.Future); } From 892f5c32a5b097fcc31895fb99b793e062411590 Mon Sep 17 00:00:00 2001 From: Dennis Loose Date: Thu, 5 Oct 2023 13:00:33 +0200 Subject: [PATCH 2/3] test: add ratings_model_test --- lib/src/ratings/ratings_model.dart | 4 +- pubspec.yaml | 3 +- test/ratings_model_test.dart | 70 ++++++++++++++++++++++++++++++ test/test_utils.dart | 15 ++++++- 4 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 test/ratings_model_test.dart diff --git a/lib/src/ratings/ratings_model.dart b/lib/src/ratings/ratings_model.dart index df7a84f44..880664b4d 100644 --- a/lib/src/ratings/ratings_model.dart +++ b/lib/src/ratings/ratings_model.dart @@ -1,10 +1,10 @@ +import 'package:clock/clock.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:snapd/snapd.dart'; import 'package:ubuntu_service/ubuntu_service.dart'; import 'exports.dart'; - import 'ratings_service.dart'; final ratingsModelProvider = @@ -72,7 +72,7 @@ class RatingsModel extends ChangeNotifier { snapId: snapId, snapRevision: int.parse(snapRevision), voteUp: voteUp, // using voteUp directly here - dateTime: DateTime.now(), + dateTime: clock.now(), ); await ratings.vote(vote); _vote = castVote; diff --git a/pubspec.yaml b/pubspec.yaml index 402d63884..ff947df14 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: collection: ^1.17.0 dbus: ^0.7.8 app_center_ratings_client: - git: + git: url: https://github.com/matthew-hagemann/app_center_ratings_client.dart.git ref: main crypto: ^3.0.3 @@ -52,6 +52,7 @@ dependencies: yaru_icons: ^1.0.4 yaru_widgets: ^2.6.0 yaru_test: ^0.1.4 + clock: ^1.1.1 dev_dependencies: build_runner: ^2.4.5 diff --git a/test/ratings_model_test.dart b/test/ratings_model_test.dart new file mode 100644 index 000000000..bba353ecd --- /dev/null +++ b/test/ratings_model_test.dart @@ -0,0 +1,70 @@ +import 'package:app_center/ratings.dart'; +import 'package:clock/clock.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; + +import 'test_utils.dart'; + +void main() { + test('init', () async { + final mockService = createMockRatingsService( + rating: const Rating( + snapId: 'firefox', + totalVotes: 1337, + ratingsBand: RatingsBand.veryGood, + ), + snapVotes: [ + Vote( + snapId: 'firefox', + snapRevision: 42, + voteUp: true, + dateTime: DateTime(1970), + ), + ], + ); + final model = RatingsModel( + ratings: mockService, + snapId: 'firefox', + snapRevision: '42', + ); + + await model.init(); + expect(model.state.hasValue, isTrue); + expect( + model.snapRating, + equals( + const Rating( + snapId: 'firefox', + totalVotes: 1337, + ratingsBand: RatingsBand.veryGood, + ), + ), + ); + expect(model.vote, equals(VoteStatus.up)); + }); + + test('cast vote', () async { + final mockService = createMockRatingsService(); + final model = RatingsModel( + ratings: mockService, + snapId: 'firefox', + snapRevision: '42', + ); + + await model.init(); + await withClock( + Clock.fixed(DateTime(1984)), + () => model.castVote(VoteStatus.up), + ); + verify( + mockService.vote( + Vote( + dateTime: DateTime(1984), + snapId: 'firefox', + snapRevision: 42, + voteUp: true, + ), + ), + ).called(1); + }); +} diff --git a/test/test_utils.dart b/test/test_utils.dart index b8a40ce03..b68c3f3d4 100644 --- a/test/test_utils.dart +++ b/test/test_utils.dart @@ -283,9 +283,20 @@ MockPackageKitTransaction createMockPackageKitTransaction({ } @GenerateMocks([RatingsService]) -MockRatingsService createMockRatingsService() { +MockRatingsService createMockRatingsService({ + Rating? rating, + List? snapVotes, +}) { final service = MockRatingsService(); - when(service.vote(any)).thenAnswer((_) async => {}); + when(service.getRating(any)).thenAnswer((_) async => + rating ?? + const Rating( + snapId: '', + totalVotes: 0, + ratingsBand: RatingsBand.insufficientVotes, + )); + when(service.getSnapVotes(any)).thenAnswer((_) async => snapVotes ?? []); + return service; } From 6088b98006310891315c66b8f99aa1a5bb1b52ab Mon Sep 17 00:00:00 2001 From: Dennis Loose Date: Thu, 5 Oct 2023 13:00:54 +0200 Subject: [PATCH 3/3] test(snap_page): add missing ratings model mocks --- test/snap_page_test.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/snap_page_test.dart b/test/snap_page_test.dart index c48146419..7fcf8ca7e 100644 --- a/test/snap_page_test.dart +++ b/test/snap_page_test.dart @@ -279,12 +279,14 @@ void main() { ); final snapLauncher = createMockSnapLauncher(isLaunchable: true); final updatesModel = createMockUpdatesModel(); + final ratingsModel = createMockRatingsModel(); await tester.pumpApp((_) => ProviderScope( overrides: [ snapModelProvider.overrideWith((ref, arg) => snapModel), launchProvider.overrideWith((ref, arg) => snapLauncher), - updatesModelProvider.overrideWith((ref) => updatesModel) + updatesModelProvider.overrideWith((ref) => updatesModel), + ratingsModelProvider.overrideWith((ref, arg) => ratingsModel), ], child: SnapPage(snapName: storeSnap.name), )); @@ -313,12 +315,14 @@ void main() { ); final snapLauncher = createMockSnapLauncher(isLaunchable: true); final updatesModel = createMockUpdatesModel(); + final ratingsModel = createMockRatingsModel(); await tester.pumpApp((_) => ProviderScope( overrides: [ snapModelProvider.overrideWith((ref, arg) => snapModel), launchProvider.overrideWith((ref, arg) => snapLauncher), - updatesModelProvider.overrideWith((ref) => updatesModel) + updatesModelProvider.overrideWith((ref) => updatesModel), + ratingsModelProvider.overrideWith((ref, arg) => ratingsModel), ], child: SnapPage(snapName: storeSnap.name), ));