package com.braintreepayments.cardform.test;

import android.app.KeyguardManager;
import android.content.Context;
import android.content.Intent;
import android.test.ActivityInstrumentationTestCase2;

public class TestActivityTestCase extends ActivityInstrumentationTestCase2<TestActivity> {

    protected Context mContext;
    protected TestActivity mActivity;

    public TestActivityTestCase() {
        super(TestActivity.class);
    }

    @SuppressWarnings("deprecation")
    @Override
    public void setUp() throws Exception {
        ((KeyguardManager) getInstrumentation().getContext().getSystemService(Context.KEYGUARD_SERVICE))
                .newKeyguardLock("TestActivity").disableKeyguard();

        mContext = getInstrumentation().getContext();
    }

    public void setupCardForm() {
        setupCardForm(true, true, true, true);
    }

    public void setupCardForm(boolean cardNumberRequired, boolean expirationRequired,
            boolean cvvRequired, boolean postalCodeRequired) {
        Intent intent = new Intent(mContext, TestActivity.class)
                .putExtra(TestActivity.SETUP_FORM, true)
                .putExtra(TestActivity.CREDIT_CARD, cardNumberRequired)
                .putExtra(TestActivity.EXPIRATION, expirationRequired)
                .putExtra(TestActivity.CVV, cvvRequired)
                .putExtra(TestActivity.POSTAL_CODE, postalCodeRequired);
        setActivityIntent(intent);
        mActivity = getActivity();
    }
}

@@ -138,16 +138,47 @@
 Intent;%0A
+import android.os.SystemClock;%0A
 import a
@@ -1461,16 +1461,17 @@
 ntent);%0A
+%0A
         
@@ -1496,16 +1496,117 @@
 ivity();
+%0A%0A        // prevent flaky tests on CI when activity is slow to start%0A        SystemClock.sleep(250);
 %0A    %7D%0A%7D

Improve test reliability