-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from kosukesaigusa/test/dart_object_util
test: add dart_object_util test
- Loading branch information
Showing
3 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
packages/flutterfire_gen/test/utils/dart_object_util_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,42 @@ | ||
import 'package:analyzer/dart/constant/value.dart'; | ||
import 'package:flutterfire_gen/src/utils/dart_object_util.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import 'dart_object_util_test.mocks.dart'; | ||
|
||
@GenerateMocks([DartObject]) | ||
void main() { | ||
group('DartObjectExtension tests', () { | ||
final pathDartObject = MockDartObject(); | ||
when(pathDartObject.isNull).thenReturn(false); | ||
when(pathDartObject.toStringValue()).thenReturn('users/{userId}/'); | ||
|
||
final firestoreDocumentAnnotation = MockDartObject(); | ||
when(firestoreDocumentAnnotation.getField('path')) | ||
.thenReturn(pathDartObject); | ||
when(firestoreDocumentAnnotation.getField('readClassPrefix')) | ||
.thenReturn(null); | ||
|
||
test('test decodeField', () { | ||
final path = firestoreDocumentAnnotation.decodeField( | ||
'path', | ||
decode: (obj) => obj.toStringValue()!, | ||
orElse: () => throw Exception('path field is required.'), | ||
); | ||
|
||
expect(path, 'users/{userId}/'); | ||
}); | ||
|
||
test('test decodeField if the field does not exist', () { | ||
final readClassPrefix = firestoreDocumentAnnotation.decodeField( | ||
'readClassPrefix', | ||
decode: (obj) => obj.toStringValue()!, | ||
orElse: () => 'Read', | ||
); | ||
|
||
expect(readClassPrefix, 'Read'); | ||
}); | ||
}); | ||
} |
48 changes: 48 additions & 0 deletions
48
packages/flutterfire_gen/test/utils/dart_object_util_test.mocks.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,48 @@ | ||
// Mocks generated by Mockito 5.4.4 from annotations | ||
// in flutterfire_gen/test/utils/dart_object_util_test.dart. | ||
// Do not manually edit this file. | ||
|
||
// ignore_for_file: no_leading_underscores_for_library_prefixes | ||
import 'package:analyzer/dart/constant/value.dart' as _i2; | ||
import 'package:mockito/mockito.dart' as _i1; | ||
|
||
// ignore_for_file: type=lint | ||
// ignore_for_file: avoid_redundant_argument_values | ||
// ignore_for_file: avoid_setters_without_getters | ||
// ignore_for_file: comment_references | ||
// ignore_for_file: deprecated_member_use | ||
// ignore_for_file: deprecated_member_use_from_same_package | ||
// ignore_for_file: implementation_imports | ||
// ignore_for_file: invalid_use_of_visible_for_testing_member | ||
// ignore_for_file: prefer_const_constructors | ||
// ignore_for_file: unnecessary_parenthesis | ||
// ignore_for_file: camel_case_types | ||
// ignore_for_file: subtype_of_sealed_class | ||
|
||
/// A class which mocks [DartObject]. | ||
/// | ||
/// See the documentation for Mockito's code generation for more information. | ||
class MockDartObject extends _i1.Mock implements _i2.DartObject { | ||
MockDartObject() { | ||
_i1.throwOnMissingStub(this); | ||
} | ||
|
||
@override | ||
bool get hasKnownValue => (super.noSuchMethod( | ||
Invocation.getter(#hasKnownValue), | ||
returnValue: false, | ||
) as bool); | ||
|
||
@override | ||
bool get isNull => (super.noSuchMethod( | ||
Invocation.getter(#isNull), | ||
returnValue: false, | ||
) as bool); | ||
|
||
@override | ||
_i2.DartObject? getField(String? name) => | ||
(super.noSuchMethod(Invocation.method( | ||
#getField, | ||
[name], | ||
)) as _i2.DartObject?); | ||
} |
Oops, something went wrong.