Skip to content

tests: mockito dependency updates due to breaking API changes #5013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Timestamp implements Comparable<Timestamp> {

/// Create a [Timestamp] fromMillisecondsSinceEpoch
factory Timestamp.fromMillisecondsSinceEpoch(int milliseconds) {
final int seconds = (milliseconds ~/ _kThousand).floor();
int seconds = (milliseconds / _kThousand).floor();
final int nanoseconds = (milliseconds - seconds * _kThousand) * _kMillion;
return Timestamp(seconds, nanoseconds);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ import 'package:cloud_firestore_platform_interface/src/method_channel/method_cha

import '../utils/test_common.dart';

const String mockId = 'mock-id';
const String mockPath = 'foo/bar';

//ignore: avoid_implementing_value_types
class MockDocumentReference extends Mock implements DocumentReferencePlatform {
@override
String get path => super.noSuchMethod(Invocation.getter(#path), 'foo/bar');
String get path => super.noSuchMethod(Invocation.getter(#path),
returnValue: mockPath, returnValueForMissingStub: mockPath);
@override
String get id => super.noSuchMethod(Invocation.getter(#id), 'mock-id');
String get id => super.noSuchMethod(Invocation.getter(#id),
returnValue: mockId, returnValueForMissingStub: mockId);
}

const _kTransactionId = '1022';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
const int _kBillion = 1000000000;
const int _kStartOfTime = -62135596800;
const int _kEndOfTime = 253402300800;
const int int64MaxValue = 9223372036854775807;

void main() {
group('$Timestamp', () {
Expand All @@ -34,5 +35,49 @@ void main() {
Timestamp maxTimestamp = Timestamp(_kEndOfTime - 1, _kBillion - 1);
Timestamp.fromMicrosecondsSinceEpoch(maxTimestamp.microsecondsSinceEpoch);
});

test('fromMillisecondsSinceEpoch throws max out of range exception', () {
expect(() => Timestamp.fromMillisecondsSinceEpoch(int64MaxValue),
throwsArgumentError);
});

test('fromMillisecondsSinceEpoch can handle current timestamp', () {
int currentEpoch = DateTime.now().millisecondsSinceEpoch;
Timestamp t = Timestamp.fromMillisecondsSinceEpoch(currentEpoch);

expect(t.toDate().year > 1970, equals(true));
});

test('fromMillisecondsSinceEpoch can handle future date', () {
int currentEpoch = DateTime.now().millisecondsSinceEpoch + 999999999;
Timestamp t = Timestamp.fromMillisecondsSinceEpoch(currentEpoch);

expect(
t.toDate().millisecondsSinceEpoch >
DateTime.now().millisecondsSinceEpoch,
equals(true));
});

test('fromMillisecondsSinceEpoch can handle 0', () {
Timestamp t = Timestamp.fromMillisecondsSinceEpoch(0);
expect(t.toDate().year, 1970);
expect(t.toDate().month, 1);
expect(t.toDate().day, 1);
});

test('fromMillisecondsSinceEpoch can handle negative millisecond values',
() {
Timestamp t = Timestamp.fromMillisecondsSinceEpoch(-9999999999);

expect(t.toDate().year, 1969);
expect(t.toDate().month, 9);
});

test('millisecondsSinceEpoch returns correct negative epoch value', () {
Timestamp t = Timestamp.fromMillisecondsSinceEpoch(-9999999999);
int epoch = t.millisecondsSinceEpoch;

expect(epoch, equals(-9999999999));
});
});
}
88 changes: 59 additions & 29 deletions packages/firebase_auth/firebase_auth/test/firebase_auth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -651,31 +651,35 @@ class MockFirebaseAuth extends Mock
Stream<UserPlatform?> userChanges() {
return super.noSuchMethod(
Invocation.method(#userChanges, []),
const Stream<UserPlatform?>.empty(),
returnValue: const Stream<UserPlatform?>.empty(),
returnValueForMissingStub: const Stream<UserPlatform?>.empty(),
);
}

@override
Stream<UserPlatform?> idTokenChanges() {
return super.noSuchMethod(
Invocation.method(#idTokenChanges, []),
const Stream<UserPlatform?>.empty(),
returnValue: const Stream<UserPlatform?>.empty(),
returnValueForMissingStub: const Stream<UserPlatform?>.empty(),
);
}

@override
Stream<UserPlatform?> authStateChanges() {
return super.noSuchMethod(
Invocation.method(#authStateChanges, []),
const Stream<UserPlatform?>.empty(),
returnValue: const Stream<UserPlatform?>.empty(),
returnValueForMissingStub: const Stream<UserPlatform?>.empty(),
);
}

@override
FirebaseAuthPlatform delegateFor({FirebaseApp? app}) {
return super.noSuchMethod(
Invocation.method(#delegateFor, [], {#app: app}),
TestFirebaseAuthPlatform(),
returnValue: TestFirebaseAuthPlatform(),
returnValueForMissingStub: TestFirebaseAuthPlatform(),
);
}

Expand All @@ -686,7 +690,8 @@ class MockFirebaseAuth extends Mock
) {
return super.noSuchMethod(
Invocation.method(#createUserWithEmailAndPassword, [email, password]),
neverEndingFuture<UserCredentialPlatform>(),
returnValue: neverEndingFuture<UserCredentialPlatform>(),
returnValueForMissingStub: neverEndingFuture<UserCredentialPlatform>(),
);
}

Expand All @@ -700,7 +705,9 @@ class MockFirebaseAuth extends Mock
#signInWithPhoneNumber,
[phoneNumber, applicationVerifier],
),
neverEndingFuture<ConfirmationResultPlatform>(),
returnValue: neverEndingFuture<ConfirmationResultPlatform>(),
returnValueForMissingStub:
neverEndingFuture<ConfirmationResultPlatform>(),
);
}

Expand All @@ -710,15 +717,17 @@ class MockFirebaseAuth extends Mock
) {
return super.noSuchMethod(
Invocation.method(#signInWithCredential, [credential]),
neverEndingFuture<UserCredentialPlatform>(),
returnValue: neverEndingFuture<UserCredentialPlatform>(),
returnValueForMissingStub: neverEndingFuture<UserCredentialPlatform>(),
);
}

@override
Future<UserCredentialPlatform> signInWithCustomToken(String? token) {
return super.noSuchMethod(
Invocation.method(#signInWithCustomToken, [token]),
neverEndingFuture<UserCredentialPlatform>(),
returnValue: neverEndingFuture<UserCredentialPlatform>(),
returnValueForMissingStub: neverEndingFuture<UserCredentialPlatform>(),
);
}

Expand All @@ -729,15 +738,17 @@ class MockFirebaseAuth extends Mock
) {
return super.noSuchMethod(
Invocation.method(#signInWithEmailAndPassword, [email, password]),
neverEndingFuture<UserCredentialPlatform>(),
returnValue: neverEndingFuture<UserCredentialPlatform>(),
returnValueForMissingStub: neverEndingFuture<UserCredentialPlatform>(),
);
}

@override
Future<UserCredentialPlatform> signInWithPopup(AuthProvider? provider) {
return super.noSuchMethod(
Invocation.method(#signInWithPopup, [provider]),
neverEndingFuture<UserCredentialPlatform>(),
returnValue: neverEndingFuture<UserCredentialPlatform>(),
returnValueForMissingStub: neverEndingFuture<UserCredentialPlatform>(),
);
}

Expand All @@ -748,23 +759,26 @@ class MockFirebaseAuth extends Mock
) {
return super.noSuchMethod(
Invocation.method(#signInWithEmailLink, [email, emailLink]),
neverEndingFuture<UserCredentialPlatform>(),
returnValue: neverEndingFuture<UserCredentialPlatform>(),
returnValueForMissingStub: neverEndingFuture<UserCredentialPlatform>(),
);
}

@override
Future<void> signInWithRedirect(AuthProvider? provider) {
return super.noSuchMethod(
Invocation.method(#signInWithRedirect, [provider]),
neverEndingFuture<void>(),
returnValue: neverEndingFuture<void>(),
returnValueForMissingStub: neverEndingFuture<void>(),
);
}

@override
Future<UserCredentialPlatform> signInAnonymously() {
return super.noSuchMethod(
Invocation.method(#signInAnonymously, []),
neverEndingFuture<UserCredentialPlatform>(),
returnValue: neverEndingFuture<UserCredentialPlatform>(),
returnValueForMissingStub: neverEndingFuture<UserCredentialPlatform>(),
);
}

Expand All @@ -778,63 +792,71 @@ class MockFirebaseAuth extends Mock
#currentUser: currentUser,
#languageCode: languageCode,
}),
TestFirebaseAuthPlatform(),
returnValue: TestFirebaseAuthPlatform(),
returnValueForMissingStub: TestFirebaseAuthPlatform(),
);
}

@override
Future<UserCredentialPlatform> getRedirectResult() {
return super.noSuchMethod(
Invocation.method(#getRedirectResult, []),
neverEndingFuture<UserCredentialPlatform>(),
returnValue: neverEndingFuture<UserCredentialPlatform>(),
returnValueForMissingStub: neverEndingFuture<UserCredentialPlatform>(),
);
}

@override
Future<void> setLanguageCode(String? languageCode) {
return super.noSuchMethod(
Invocation.method(#setLanguageCode, [languageCode]),
neverEndingFuture<void>(),
returnValue: neverEndingFuture<void>(),
returnValueForMissingStub: neverEndingFuture<void>(),
);
}

@override
Future<void> useEmulator(String host, int port) {
return super.noSuchMethod(
Invocation.method(#useEmulator, [host, port]),
neverEndingFuture<void>(),
returnValue: neverEndingFuture<void>(),
returnValueForMissingStub: neverEndingFuture<void>(),
);
}

@override
Future<ActionCodeInfo> checkActionCode(String? code) {
return super.noSuchMethod(
Invocation.method(#checkActionCode, [code]),
neverEndingFuture<ActionCodeInfo>(),
returnValue: neverEndingFuture<ActionCodeInfo>(),
returnValueForMissingStub: neverEndingFuture<ActionCodeInfo>(),
);
}

@override
Future<void> confirmPasswordReset(String? code, String? newPassword) {
return super.noSuchMethod(
Invocation.method(#confirmPasswordReset, [code, newPassword]),
neverEndingFuture<void>(),
returnValue: neverEndingFuture<void>(),
returnValueForMissingStub: neverEndingFuture<void>(),
);
}

@override
Future<List<String>> fetchSignInMethodsForEmail(String? email) {
return super.noSuchMethod(
Invocation.method(#checkActionCode, [email]),
neverEndingFuture<List<String>>(),
returnValue: neverEndingFuture<List<String>>(),
returnValueForMissingStub: neverEndingFuture<List<String>>(),
);
}

@override
bool isSignInWithEmailLink(String? emailLink) {
return super.noSuchMethod(
Invocation.method(#isSignInWithEmailLink, [emailLink]),
false,
returnValue: false,
returnValueForMissingStub: false,
);
}

Expand All @@ -845,7 +867,8 @@ class MockFirebaseAuth extends Mock
]) {
return super.noSuchMethod(
Invocation.method(#sendPasswordResetEmail, [email, actionCodeSettings]),
neverEndingFuture<void>(),
returnValue: neverEndingFuture<void>(),
returnValueForMissingStub: neverEndingFuture<void>(),
);
}

Expand All @@ -856,7 +879,8 @@ class MockFirebaseAuth extends Mock
) {
return super.noSuchMethod(
Invocation.method(#sendSignInLinkToEmail, [email, actionCodeSettings]),
neverEndingFuture<void>(),
returnValue: neverEndingFuture<void>(),
returnValueForMissingStub: neverEndingFuture<void>(),
);
}

Expand All @@ -870,31 +894,35 @@ class MockFirebaseAuth extends Mock
appVerificationDisabledForTesting,
userAccessGroup,
]),
neverEndingFuture<void>(),
returnValue: neverEndingFuture<void>(),
returnValueForMissingStub: neverEndingFuture<void>(),
);
}

@override
Future<void> setPersistence(Persistence? persistence) {
return super.noSuchMethod(
Invocation.method(#setPersistence, [persistence]),
neverEndingFuture<void>(),
returnValue: neverEndingFuture<void>(),
returnValueForMissingStub: neverEndingFuture<void>(),
);
}

@override
Future<void> signOut() {
return super.noSuchMethod(
Invocation.method(#signOut, [signOut]),
neverEndingFuture<void>(),
returnValue: neverEndingFuture<void>(),
returnValueForMissingStub: neverEndingFuture<void>(),
);
}

@override
Future<String> verifyPasswordResetCode(String? code) {
return super.noSuchMethod(
Invocation.method(#verifyPasswordResetCode, [code]),
neverEndingFuture<String>(),
returnValue: neverEndingFuture<String>(),
returnValueForMissingStub: neverEndingFuture<String>(),
);
}

Expand All @@ -920,7 +948,8 @@ class MockFirebaseAuth extends Mock
#forceResendingToken: forceResendingToken,
#autoRetrievedSmsCodeForTesting: autoRetrievedSmsCodeForTesting,
}),
neverEndingFuture<String>(),
returnValue: neverEndingFuture<String>(),
returnValueForMissingStub: neverEndingFuture<String>(),
);
}
}
Expand Down Expand Up @@ -1000,7 +1029,8 @@ class MockRecaptchaVerifier extends Mock
RecaptchaVerifierFactoryPlatform get delegate {
return super.noSuchMethod(
Invocation.getter(#delegate),
MockRecaptchaVerifierFactoryPlatform(),
returnValue: MockRecaptchaVerifierFactoryPlatform(),
returnValueForMissingStub: MockRecaptchaVerifierFactoryPlatform(),
);
}
}
Expand Down
Loading