package com.braintreepayments.api.internal;

import android.os.SystemClock;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import android.util.Log;

import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.InstrumentationRegistry.getTargetContext;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class SignatureVerificationTest {

    @Test(timeout = 15000)
    public void isSignatureValid_returnsFalseWhenAppNotInstalled() {
        Log.d("request_command", "uninstall paypal wallet");
        SystemClock.sleep(10000);

        assertFalse(checkSignature());
    }

    @Test(timeout = 65000)
    public void isSignatureValid_returnsTrueWhenAppIsInstalled() {
        Log.d("request_command", "install paypal wallet");
        SystemClock.sleep(60000);

        assertTrue(checkSignature());
    }

    private boolean checkSignature() {
        return SignatureVerification.isSignatureValid(getTargetContext(),
                "com.paypal.android.p2pmobile", "O=Paypal", "O=Paypal", 34172764);
    }
}

@@ -38,16 +38,122 @@
 ernal;%0A%0A
+import android.content.pm.PackageManager;%0Aimport android.content.pm.PackageManager.NameNotFoundException;%0A
 import a
@@ -647,10 +647,10 @@
 t = 
-15
+20
 000)
@@ -807,20 +807,59 @@
 .sleep(1
+5
 000
-0
+);%0A        assertFalse(isAppInstalled()
 );%0A%0A    
@@ -920,17 +920,17 @@
 meout = 
-6
+8
 5000)%0A  
@@ -1083,54 +1083,419 @@
 eep(
-6
+8
 0000);%0A
-%0A        assertTrue(checkSignature());
+        assertTrue(isAppInstalled());%0A%0A        assertTrue(checkSignature());%0A    %7D%0A%0A    private boolean isAppInstalled() %7B%0A        PackageManager pm = getTargetContext().getPackageManager();%0A        try %7B%0A            pm.getPackageInfo(%22com.paypal.android.p2pmobile%22, PackageManager.GET_ACTIVITIES);%0A            return true;%0A        %7D catch (NameNotFoundException e) %7B%0A            return false;%0A        %7D
 %0A   

Increase signature verification test timeout