11import 'package:dbus/dbus.dart' ;
22import 'package:flutter_test/flutter_test.dart' ;
3- import 'package:mockito/annotations.dart' ;
4- import 'package:mockito/mockito.dart' ;
3+ import 'package:mocktail/mocktail.dart' ;
54import 'package:wakelock_plus/src/wakelock_plus_linux_plugin.dart' ;
65import 'package:wakelock_plus_platform_interface/wakelock_plus_platform_interface.dart' ;
76
8- import 'wakelock_plus_linux_plugin_test.mocks.dart' ;
7+ class MockDBusClient extends Mock implements DBusClient {}
8+
9+ class MockDBusRemoteObject extends Mock implements DBusRemoteObject {}
10+
11+ class FakeDBusSignature extends Fake implements DBusSignature {}
912
10- @GenerateMocks ([DBusClient , DBusRemoteObject ])
1113void main () {
1214 TestWidgetsFlutterBinding .ensureInitialized ();
1315
16+ setUpAll (() {
17+ registerFallbackValue (FakeDBusSignature ());
18+ });
19+
1420 group ('WakelockPlusLinuxPlugin' , () {
1521 late MockDBusClient mockClient;
1622 late MockDBusRemoteObject mockPortalObject;
@@ -50,22 +56,22 @@ void main() {
5056 ]);
5157
5258 when (
53- mockPortalObject.callMethod (
59+ () => mockPortalObject.callMethod (
5460 'org.freedesktop.portal.Inhibit' ,
5561 'Inhibit' ,
56- any,
57- replySignature: anyNamed ( 'replySignature' ),
62+ any () ,
63+ replySignature: any (named : 'replySignature' ),
5864 ),
5965 ).thenAnswer ((_) async => mockResponse);
6066
6167 await plugin.toggle (enable: true );
6268
6369 verify (
64- mockPortalObject.callMethod (
70+ () => mockPortalObject.callMethod (
6571 'org.freedesktop.portal.Inhibit' ,
6672 'Inhibit' ,
67- argThat (
68- isA <List >()
73+ any (
74+ that : isA <List >()
6975 .having ((l) => l.length, 'length' , 3 )
7076 .having ((l) => l[0 ], 'window' , isA <DBusString >())
7177 .having ((l) => l[1 ], 'flags' , isA <DBusUint32 >())
@@ -84,26 +90,26 @@ void main() {
8490 ]);
8591
8692 when (
87- mockPortalObject.callMethod (
88- any,
89- any,
90- any,
91- replySignature: anyNamed ( 'replySignature' ),
93+ () => mockPortalObject.callMethod (
94+ any () ,
95+ any () ,
96+ any () ,
97+ replySignature: any (named : 'replySignature' ),
9298 ),
9399 ).thenAnswer ((_) async => mockResponse);
94100
95101 await plugin.toggle (enable: true );
96102
97103 final captured =
98104 verify (
99- mockPortalObject.callMethod (
100- any,
101- any,
102- captureAny,
103- replySignature: anyNamed ( 'replySignature' ),
105+ () => mockPortalObject.callMethod (
106+ any () ,
107+ any () ,
108+ captureAny () ,
109+ replySignature: any (named : 'replySignature' ),
104110 ),
105111 ).captured.single
106- as List ;
112+ as List < dynamic > ;
107113
108114 final flags = captured[1 ] as DBusUint32 ;
109115 expect (flags.value, equals (8 )); // 8 = Idle flag
@@ -115,26 +121,26 @@ void main() {
115121 ]);
116122
117123 when (
118- mockPortalObject.callMethod (
119- any,
120- any,
121- any,
122- replySignature: anyNamed ( 'replySignature' ),
124+ () => mockPortalObject.callMethod (
125+ any () ,
126+ any () ,
127+ any () ,
128+ replySignature: any (named : 'replySignature' ),
123129 ),
124130 ).thenAnswer ((_) async => mockResponse);
125131
126132 await plugin.toggle (enable: true );
127133
128134 final captured =
129135 verify (
130- mockPortalObject.callMethod (
131- any,
132- any,
133- captureAny,
134- replySignature: anyNamed ( 'replySignature' ),
136+ () => mockPortalObject.callMethod (
137+ any () ,
138+ any () ,
139+ captureAny () ,
140+ replySignature: any (named : 'replySignature' ),
135141 ),
136142 ).captured.single
137- as List ;
143+ as List < dynamic > ;
138144
139145 final options = captured[2 ] as DBusDict ;
140146 expect (options.children.containsKey (DBusString ('reason' )), isTrue);
@@ -150,22 +156,22 @@ void main() {
150156 final mockCloseResponse = DBusMethodSuccessResponse ([]);
151157
152158 when (
153- mockPortalObject.callMethod (
159+ () => mockPortalObject.callMethod (
154160 'org.freedesktop.portal.Inhibit' ,
155161 'Inhibit' ,
156- any,
157- replySignature: anyNamed ( 'replySignature' ),
162+ any () ,
163+ replySignature: any (named : 'replySignature' ),
158164 ),
159165 ).thenAnswer ((_) async => mockInhibitResponse);
160166
161167 // Mock the Close call on DBusClient
162168 when (
163- mockClient.callMethod (
169+ () => mockClient.callMethod (
164170 destination: 'org.freedesktop.portal.Desktop' ,
165171 path: handlePath,
166172 interface : 'org.freedesktop.portal.Request' ,
167173 name: 'Close' ,
168- values: [] ,
174+ values: any (named : 'values' ) ,
169175 replySignature: DBusSignature .empty,
170176 ),
171177 ).thenAnswer ((_) async => mockCloseResponse);
@@ -180,7 +186,7 @@ void main() {
180186
181187 // Verify Close was called
182188 verify (
183- mockClient.callMethod (
189+ () => mockClient.callMethod (
184190 destination: 'org.freedesktop.portal.Desktop' ,
185191 path: handlePath,
186192 interface : 'org.freedesktop.portal.Request' ,
@@ -195,11 +201,11 @@ void main() {
195201 await plugin.toggle (enable: false );
196202 expect (await plugin.enabled, isFalse);
197203 verifyNever (
198- mockPortalObject.callMethod (
199- any,
200- any,
201- any,
202- replySignature: anyNamed ( 'replySignature' ),
204+ () => mockPortalObject.callMethod (
205+ any () ,
206+ any () ,
207+ any () ,
208+ replySignature: any (named : 'replySignature' ),
203209 ),
204210 );
205211 });
@@ -216,11 +222,11 @@ void main() {
216222 ]);
217223
218224 when (
219- mockPortalObject.callMethod (
220- any,
221- any,
222- any,
223- replySignature: anyNamed ( 'replySignature' ),
225+ () => mockPortalObject.callMethod (
226+ any () ,
227+ any () ,
228+ any () ,
229+ replySignature: any (named : 'replySignature' ),
224230 ),
225231 ).thenAnswer ((_) async => mockResponse);
226232
0 commit comments