-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
120 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/mocktail/test/mockito_compat/nnbd_support_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
class Foo { | ||
String? returnsNullableString() => 'Hello'; | ||
|
||
String returnsNonNullableString() => 'Hello'; | ||
} | ||
|
||
class MockFoo extends Mock implements Foo {} | ||
|
||
void main() { | ||
late MockFoo mock; | ||
|
||
setUp(() { | ||
mock = MockFoo(); | ||
}); | ||
|
||
tearDown(resetMocktailState); | ||
|
||
group('Using nSM out of the box,', () { | ||
test('nSM returns the dummy value during method stubbing', () { | ||
// Trigger method stubbing. | ||
final whenCall = when; | ||
final stubbedResponse = mock.returnsNullableString(); | ||
expect(stubbedResponse, equals(null)); | ||
whenCall(() => stubbedResponse).thenReturn('A'); | ||
}); | ||
|
||
test('nSM returns the dummy value during method call verification', () { | ||
when(() => mock.returnsNullableString()).thenReturn('A'); | ||
|
||
// Make a real call. | ||
final realResponse = mock.returnsNullableString(); | ||
expect(realResponse, equals('A')); | ||
|
||
// Trigger method call verification. | ||
final verifyCall = verify; | ||
final verificationResponse = mock.returnsNullableString(); | ||
expect(verificationResponse, equals(null)); | ||
verifyCall(() => verificationResponse); | ||
}); | ||
|
||
test( | ||
'nSM returns the dummy value during method call verification, using ' | ||
'verifyNever', () { | ||
// Trigger method call verification. | ||
final verifyNeverCall = verifyNever; | ||
final verificationResponse = mock.returnsNullableString(); | ||
expect(verificationResponse, equals(null)); | ||
verifyNeverCall(() => verificationResponse); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters