Skip to content

Commit 70aabfc

Browse files
Merge pull request #686 from parlough:fix/example-analysis-errors
PiperOrigin-RevId: 559428104
2 parents e54a006 + 9737d71 commit 70aabfc

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

example/example.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// ignore_for_file: sdk_version_async_exported_from_core
2-
// ignore_for_file: unawaited_futures
31
import 'package:mockito/annotations.dart';
42
import 'package:mockito/mockito.dart';
53
import 'package:test/test.dart';
@@ -35,7 +33,10 @@ abstract class Callbacks {
3533
Cat,
3634
Callbacks,
3735
], customMocks: [
38-
MockSpec<Cat>(as: #MockCatRelaxed, returnNullOnMissingStub: true),
36+
MockSpec<Cat>(
37+
as: #MockCatRelaxed,
38+
onMissingStub: OnMissingStub.returnDefault,
39+
),
3940
])
4041
void main() {
4142
late Cat cat;
@@ -57,14 +58,8 @@ void main() {
5758
});
5859

5960
test('How about some stubbing?', () {
60-
try {
61-
cat.sound();
62-
} on MissingStubError {
63-
// Unstubbed methods throw MissingStubError.
64-
}
65-
66-
// Unstubbed methods return null.
67-
expect(cat.sound(), null);
61+
// Unstubbed methods throw MissingStubError.
62+
expect(() => cat.sound(), throwsA(isA<MissingStubError>()));
6863

6964
// Stub a method before interacting with it.
7065
when(cat.sound()).thenReturn('Purr');
@@ -102,7 +97,7 @@ void main() {
10297
// ... or matchers
10398
when(cat.eatFood(argThat(startsWith('dry')))).thenReturn(false);
10499

105-
// ... or mix aguments with matchers
100+
// ... or mix arguments with matchers
106101
when(cat.eatFood(argThat(startsWith('dry')), hungry: true))
107102
.thenReturn(true);
108103
expect(cat.eatFood('fish'), isTrue);
@@ -239,7 +234,12 @@ void main() {
239234
// You can call it without stubbing.
240235
cat.sleep();
241236

242-
// Returns null unless you stub it.
237+
// Non-null properties and function return values
238+
// default to reasonable defaults.
239+
expect(cat.lives, 0);
240+
241+
// Nullable properties and function return values
242+
// default to null unless you stub them.
243243
expect(cat.sound(), null);
244244
expect(cat.eatFood('Milk'), null);
245245

0 commit comments

Comments
 (0)