package com.braintreepayments.demo.test;

import android.widget.EditText;

import androidx.preference.PreferenceManager;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject;
import androidx.test.uiautomator.UiObjectNotFoundException;
import androidx.test.uiautomator.UiSelector;

import com.braintreepayments.demo.test.utilities.TestHelper;

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

import java.io.IOException;

import static androidx.test.InstrumentationRegistry.getInstrumentation;
import static androidx.test.InstrumentationRegistry.getTargetContext;
import static com.lukekorth.deviceautomator.AutomatorAction.click;
import static com.lukekorth.deviceautomator.AutomatorAction.setText;
import static com.lukekorth.deviceautomator.AutomatorAssertion.text;
import static com.lukekorth.deviceautomator.DeviceAutomator.onDevice;
import static com.lukekorth.deviceautomator.UiObjectMatcher.withClass;
import static com.lukekorth.deviceautomator.UiObjectMatcher.withResourceId;
import static com.lukekorth.deviceautomator.UiObjectMatcher.withText;
import static com.lukekorth.deviceautomator.UiObjectMatcher.withTextStartingWith;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.core.StringEndsWith.endsWith;

@RunWith(AndroidJUnit4.class)
public class ThreeDSecureCardinalTest extends TestHelper {

    @Before
    public void setup() {
        super.setup();
        onDevice(withText("Credit or Debit Cards")).waitForEnabled().perform(click());

        PreferenceManager.getDefaultSharedPreferences(getTargetContext())
                .edit()
                .putBoolean("enable_three_d_secure", true)
                .commit();
    }

    @Test(timeout = 40000)
    public void threeDSecure_authenticates() throws UiObjectNotFoundException {
        onDevice(withText("Card Number")).perform(setText("4000000000001091"));
        fillInExpiration("01", "2022");
        onDevice(withText("CVV")).perform(setText("123"));
        onDevice(withText("Postal Code")).perform(setText("12345"));
        onDevice(withText("Purchase")).perform(click());

        String codeEditTextResId = "com.braintreepayments.demo:id/codeEditTextField";
        onDevice(withResourceId(codeEditTextResId)).waitForExists();
        onDevice(withResourceId(codeEditTextResId)).perform(click());
        onDevice().typeText("1234");

        onDevice(withText("Submit")).perform(click());

        getNonceDetails().check(text(containsString("Card Last Two: 91")));
        getNonceDetails().check(text(containsString("isLiabilityShifted: true")));
        getNonceDetails().check(text(containsString("isLiabilityShiftPossible: true")));

        onDevice(withText("Create a Transaction")).perform(click());
        onDevice(withTextStartingWith("created")).check(text(endsWith("authorized")));
    }
}

@@ -39,41 +39,8 @@
 t;%0A%0A
-import android.widget.EditText;%0A%0A
 impo
@@ -128,94 +128,8 @@
 t4;%0A
-import androidx.test.uiautomator.UiDevice;%0Aimport androidx.test.uiautomator.UiObject;%0A
 impo
@@ -187,53 +187,8 @@
 ion;
-%0Aimport androidx.test.uiautomator.UiSelector;
 %0A%0Aim
@@ -333,109 +333,8 @@
 h;%0A%0A
-import java.io.IOException;%0A%0Aimport static androidx.test.InstrumentationRegistry.getInstrumentation;%0A
 impo
@@ -678,79 +678,8 @@
 ce;%0A
-import static com.lukekorth.deviceautomator.UiObjectMatcher.withClass;%0A
 impo

Remove no longer needed imports.