Skip to content

Commit

Permalink
Merge pull request #17 from kosukesaigusa/test/dart_object_util
Browse files Browse the repository at this point in the history
test: add dart_object_util test
  • Loading branch information
kosukesaigusa authored Dec 22, 2023
2 parents 150468e + 8447397 commit 8d6cbc3
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/flutterfire_gen/test/utils/dart_object_util_test.dart
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');
});
});
}
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?);
}
Loading

0 comments on commit 8d6cbc3

Please sign in to comment.