Skip to content

Commit

Permalink
Remove Powermock (#731)
Browse files Browse the repository at this point in the history
* Remove powermock legacy build.gradle variables.

* Remove powermock dependency from GooglePlay unit tests.

* Remove powermock dependency from AmericanExpress unit tests.

* Remove powermock dependency from PayPalDataCollector unit tests.

* Remove powermock test dependency from BraintreeCore unit tests.

* Remove powermock dependency from BraintreeDataCollector.

* Remove power mock dependency from sepa direct debit.

* Remove powermock from Card module test dependencies.

* Remove powermock from Local Payment module test dependencies.

* Remove power mock from paypal module unit tests.

* Remove powermock dependency from SamsungPay module unit tests.

* Remove powermock dependency from Venmo module unit tests.

* Remove powermock dependency from UnionPay module unit tests.

* Remove powermock from TestUtils module compile only dependencies.

* Update mockito version to latest and migrate shared utils away from power mock.

* Migrate MockBraintreeClientBuilder to updated mockito matchers.

* Fix AmericanExpress module mockito upgrade build errors.

* Fix Card module mockito upgrade errors.

* Fix GooglePayClient mockito upgrade errors.

* Fix LocalPayment mockito upgrade errors.

* Fix PayPal module mockito upgrade errors.

* Fix UnionPay mockito upgrade issues.

* Fix Venmo mockito upgrade errors.

* Update broken mockito imports in PayPalNativeCheckout.

* Modify ThreeDSecure module to use mockito core instead of powermock.

* Refactor PayPalNativeCheckoutClientUnitTest to use mockk.

* Remove power mock from paypal native checkout module.

* Migrate VisaCheckoutAccountUnitTest to Kotlin and mockk.

* Refactor VisaCheckoutClient to no longer use powermock.

* Remove powermock dependency from visa checkout module.

* Remove mention of powermock from build.gradle.

* Remove Google Pay duct tape for mockito unit test.

* Port CardinalClient updated unit tests.

* Remove unused stub.
  • Loading branch information
sshropshire authored May 30, 2023
1 parent e139d80 commit 87a71a0
Show file tree
Hide file tree
Showing 58 changed files with 1,160 additions and 1,288 deletions.
1 change: 0 additions & 1 deletion ACKNOWLEDGEMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ The Braintree SDK uses code from the following libraries:
* [leakcanary](https://github.com/square/leakcanary), Apache License Version 2.0
* [mailable-log](https://github.com/lkorth/mailable-log), MIT License
* [Mockito](https://github.com/mockito/mockito), MIT License
* [PowerMock](https://github.com/jayway/powermock), Apache License Version 2.0
* [Retrofit](https://github.com/square/retrofit), Apache License Version 2.0
* [Robolectric](https://github.com/robolectric/robolectric), MIT License
* [SDK Manager Plugin](https://github.com/JakeWharton/sdk-manager-plugin), Apache License Version 2.0
Expand Down
5 changes: 1 addition & 4 deletions AmericanExpress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ dependencies {
implementation deps.annotation

testImplementation deps.robolectric
testImplementation deps.powermockJunit
testImplementation deps.powermockRule
testImplementation deps.powermockMockito
testImplementation deps.powermockClassloading
testImplementation deps.mockitoCore
testImplementation deps.jsonAssert
testImplementation project(':TestUtils')
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.braintreepayments.api;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.robolectric.RobolectricTestRunner;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.isNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.robolectric.RobolectricTestRunner;

@RunWith(RobolectricTestRunner.class)
public class AmericanExpressClientUnitTest {

Expand Down Expand Up @@ -73,7 +73,7 @@ public void getRewardsBalance_callsListenerWithRewardsBalanceWithErrorCode_OnIne

ArgumentCaptor<AmericanExpressRewardsBalance> amexRewardsCaptor =
ArgumentCaptor.forClass(AmericanExpressRewardsBalance.class);
verify(amexRewardsCallback).onResult(amexRewardsCaptor.capture(), (Exception) isNull());
verify(amexRewardsCallback).onResult(amexRewardsCaptor.capture(), isNull());

AmericanExpressRewardsBalance rewardsBalance = amexRewardsCaptor.getValue();
assertNotNull(rewardsBalance);
Expand Down
1 change: 1 addition & 0 deletions BraintreeCore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ dependencies {
testImplementation deps.robolectric
testImplementation deps.androidxTestCore
testImplementation deps.junitTest
testImplementation deps.mockitoCore
testImplementation deps.jsonAssert
testImplementation deps.mockk
testImplementation project(':PayPal')
Expand Down
5 changes: 1 addition & 4 deletions BraintreeDataCollector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ dependencies {
testImplementation deps.mockitoCore
testImplementation deps.androidxTestCore
testImplementation deps.jsonAssert
testImplementation deps.powermockJunit
testImplementation deps.powermockRule
testImplementation deps.powermockMockito
testImplementation deps.powermockClassloading
testImplementation deps.mockitoCore

testImplementation project(':TestUtils')

Expand Down
5 changes: 1 addition & 4 deletions Card/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ dependencies {
implementation deps.annotation

testImplementation deps.robolectric
testImplementation deps.powermockJunit
testImplementation deps.powermockRule
testImplementation deps.powermockMockito
testImplementation deps.powermockClassloading
testImplementation deps.mockitoCore
testImplementation deps.jsonAssert
testImplementation project(':TestUtils')
testImplementation project(':ThreeDSecure')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package com.braintreepayments.api;

import static junit.framework.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;

import org.json.JSONException;
Expand All @@ -12,14 +20,6 @@
import org.mockito.Mockito;
import org.robolectric.RobolectricTestRunner;

import static junit.framework.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(RobolectricTestRunner.class)
public class CardClientUnitTest {

Expand Down Expand Up @@ -76,7 +76,7 @@ public void tokenize_whenGraphQLEnabled_tokenizesWithGraphQL() throws JSONExcept
sut.tokenize(card, cardTokenizeCallback);

ArgumentCaptor<CardNonce> captor = ArgumentCaptor.forClass(CardNonce.class);
verify(cardTokenizeCallback).onResult(captor.capture(), (Exception) isNull());
verify(cardTokenizeCallback).onResult(captor.capture(), isNull());

CardNonce cardNonce = captor.getValue();
assertEquals("3744a73e-b1ab-0dbd-85f0-c12a0a4bd3d1", cardNonce.getString());
Expand Down
5 changes: 1 addition & 4 deletions GooglePay/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ dependencies {
testImplementation deps.androidxTestRules
testImplementation deps.androidxTestRunner
testImplementation deps.playServicesWallet
testImplementation deps.powermockJunit
testImplementation deps.powermockRule
testImplementation deps.powermockMockito
testImplementation deps.powermockClassloading
testImplementation deps.mockitoCore
testImplementation deps.robolectric
testImplementation deps.jsonAssert
testImplementation deps.coreKtx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
Expand Down Expand Up @@ -1222,7 +1222,7 @@ public void tokenize_withCardToken_returnsGooglePayNonce() {
sut.tokenize(pd, activityResultCallback);

ArgumentCaptor<PaymentMethodNonce> captor = ArgumentCaptor.forClass(PaymentMethodNonce.class);
verify(activityResultCallback).onResult(captor.capture(), (Exception) isNull());
verify(activityResultCallback).onResult(captor.capture(), isNull());

assertTrue(captor.getValue() instanceof GooglePayCardNonce);
}
Expand Down
5 changes: 1 addition & 4 deletions LocalPayment/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ dependencies {
implementation project(':PayPalDataCollector')

testImplementation deps.robolectric
testImplementation deps.powermockJunit
testImplementation deps.powermockRule
testImplementation deps.powermockMockito
testImplementation deps.powermockClassloading
testImplementation deps.mockitoCore
testImplementation deps.jsonAssert
testImplementation project(':TestUtils')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.assertSame;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Matchers.same;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
Expand Down Expand Up @@ -273,7 +273,7 @@ public void startPayment_whenPayPalDisabled_returnsErrorToCallback() {
sut.startPayment(request, localPaymentStartCallback);

ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
verify(localPaymentStartCallback).onResult((LocalPaymentResult) isNull(), captor.capture());
verify(localPaymentStartCallback).onResult(isNull(), captor.capture());

Exception exception = captor.getValue();
assertTrue(exception instanceof ConfigurationException);
Expand All @@ -289,7 +289,7 @@ public void startPayment_whenAmountIsNull_returnsErrorToCallback() {
sut.startPayment(request, localPaymentStartCallback);

ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
verify(localPaymentStartCallback).onResult((LocalPaymentResult) isNull(), captor.capture());
verify(localPaymentStartCallback).onResult(isNull(), captor.capture());

Exception exception = captor.getValue();
assertTrue(exception instanceof BraintreeException);
Expand All @@ -305,7 +305,7 @@ public void startPayment_whenPaymentTypeIsNull_returnsErrorToCallback() {
sut.startPayment(request, localPaymentStartCallback);

ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
verify(localPaymentStartCallback).onResult((LocalPaymentResult) isNull(), captor.capture());
verify(localPaymentStartCallback).onResult(isNull(), captor.capture());

Exception exception = captor.getValue();
assertTrue(exception instanceof BraintreeException);
Expand All @@ -319,7 +319,7 @@ public void startPayment_whenLocalPaymentRequestIsNull_returnsErrorToCallback()
sut.startPayment(null, localPaymentStartCallback);

ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
verify(localPaymentStartCallback).onResult((LocalPaymentResult) isNull(), captor.capture());
verify(localPaymentStartCallback).onResult(isNull(), captor.capture());

Exception exception = captor.getValue();
assertTrue(exception instanceof BraintreeException);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.braintreepayments.api;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;

Expand Down
5 changes: 1 addition & 4 deletions PayPal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ dependencies {
implementation project(':PayPalDataCollector')

testImplementation deps.robolectric
testImplementation deps.powermockJunit
testImplementation deps.powermockRule
testImplementation deps.powermockMockito
testImplementation deps.powermockClassloading
testImplementation deps.mockitoCore
testImplementation deps.jsonAssert
testImplementation deps.mockitoCore
testImplementation project(':TestUtils')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.braintreepayments.api;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;

import android.content.Context;

import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;

public class MockPayPalInternalClientBuilder {

private Exception error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.assertSame;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.same;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -425,7 +425,7 @@ public void sendRequest_whenRiskCorrelationIdNotNull_setsClientMetadataIdToRiskC
sut.sendRequest(context, payPalRequest, payPalInternalClientCallback);

ArgumentCaptor<PayPalResponse> captor = ArgumentCaptor.forClass(PayPalResponse.class);
verify(payPalInternalClientCallback).onResult(captor.capture(), (Exception) isNull());
verify(payPalInternalClientCallback).onResult(captor.capture(), isNull());

PayPalResponse payPalResponse = captor.getValue();
assertEquals("risk-correlation-id", payPalResponse.getClientMetadataId());
Expand Down
5 changes: 1 addition & 4 deletions PayPalDataCollector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ dependencies {
testImplementation deps.mockitoCore
testImplementation deps.androidxTestCore
testImplementation deps.jsonAssert
testImplementation deps.powermockJunit
testImplementation deps.powermockRule
testImplementation deps.powermockMockito
testImplementation deps.powermockClassloading
testImplementation deps.mockitoCore

testImplementation project(':TestUtils')

Expand Down
5 changes: 1 addition & 4 deletions PayPalNativeCheckout/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ dependencies {
}

testImplementation deps.robolectric
testImplementation deps.powermockJunit
testImplementation deps.powermockRule
testImplementation deps.powermockMockito
testImplementation deps.powermockClassloading
testImplementation deps.jsonAssert
testImplementation deps.mockk
testImplementation deps.mockitoCore
testImplementation project(':TestUtils')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Context;
import android.net.Uri;

import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import org.json.JSONException;
Expand All @@ -20,10 +19,6 @@ class PayPalNativeCheckoutInternalClient {
private final String cancelUrl;
private final String successUrl;

interface PayPalNativeCheckoutInternalClientCallback {
void onResult(@Nullable PayPalNativeCheckoutResponse payPalResponse, @Nullable Exception error);
}

PayPalNativeCheckoutInternalClient(BraintreeClient braintreeClient) {
this(braintreeClient, new PayPalDataCollector(braintreeClient), new ApiClient(braintreeClient));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.braintreepayments.api;

import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;

/**
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public interface PayPalNativeCheckoutInternalClientCallback {
void onResult(@Nullable PayPalNativeCheckoutResponse payPalResponse, @Nullable Exception error);
}
Loading

0 comments on commit 87a71a0

Please sign in to comment.