Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[google_sign_in, in_app_purchase_android] Add availability to mock models #5642

Merged
merged 17 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ Rahul Raj <64.rahulraj@gmail.com>
Daniel Roek <daniel.roek@gmail.com>
TheOneWithTheBraid <the-one@with-the-braid.cf>
Rulong Chen(陈汝龙) <rulong.crl@alibaba-inc.com>
Hwanseok Kang <tttkhs96@gmail.com>
4 changes: 4 additions & 0 deletions packages/google_sign_in/google_sign_in/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.3.1

* Enables mocking models by changing overridden operator == parameter type from `dynamic` to `Object`.

## 5.3.0

* Moves Android and iOS implementations to federated packages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class GoogleSignInAccount implements GoogleIdentity {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
if (identical(this, other)) {
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/google_sign_in/google_sign_in/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system
for signing in with a Google account on Android and iOS.
repository: https://github.com/flutter/plugins/tree/main/packages/google_sign_in/google_sign_in
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
version: 5.3.0
version: 5.3.1


environment:
Expand Down Expand Up @@ -36,6 +36,7 @@ dev_dependencies:
http: ^0.13.0
integration_test:
sdk: flutter
mockito: ^5.1.0

# The example deliberately includes limited-use secrets.
false_secrets:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:google_sign_in/testing.dart';
import 'package:google_sign_in_platform_interface/google_sign_in_platform_interface.dart';
import 'package:mockito/mockito.dart';

/// Verify that [GoogleSignInAccount] can be mocked even though it's unused
class MockGoogleSignInAccount extends Mock implements GoogleSignInAccount {}
Hwan-seok marked this conversation as resolved.
Show resolved Hide resolved
Hwan-seok marked this conversation as resolved.
Show resolved Hide resolved

void main() {
TestWidgetsFlutterBinding.ensureInitialized();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.1.3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to move all of the google_sign_in_platform_interface (or all of the google_sign_in) changes to another PR; this is tripping our check against changing code in multiple parts of a federated plugin at the same time. (In this case it happens to be safe, but it's a sufficiently dangerous thing in general that our CI actually enforces not doing it in most cases.)

Just leave a link to the new PR here and I can make sure that the new PR gets reviewed along with this one.

Copy link
Contributor Author

@Hwan-seok Hwan-seok May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new PR: #5669


* Enables mocking models by changing overridden operator == parameter type from `dynamic` to `Object`.
* Removes unnecessary imports.

## 2.1.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class GoogleSignInUserData {
@override
// TODO(stuartmorgan): Make this class immutable in the next breaking change.
// ignore: avoid_equals_and_hash_code_on_mutable_classes
bool operator ==(dynamic other) {
bool operator ==(Object other) {
if (identical(this, other)) {
return true;
}
Expand Down Expand Up @@ -122,7 +122,7 @@ class GoogleSignInTokenData {
@override
// TODO(stuartmorgan): Make this class immutable in the next breaking change.
// ignore: avoid_equals_and_hash_code_on_mutable_classes
bool operator ==(dynamic other) {
bool operator ==(Object other) {
if (identical(this, other)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/google_sign_in
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.1.2
version: 2.1.3

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,43 @@ void main() {
GoogleSignInPlatform.instance = ImplementsWithIsMock();
});
});

group('GoogleSignInTokenData', () {
test('can be compared by == operator', () {
final GoogleSignInTokenData firstInstance = GoogleSignInTokenData(
accessToken: 'accessToken',
idToken: 'idToken',
serverAuthCode: 'serverAuthCode',
);
final GoogleSignInTokenData secondInstance = GoogleSignInTokenData(
accessToken: 'accessToken',
idToken: 'idToken',
serverAuthCode: 'serverAuthCode',
);
expect(firstInstance == secondInstance, isTrue);
});
});
group('GoogleSignInUserData', () {
test('can be compared by == operator', () {
final GoogleSignInUserData firstInstance = GoogleSignInUserData(
email: 'email',
id: 'id',
displayName: 'displayName',
photoUrl: 'photoUrl',
idToken: 'idToken',
serverAuthCode: 'serverAuthCode',
);
final GoogleSignInUserData secondInstance = GoogleSignInUserData(
email: 'email',
id: 'id',
displayName: 'displayName',
photoUrl: 'photoUrl',
idToken: 'idToken',
serverAuthCode: 'serverAuthCode',
);
expect(firstInstance == secondInstance, isTrue);
});
});
}

class ImplementsWithIsMock extends Mock implements GoogleSignInPlatform {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 0.2.2+4

* Enables mocking models by changing overridden operator == parameter type from `dynamic` to `Object`.
* Removes unnecessary imports.

## 0.2.2+3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class SkuDetailsWrapper {
final int originalPriceAmountMicros;

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
if (other.runtimeType != runtimeType) {
return false;
}
Expand Down Expand Up @@ -203,7 +203,7 @@ class SkuDetailsResponseWrapper {
final List<SkuDetailsWrapper> skuDetailsList;

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
if (other.runtimeType != runtimeType) {
return false;
}
Expand Down Expand Up @@ -248,7 +248,7 @@ class BillingResultWrapper {
final String? debugMessage;

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
if (other.runtimeType != runtimeType) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: in_app_purchase_android
description: An implementation for the Android platform of the Flutter `in_app_purchase` plugin. This uses the Android BillingClient APIs.
repository: https://github.com/flutter/plugins/tree/main/packages/in_app_purchase/in_app_purchase_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
version: 0.2.2+3
version: 0.2.2+4

environment:
sdk: ">=2.14.0 <3.0.0"
Expand All @@ -28,4 +28,5 @@ dev_dependencies:
flutter_test:
sdk: flutter
json_serializable: ^6.0.0
test: ^1.16.0
mockito: ^5.1.0
test: ^1.16.0
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,60 @@ void main() {
expect(billingResult.debugMessage, kInvalidBillingResultErrorMessage);
expect(billingResult.responseCode, BillingResponse.error);
});

test('operator == of SkuDetailsWrapper works fine', () {
const SkuDetailsWrapper firstSkuDetailsInstance = SkuDetailsWrapper(
description: 'description',
freeTrialPeriod: 'freeTrialPeriod',
introductoryPrice: 'introductoryPrice',
introductoryPriceAmountMicros: 990000,
introductoryPriceCycles: 1,
introductoryPricePeriod: 'introductoryPricePeriod',
price: 'price',
priceAmountMicros: 1000,
priceCurrencyCode: 'priceCurrencyCode',
priceCurrencySymbol: r'$',
sku: 'sku',
subscriptionPeriod: 'subscriptionPeriod',
title: 'title',
type: SkuType.inapp,
originalPrice: 'originalPrice',
originalPriceAmountMicros: 1000,
);
const SkuDetailsWrapper secondSkuDetailsInstance = SkuDetailsWrapper(
description: 'description',
freeTrialPeriod: 'freeTrialPeriod',
introductoryPrice: 'introductoryPrice',
introductoryPriceAmountMicros: 990000,
introductoryPriceCycles: 1,
introductoryPricePeriod: 'introductoryPricePeriod',
price: 'price',
priceAmountMicros: 1000,
priceCurrencyCode: 'priceCurrencyCode',
priceCurrencySymbol: r'$',
sku: 'sku',
subscriptionPeriod: 'subscriptionPeriod',
title: 'title',
type: SkuType.inapp,
originalPrice: 'originalPrice',
originalPriceAmountMicros: 1000,
);
expect(firstSkuDetailsInstance == secondSkuDetailsInstance, isTrue);
});

test('operator == of BillingResultWrapper works fine', () {
const BillingResultWrapper firstBillingResultInstance =
BillingResultWrapper(
responseCode: BillingResponse.ok,
debugMessage: 'debugMessage',
);
const BillingResultWrapper secondBillingResultInstance =
BillingResultWrapper(
responseCode: BillingResponse.ok,
debugMessage: 'debugMessage',
);
expect(firstBillingResultInstance == secondBillingResultInstance, isTrue);
});
});
}

Expand Down