Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahkoop committed Dec 19, 2023
1 parent 6c4f6dc commit 63c40d7
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.android.gms.wallet.IsReadyToPayRequest;
import com.google.android.gms.wallet.PaymentData;
import com.google.android.gms.wallet.PaymentDataRequest;
import com.google.android.gms.wallet.PaymentMethodTokenizationParameters;
import com.google.android.gms.wallet.ShippingAddressRequirements;
import com.google.android.gms.wallet.TransactionInfo;
import com.google.android.gms.wallet.WalletConstants;
Expand Down Expand Up @@ -454,8 +453,8 @@ public void createPaymentAuthRequest_sendsAnalyticsEvent() {
sut.createPaymentAuthRequest(googlePayRequest, intentDataCallback);

InOrder order = inOrder(braintreeClient);
order.verify(braintreeClient).sendAnalyticsEvent(eq("google-payment.selected"));
order.verify(braintreeClient).sendAnalyticsEvent(eq("google-payment.started"));
order.verify(braintreeClient).sendAnalyticsEvent(eq(GooglePayAnalytics.PAYMENT_REQUEST_STARTED));
order.verify(braintreeClient).sendAnalyticsEvent(eq(GooglePayAnalytics.PAYMENT_REQUEST_SUCCEEDED));
}

@Test
Expand Down Expand Up @@ -484,8 +483,8 @@ public void createPaymentAuthRequest_postsExceptionWhenTransactionInfoIsNull() {
sut.createPaymentAuthRequest(googlePayRequest, intentDataCallback);

InOrder order = inOrder(braintreeClient);
order.verify(braintreeClient).sendAnalyticsEvent(eq("google-payment.selected"));
order.verify(braintreeClient).sendAnalyticsEvent(eq("google-payment.failed"));
order.verify(braintreeClient).sendAnalyticsEvent(eq(GooglePayAnalytics.PAYMENT_REQUEST_STARTED));
order.verify(braintreeClient).sendAnalyticsEvent(eq(GooglePayAnalytics.PAYMENT_REQUEST_FAILED));
}

@Test
Expand Down Expand Up @@ -516,6 +515,7 @@ public void createPaymentAuthRequest_whenMerchantNotConfigured_returnsExceptionT
assertEquals(
"Google Pay is not enabled for your Braintree account, or Google Play Services are not configured correctly.",
exception.getMessage());
verify(braintreeClient).sendAnalyticsEvent(GooglePayAnalytics.PAYMENT_REQUEST_FAILED);
}

@Test
Expand Down Expand Up @@ -976,6 +976,7 @@ public void createPaymentAuthRequest_whenRequestIsNull_forwardsExceptionToListen
Exception exception = ((GooglePayPaymentAuthRequest.Failure) request).getError();
assertTrue(exception instanceof BraintreeException);
assertEquals("Cannot pass null GooglePayRequest to requestPayment", exception.getMessage());
verify(braintreeClient).sendAnalyticsEvent(GooglePayAnalytics.PAYMENT_REQUEST_FAILED);
}

@Test
Expand Down Expand Up @@ -1013,6 +1014,7 @@ public void createPaymentAuthRequest_whenManifestInvalid_forwardsExceptionToList
assertEquals("GooglePayActivity was not found in the Android " +
"manifest, or did not have a theme of R.style.bt_transparent_activity",
exception.getMessage());
verify(braintreeClient).sendAnalyticsEvent(GooglePayAnalytics.PAYMENT_REQUEST_FAILED);
}

// endregion
Expand Down Expand Up @@ -1113,7 +1115,6 @@ public void tokenize_whenPaymentDataExists_returnsResultToListener_andSendsAnaly
googlePayPaymentAuthResult = new GooglePayPaymentAuthResult(paymentData, null);
sut.tokenize(googlePayPaymentAuthResult, activityResultCallback);

verify(braintreeClient).sendAnalyticsEvent(eq("google-payment.authorized"));
ArgumentCaptor<GooglePayResult> captor =
ArgumentCaptor.forClass(GooglePayResult.class);
verify(activityResultCallback).onGooglePayResult(captor.capture());
Expand All @@ -1123,6 +1124,8 @@ public void tokenize_whenPaymentDataExists_returnsResultToListener_andSendsAnaly
PaymentMethodNonce nonce = ((GooglePayResult.Success) result).getNonce();
PaymentMethodNonce expectedNonce = GooglePayCardNonce.fromJSON(new JSONObject(paymentDataJson));
assertEquals(nonce.getString(), expectedNonce.getString());
verify(braintreeClient).sendAnalyticsEvent(GooglePayAnalytics.TOKENIZE_STARTED);
verify(braintreeClient).sendAnalyticsEvent(GooglePayAnalytics.TOKENIZE_SUCCEEDED);
}

@Test
Expand All @@ -1138,14 +1141,14 @@ public void tokenize_whenErrorExists_returnsErrorToListener_andSendsAnalytics()
googlePayPaymentAuthResult = new GooglePayPaymentAuthResult(null, error);
sut.tokenize(googlePayPaymentAuthResult, activityResultCallback);

verify(braintreeClient).sendAnalyticsEvent(eq("google-payment.failed"));

ArgumentCaptor<GooglePayResult> captor = ArgumentCaptor.forClass(GooglePayResult.class);
verify(activityResultCallback).onGooglePayResult(captor.capture());

GooglePayResult result = captor.getValue();
assertTrue(result instanceof GooglePayResult.Failure);
assertEquals(error, ((GooglePayResult.Failure) result).getError());
verify(braintreeClient).sendAnalyticsEvent(GooglePayAnalytics.TOKENIZE_STARTED);
verify(braintreeClient).sendAnalyticsEvent(GooglePayAnalytics.TOKENIZE_FAILED);
}

@Test
Expand All @@ -1162,13 +1165,13 @@ public void tokenize_whenUserCanceledErrorExists_returnsErrorToListener_andSends
googlePayPaymentAuthResult = new GooglePayPaymentAuthResult(null, userCanceledError);
sut.tokenize(googlePayPaymentAuthResult, activityResultCallback);

verify(braintreeClient).sendAnalyticsEvent(eq("google-payment.canceled"));

ArgumentCaptor<GooglePayResult> captor = ArgumentCaptor.forClass(GooglePayResult.class);
verify(activityResultCallback).onGooglePayResult(captor.capture());

GooglePayResult result = captor.getValue();
assertTrue(result instanceof GooglePayResult.Cancel);
verify(braintreeClient).sendAnalyticsEvent(GooglePayAnalytics.TOKENIZE_STARTED);
verify(braintreeClient).sendAnalyticsEvent(GooglePayAnalytics.PAYMENT_SHEET_CANCELED);
}

// endregion
Expand Down

0 comments on commit 63c40d7

Please sign in to comment.