Search in sources :

Example 1 with ContextInspector

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

the class TestSetupHelper method getMockContextInspector.

public static ContextInspector getMockContextInspector() throws NameNotFoundException {
    ApplicationInfo applicationInfoMock = mock(ApplicationInfo.class);
    when(applicationInfoMock.loadLabel(any(PackageManager.class))).thenReturn("application-name");
    ApplicationInfo applicationInfo = new ApplicationInfo();
    applicationInfo.packageName = "com.test";
    PackageInfo packageInfo = new PackageInfo();
    packageInfo.applicationInfo = applicationInfoMock;
    ActivityInfo activityInfo = new ActivityInfo();
    activityInfo.name = "Browser";
    activityInfo.applicationInfo = applicationInfo;
    ResolveInfo resolveInfo = new ResolveInfo();
    resolveInfo.activityInfo = activityInfo;
    PackageManager packageManager = mock(PackageManager.class);
    when(packageManager.getPackageInfo(anyString(), anyInt())).thenReturn(packageInfo);
    when(packageManager.resolveActivity(any(Intent.class), eq(PackageManager.MATCH_DEFAULT_ONLY))).thenReturn(resolveInfo);
    TelephonyManager telephonyManager = mock(TelephonyManager.class);
    when(telephonyManager.getSimOperator()).thenReturn("12345");
    Context context = spy(RuntimeEnvironment.application);
    when(context.getPackageManager()).thenReturn(packageManager);
    when(context.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(telephonyManager);
    ContextInspector contextInspector = mock(ContextInspector.class);
    when(contextInspector.getContext()).thenReturn(context);
    RuntimeEnvironment.application.getSharedPreferences("PayPalOTC", Context.MODE_PRIVATE).edit().putString("InstallationGUID", "installation-guid").apply();
    return contextInspector;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) Context(android.content.Context) ActivityInfo(android.content.pm.ActivityInfo) ContextInspector(com.paypal.android.sdk.onetouch.core.base.ContextInspector) PackageManager(android.content.pm.PackageManager) TelephonyManager(android.telephony.TelephonyManager) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent)

Example 2 with ContextInspector

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

the class FptiManagerUnitTest method setup.

@Before
public void setup() throws NameNotFoundException {
    ContextInspector contextInspector = getMockContextInspector();
    PayPalHttpClient httpClient = mock(PayPalHttpClient.class);
    mFptiManager = spy(new FptiManager(contextInspector, httpClient));
}
Also used : ContextInspector(com.paypal.android.sdk.onetouch.core.base.ContextInspector) TestSetupHelper.getMockContextInspector(com.paypal.android.sdk.onetouch.core.test.TestSetupHelper.getMockContextInspector) PayPalHttpClient(com.paypal.android.sdk.onetouch.core.network.PayPalHttpClient) Before(org.junit.Before)

Aggregations

ContextInspector (com.paypal.android.sdk.onetouch.core.base.ContextInspector)2 Context (android.content.Context)1 Intent (android.content.Intent)1 ActivityInfo (android.content.pm.ActivityInfo)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 TelephonyManager (android.telephony.TelephonyManager)1 PayPalHttpClient (com.paypal.android.sdk.onetouch.core.network.PayPalHttpClient)1 TestSetupHelper.getMockContextInspector (com.paypal.android.sdk.onetouch.core.test.TestSetupHelper.getMockContextInspector)1 Before (org.junit.Before)1