-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix cancel listener being called twice when PayPal is canceled with b…
…ack button Fixes #112
- Loading branch information
Showing
3 changed files
with
56 additions
and
8 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
Braintree/src/androidTest/java/com/braintreepayments/api/PayPalTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.braintreepayments.api; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import com.braintreepayments.api.models.Configuration; | ||
import com.braintreepayments.api.models.PayPalRequest; | ||
import com.braintreepayments.api.test.TestActivity; | ||
import com.braintreepayments.testutils.BraintreeActivityTestRule; | ||
import com.braintreepayments.testutils.TestConfigurationBuilder; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.invocation.InvocationOnMock; | ||
import org.mockito.stubbing.Answer; | ||
|
||
import static com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragment; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.doAnswer; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class PayPalTest { | ||
|
||
@Rule | ||
public final BraintreeActivityTestRule<TestActivity> mActivityTestRule = | ||
new BraintreeActivityTestRule<>(TestActivity.class); | ||
|
||
@Test | ||
public void authorizeAccount_onBackPressed_callsCancelListenerOnlyOnce() { | ||
Configuration configuration = new TestConfigurationBuilder() | ||
.paypalEnabled(true) | ||
.buildConfiguration(); | ||
|
||
final BraintreeFragment fragment = getMockFragment(mActivityTestRule.getActivity(), configuration); | ||
doAnswer(new Answer() { | ||
@Override | ||
public Object answer(InvocationOnMock invocation) throws Throwable { | ||
fragment.onActivityResult(PayPal.PAYPAL_REQUEST_CODE, Activity.RESULT_CANCELED, new Intent()); | ||
return null; | ||
} | ||
}).when(fragment).startActivity(any(Intent.class)); | ||
|
||
PayPal.authorizeAccount(fragment); | ||
|
||
verify(fragment, times(1)).postCancelCallback(PayPal.PAYPAL_REQUEST_CODE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters