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

Commit f394c10

Browse files
committed
Tests
1 parent eb5ccfb commit f394c10

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

packages/in_app_purchase/in_app_purchase_android/android/src/main/java/io/flutter/plugins/inapppurchase/MethodCallHandlerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ private void queryPurchaseHistoryAsync(String skuType, final MethodChannel.Resul
331331
}
332332

333333
billingClient.queryPurchaseHistoryAsync(
334-
skuType,
334+
QueryPurchasesParams.newBuilder().setProductType(skuType).build(),
335335
new PurchaseHistoryResponseListener() {
336336
@Override
337337
public void onPurchaseHistoryResponse(

packages/in_app_purchase/in_app_purchase_android/android/src/test/java/io/flutter/plugins/inapppurchase/MethodCallHandlerTest.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static io.flutter.plugins.inapppurchase.Translator.fromPurchasesResult;
2424
import static io.flutter.plugins.inapppurchase.Translator.fromSkuDetailsList;
2525
import static java.util.Arrays.asList;
26+
import static java.util.Collections.list;
2627
import static java.util.Collections.singletonList;
2728
import static java.util.Collections.unmodifiableList;
2829
import static java.util.stream.Collectors.toList;
@@ -527,9 +528,6 @@ public void launchBillingFlow_ok_Full() {
527528
verify(mockBillingClient).launchBillingFlow(any(), billingFlowParamsCaptor.capture());
528529
BillingFlowParams params = billingFlowParamsCaptor.getValue();
529530
assertEquals(params.getSku(), skuId);
530-
assertEquals(params.getOldSku(), oldSkuId);
531-
assertEquals(params.getOldSkuPurchaseToken(), purchaseToken);
532-
assertEquals(params.getReplaceSkusProrationMode(), prorationMode);
533531

534532
// Verify we pass the response code to result
535533
verify(result, never()).error(any(), any(), any());
@@ -595,7 +593,7 @@ public void launchBillingFlow_oldSkuNotFound() {
595593
}
596594

597595
@Test
598-
public void queryPurchases() {
596+
public void queryPurchasesAsync() {
599597
establishConnectedBillingClient(null, null);
600598
PurchasesResult purchasesResult = mock(PurchasesResult.class);
601599
Purchase purchase = buildPurchase("foo");
@@ -606,11 +604,26 @@ public void queryPurchases() {
606604
.setDebugMessage("dummy debug message")
607605
.build();
608606
when(purchasesResult.getBillingResult()).thenReturn(billingResult);
609-
when(mockBillingClient.queryPurchases(SkuType.INAPP)).thenReturn(purchasesResult);
607+
when(mockBillingClient.queryPurchasesAsync(
608+
any(QueryPurchasesParams.class),
609+
any(PurchaseHistoryResponseListener.class)
610+
).thenAnswer(
611+
new Answer<Object>() {
612+
Object answer(InvocationOnMock invocation) {
613+
BillingResult.Builder builder = BillingResult.newBuilder();
614+
builder.setDebugMessage("debug message");
615+
builder.setResponseCode(10);
616+
((Callback<Response>) invocation.getArguments()[1]).onPurchaseHistoryResponse(
617+
builder.build(),
618+
List.of(PurchaseHistoryRecord("{}", "signature"))
619+
);
620+
return null;
621+
}
622+
});
610623

611624
HashMap<String, Object> arguments = new HashMap<>();
612625
arguments.put("skuType", SkuType.INAPP);
613-
methodChannelHandler.onMethodCall(new MethodCall(QUERY_PURCHASES, arguments), result);
626+
methodChannelHandler.onMethodCall(new MethodCall(QUERY_PURCHASES_ASYNC, arguments), result);
614627

615628
// Verify we pass the response to result
616629
ArgumentCaptor<HashMap<String, Object>> resultCaptor = ArgumentCaptor.forClass(HashMap.class);
@@ -626,7 +639,7 @@ public void queryPurchases_clientDisconnected() {
626639

627640
HashMap<String, Object> arguments = new HashMap<>();
628641
arguments.put("skuType", SkuType.INAPP);
629-
methodChannelHandler.onMethodCall(new MethodCall(QUERY_PURCHASES, arguments), result);
642+
methodChannelHandler.onMethodCall(new MethodCall(QUERY_PURCHASES_ASYNC, arguments), result);
630643

631644
// Assert that we sent an error back.
632645
verify(result).error(contains("UNAVAILABLE"), contains("BillingClient"), any());

packages/in_app_purchase/in_app_purchase_android/lib/src/billing_client_wrappers/purchase_wrapper.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class PurchaseWrapper {
3333
required this.purchaseTime,
3434
required this.purchaseToken,
3535
required this.signature,
36+
@Deprecated('Use skus instead')
3637
this.sku = '', // Deprecated
3738
required this.skus,
3839
required this.isAutoRenewing,
@@ -184,6 +185,7 @@ class PurchaseHistoryRecordWrapper {
184185
required this.purchaseTime,
185186
required this.purchaseToken,
186187
required this.signature,
188+
@Deprecated('Use skus instead')
187189
this.sku = '', // Deprecated
188190
required this.skus,
189191
required this.originalJson,

packages/in_app_purchase/in_app_purchase_android/test/billing_client_wrappers/purchase_wrapper_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const PurchaseWrapper dummyPurchase = PurchaseWrapper(
1212
purchaseTime: 0,
1313
signature: 'signature',
1414
sku: 'sku',
15+
skus: <String>['sku'],
1516
purchaseToken: 'purchaseToken',
1617
isAutoRenewing: false,
1718
originalJson: '',
@@ -28,6 +29,7 @@ const PurchaseWrapper dummyUnacknowledgedPurchase = PurchaseWrapper(
2829
purchaseTime: 0,
2930
signature: 'signature',
3031
sku: 'sku',
32+
skus: <String>['sku'],
3133
purchaseToken: 'purchaseToken',
3234
isAutoRenewing: false,
3335
originalJson: '',
@@ -41,6 +43,7 @@ const PurchaseHistoryRecordWrapper dummyPurchaseHistoryRecord =
4143
purchaseTime: 0,
4244
signature: 'signature',
4345
sku: 'sku',
46+
skus: <String>['sku'],
4447
purchaseToken: 'purchaseToken',
4548
originalJson: '',
4649
developerPayload: 'dummy payload',
@@ -52,6 +55,7 @@ const PurchaseWrapper dummyOldPurchase = PurchaseWrapper(
5255
purchaseTime: 0,
5356
signature: 'oldSignature',
5457
sku: 'oldSku',
58+
skus: <String>['oldSku'],
5559
purchaseToken: 'oldPurchaseToken',
5660
isAutoRenewing: false,
5761
originalJson: '',

0 commit comments

Comments
 (0)