Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 834ffaa

Browse files
committed
extract assertion method
1 parent 9fdcfbb commit 834ffaa

File tree

2 files changed

+115
-120
lines changed

2 files changed

+115
-120
lines changed

packages/file_selector/file_selector_platform_interface/test/file_selector_platform_interface_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ void main() {
2222

2323
group('#GetDirectoryPaths', () {
2424
test('Should throw unimplemented exception', () async {
25-
final FileSelectorPlatform sut = ExtendsFileSelectorPlatform();
25+
final FileSelectorPlatform fileSelector = ExtendsFileSelectorPlatform();
2626

2727
await expectLater(() async {
28-
return sut.getDirectoryPaths();
28+
return fileSelector.getDirectoryPaths();
2929
}, throwsA(isA<UnimplementedError>()));
3030
});
3131
});

packages/file_selector/file_selector_platform_interface/test/method_channel_file_selector_test.dart

Lines changed: 113 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -43,49 +43,46 @@ void main() {
4343
await plugin
4444
.openFile(acceptedTypeGroups: <XTypeGroup>[group, groupTwo]);
4545

46-
expect(
46+
expectMethodCall(
4747
log,
48-
<Matcher>[
49-
isMethodCall('openFile', arguments: <String, dynamic>{
50-
'acceptedTypeGroups': <Map<String, dynamic>>[
51-
group.toJSON(),
52-
groupTwo.toJSON()
53-
],
54-
'initialDirectory': null,
55-
'confirmButtonText': null,
56-
'multiple': false,
57-
}),
58-
],
48+
'openFile',
49+
arguments: <String, dynamic>{
50+
'acceptedTypeGroups': <Map<String, dynamic>>[
51+
group.toJSON(),
52+
groupTwo.toJSON()
53+
],
54+
'initialDirectory': null,
55+
'confirmButtonText': null,
56+
'multiple': false,
57+
},
5958
);
6059
});
6160
test('passes initialDirectory correctly', () async {
6261
await plugin.openFile(initialDirectory: '/example/directory');
6362

64-
expect(
63+
expectMethodCall(
6564
log,
66-
<Matcher>[
67-
isMethodCall('openFile', arguments: <String, dynamic>{
68-
'acceptedTypeGroups': null,
69-
'initialDirectory': '/example/directory',
70-
'confirmButtonText': null,
71-
'multiple': false,
72-
}),
73-
],
65+
'openFile',
66+
arguments: <String, dynamic>{
67+
'acceptedTypeGroups': null,
68+
'initialDirectory': '/example/directory',
69+
'confirmButtonText': null,
70+
'multiple': false,
71+
},
7472
);
7573
});
7674
test('passes confirmButtonText correctly', () async {
7775
await plugin.openFile(confirmButtonText: 'Open File');
7876

79-
expect(
77+
expectMethodCall(
8078
log,
81-
<Matcher>[
82-
isMethodCall('openFile', arguments: <String, dynamic>{
83-
'acceptedTypeGroups': null,
84-
'initialDirectory': null,
85-
'confirmButtonText': 'Open File',
86-
'multiple': false,
87-
}),
88-
],
79+
'openFile',
80+
arguments: <String, dynamic>{
81+
'acceptedTypeGroups': null,
82+
'initialDirectory': null,
83+
'confirmButtonText': 'Open File',
84+
'multiple': false,
85+
},
8986
);
9087
});
9188
});
@@ -108,49 +105,46 @@ void main() {
108105
await plugin
109106
.openFiles(acceptedTypeGroups: <XTypeGroup>[group, groupTwo]);
110107

111-
expect(
108+
expectMethodCall(
112109
log,
113-
<Matcher>[
114-
isMethodCall('openFile', arguments: <String, dynamic>{
115-
'acceptedTypeGroups': <Map<String, dynamic>>[
116-
group.toJSON(),
117-
groupTwo.toJSON()
118-
],
119-
'initialDirectory': null,
120-
'confirmButtonText': null,
121-
'multiple': true,
122-
}),
123-
],
110+
'openFile',
111+
arguments: <String, dynamic>{
112+
'acceptedTypeGroups': <Map<String, dynamic>>[
113+
group.toJSON(),
114+
groupTwo.toJSON()
115+
],
116+
'initialDirectory': null,
117+
'confirmButtonText': null,
118+
'multiple': true,
119+
},
124120
);
125121
});
126122
test('passes initialDirectory correctly', () async {
127123
await plugin.openFiles(initialDirectory: '/example/directory');
128124

129-
expect(
125+
expectMethodCall(
130126
log,
131-
<Matcher>[
132-
isMethodCall('openFile', arguments: <String, dynamic>{
133-
'acceptedTypeGroups': null,
134-
'initialDirectory': '/example/directory',
135-
'confirmButtonText': null,
136-
'multiple': true,
137-
}),
138-
],
127+
'openFile',
128+
arguments: <String, dynamic>{
129+
'acceptedTypeGroups': null,
130+
'initialDirectory': '/example/directory',
131+
'confirmButtonText': null,
132+
'multiple': true,
133+
},
139134
);
140135
});
141136
test('passes confirmButtonText correctly', () async {
142137
await plugin.openFiles(confirmButtonText: 'Open File');
143138

144-
expect(
139+
expectMethodCall(
145140
log,
146-
<Matcher>[
147-
isMethodCall('openFile', arguments: <String, dynamic>{
148-
'acceptedTypeGroups': null,
149-
'initialDirectory': null,
150-
'confirmButtonText': 'Open File',
151-
'multiple': true,
152-
}),
153-
],
141+
'openFile',
142+
arguments: <String, dynamic>{
143+
'acceptedTypeGroups': null,
144+
'initialDirectory': null,
145+
'confirmButtonText': 'Open File',
146+
'multiple': true,
147+
},
154148
);
155149
});
156150
});
@@ -174,108 +168,109 @@ void main() {
174168
await plugin
175169
.getSavePath(acceptedTypeGroups: <XTypeGroup>[group, groupTwo]);
176170

177-
expect(
171+
expectMethodCall(
178172
log,
179-
<Matcher>[
180-
isMethodCall('getSavePath', arguments: <String, dynamic>{
181-
'acceptedTypeGroups': <Map<String, dynamic>>[
182-
group.toJSON(),
183-
groupTwo.toJSON()
184-
],
185-
'initialDirectory': null,
186-
'suggestedName': null,
187-
'confirmButtonText': null,
188-
}),
189-
],
173+
'getSavePath',
174+
arguments: <String, dynamic>{
175+
'acceptedTypeGroups': <Map<String, dynamic>>[
176+
group.toJSON(),
177+
groupTwo.toJSON()
178+
],
179+
'initialDirectory': null,
180+
'suggestedName': null,
181+
'confirmButtonText': null,
182+
},
190183
);
191184
});
192185
test('passes initialDirectory correctly', () async {
193186
await plugin.getSavePath(initialDirectory: '/example/directory');
194187

195-
expect(
188+
expectMethodCall(
196189
log,
197-
<Matcher>[
198-
isMethodCall('getSavePath', arguments: <String, dynamic>{
199-
'acceptedTypeGroups': null,
200-
'initialDirectory': '/example/directory',
201-
'suggestedName': null,
202-
'confirmButtonText': null,
203-
}),
204-
],
190+
'getSavePath',
191+
arguments: <String, dynamic>{
192+
'acceptedTypeGroups': null,
193+
'initialDirectory': '/example/directory',
194+
'suggestedName': null,
195+
'confirmButtonText': null,
196+
},
205197
);
206198
});
207199
test('passes confirmButtonText correctly', () async {
208200
await plugin.getSavePath(confirmButtonText: 'Open File');
209201

210-
expect(
202+
expectMethodCall(
211203
log,
212-
<Matcher>[
213-
isMethodCall('getSavePath', arguments: <String, dynamic>{
214-
'acceptedTypeGroups': null,
215-
'initialDirectory': null,
216-
'suggestedName': null,
217-
'confirmButtonText': 'Open File',
218-
}),
219-
],
204+
'getSavePath',
205+
arguments: <String, dynamic>{
206+
'acceptedTypeGroups': null,
207+
'initialDirectory': null,
208+
'suggestedName': null,
209+
'confirmButtonText': 'Open File',
210+
},
220211
);
221212
});
222213
});
223214
group('#getDirectoryPath', () {
224215
test('passes initialDirectory correctly', () async {
225216
await plugin.getDirectoryPath(initialDirectory: '/example/directory');
226217

227-
expect(
218+
expectMethodCall(
228219
log,
229-
<Matcher>[
230-
isMethodCall('getDirectoryPath', arguments: <String, dynamic>{
231-
'initialDirectory': '/example/directory',
232-
'confirmButtonText': null,
233-
}),
234-
],
220+
'getDirectoryPath',
221+
arguments: <String, dynamic>{
222+
'initialDirectory': '/example/directory',
223+
'confirmButtonText': null,
224+
},
235225
);
236226
});
237227
test('passes confirmButtonText correctly', () async {
238228
await plugin.getDirectoryPath(confirmButtonText: 'Select Folder');
239229

240-
expect(
230+
expectMethodCall(
241231
log,
242-
<Matcher>[
243-
isMethodCall('getDirectoryPath', arguments: <String, dynamic>{
244-
'initialDirectory': null,
245-
'confirmButtonText': 'Select Folder',
246-
}),
247-
],
232+
'getDirectoryPath',
233+
arguments: <String, dynamic>{
234+
'initialDirectory': null,
235+
'confirmButtonText': 'Select Folder',
236+
},
248237
);
249238
});
250239
});
251240
group('#getDirectoryPaths', () {
252241
test('passes initialDirectory correctly', () async {
253242
await plugin.getDirectoryPaths(initialDirectory: '/example/directory');
254243

255-
expect(
244+
expectMethodCall(
256245
log,
257-
<Matcher>[
258-
isMethodCall('getDirectoryPaths', arguments: <String, dynamic>{
259-
'initialDirectory': '/example/directory',
260-
'confirmButtonText': null,
261-
}),
262-
],
246+
'getDirectoryPaths',
247+
arguments: <String, dynamic>{
248+
'initialDirectory': '/example/directory',
249+
'confirmButtonText': null,
250+
},
263251
);
264252
});
265253
test('passes confirmButtonText correctly', () async {
266254
await plugin.getDirectoryPaths(
267255
confirmButtonText: 'Select one or more Folders');
268256

269-
expect(
257+
expectMethodCall(
270258
log,
271-
<Matcher>[
272-
isMethodCall('getDirectoryPaths', arguments: <String, dynamic>{
273-
'initialDirectory': null,
274-
'confirmButtonText': 'Select one or more Folders',
275-
}),
276-
],
259+
'getDirectoryPaths',
260+
arguments: <String, dynamic>{
261+
'initialDirectory': null,
262+
'confirmButtonText': 'Select one or more Folders',
263+
},
277264
);
278265
});
279266
});
280267
});
281268
}
269+
270+
void expectMethodCall(
271+
List<MethodCall> log,
272+
String methodName, {
273+
Map<String, dynamic>? arguments,
274+
}) {
275+
expect(log, <Matcher>[isMethodCall(methodName, arguments: arguments)]);
276+
}

0 commit comments

Comments
 (0)