Search in sources :

Example 11 with Result

use of com.paypal.android.sdk.onetouch.core.Result in project braintree_android by braintree.

the class AppSwitchHelperUnitTest method parseAppSwitchResponse_parsesAuthorizationCodeResponseAndReturnsResult.

@Test
public void parseAppSwitchResponse_parsesAuthorizationCodeResponseAndReturnsResult() throws JSONException {
    Request request = mock(AuthorizationRequest.class);
    when(request.validateV1V2Response(any(ContextInspector.class), any(Bundle.class))).thenReturn(true);
    Intent intent = new Intent().putExtra("environment", "test").putExtra("response_type", "code").putExtra("authorization_code", "auth-code").putExtra("email", "test@paypal.com");
    Result result = AppSwitchHelper.parseAppSwitchResponse(mContextInspector, request, intent);
    verify(request).trackFpti(any(Context.class), eq(TrackingPoint.Return), isNull(Protocol.class));
    assertEquals(ResultType.Success, result.getResultType());
    assertEquals(ResponseType.authorization_code.name(), result.getResponse().getString("response_type"));
    JSONObject client = result.getResponse().getJSONObject("client");
    assertEquals("test", client.getString("environment"));
    assertEquals("auth-code", result.getResponse().getJSONObject("response").getString("code"));
    assertEquals("test@paypal.com", result.getResponse().getJSONObject("user").getString("display_string"));
}
Also used : Context(android.content.Context) ContextInspector(com.paypal.android.sdk.onetouch.core.base.ContextInspector) TestSetupHelper.getMockContextInspector(com.paypal.android.sdk.onetouch.core.test.TestSetupHelper.getMockContextInspector) JSONObject(org.json.JSONObject) Bundle(android.os.Bundle) Request(com.paypal.android.sdk.onetouch.core.Request) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) Intent(android.content.Intent) Protocol(com.paypal.android.sdk.onetouch.core.enums.Protocol) Result(com.paypal.android.sdk.onetouch.core.Result) Test(org.junit.Test)

Aggregations

Result (com.paypal.android.sdk.onetouch.core.Result)11 CheckoutRequest (com.paypal.android.sdk.onetouch.core.CheckoutRequest)10 ContextInspector (com.paypal.android.sdk.onetouch.core.base.ContextInspector)9 TestSetupHelper.getMockContextInspector (com.paypal.android.sdk.onetouch.core.test.TestSetupHelper.getMockContextInspector)9 Test (org.junit.Test)9 Context (android.content.Context)8 Protocol (com.paypal.android.sdk.onetouch.core.enums.Protocol)8 AuthorizationRequest (com.paypal.android.sdk.onetouch.core.AuthorizationRequest)6 Request (com.paypal.android.sdk.onetouch.core.Request)6 Intent (android.content.Intent)5 Bundle (android.os.Bundle)5 Uri (android.net.Uri)4 JSONObject (org.json.JSONObject)4 WalletSwitchException (com.paypal.android.sdk.onetouch.core.exception.WalletSwitchException)3 ResponseParsingException (com.paypal.android.sdk.onetouch.core.exception.ResponseParsingException)2 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 BrowserSwitchException (com.braintreepayments.api.exceptions.BrowserSwitchException)1 PayPalRequest (com.braintreepayments.api.models.PayPalRequest)1 BillingAgreementRequest (com.paypal.android.sdk.onetouch.core.BillingAgreementRequest)1 ResponseType (com.paypal.android.sdk.onetouch.core.enums.ResponseType)1