From 8b8242795e5225955f14b783004e3c38f22e0bb7 Mon Sep 17 00:00:00 2001 From: Michael Shafrir Date: Tue, 15 Sep 2020 13:38:37 -0400 Subject: [PATCH] Fix tests --- .../view/BecsDebitAccountNumberEditTextTest.kt | 7 ++++++- .../stripe/android/view/BecsDebitBsbEditTextTest.kt | 9 ++++++++- .../stripe/android/view/CardNumberEditTextTest.kt | 7 +++++-- .../java/com/stripe/android/view/CvcEditTextTest.kt | 10 ++++++++-- .../com/stripe/android/view/EmailEditTextTest.kt | 7 ++++++- .../stripe/android/view/ExpiryDateEditTextTest.kt | 12 ++++++++---- .../stripe/android/view/PostalCodeEditTextTest.kt | 8 ++++++-- .../com/stripe/android/view/StripeEditTextTest.kt | 9 +++++---- 8 files changed, 52 insertions(+), 17 deletions(-) diff --git a/stripe/src/test/java/com/stripe/android/view/BecsDebitAccountNumberEditTextTest.kt b/stripe/src/test/java/com/stripe/android/view/BecsDebitAccountNumberEditTextTest.kt index 28a72f1f3ab..9c1531903f1 100644 --- a/stripe/src/test/java/com/stripe/android/view/BecsDebitAccountNumberEditTextTest.kt +++ b/stripe/src/test/java/com/stripe/android/view/BecsDebitAccountNumberEditTextTest.kt @@ -1,7 +1,9 @@ package com.stripe.android.view +import androidx.appcompat.view.ContextThemeWrapper import androidx.test.core.app.ApplicationProvider import com.google.common.truth.Truth.assertThat +import com.stripe.android.R import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import kotlin.test.Test @@ -9,7 +11,10 @@ import kotlin.test.Test @RunWith(RobolectricTestRunner::class) class BecsDebitAccountNumberEditTextTest { private val accountNumberEditText = BecsDebitAccountNumberEditText( - ApplicationProvider.getApplicationContext() + ContextThemeWrapper( + ApplicationProvider.getApplicationContext(), + R.style.StripeDefaultTheme + ) ) @Test diff --git a/stripe/src/test/java/com/stripe/android/view/BecsDebitBsbEditTextTest.kt b/stripe/src/test/java/com/stripe/android/view/BecsDebitBsbEditTextTest.kt index 5d479afaf76..8499ced9485 100644 --- a/stripe/src/test/java/com/stripe/android/view/BecsDebitBsbEditTextTest.kt +++ b/stripe/src/test/java/com/stripe/android/view/BecsDebitBsbEditTextTest.kt @@ -1,7 +1,9 @@ package com.stripe.android.view +import androidx.appcompat.view.ContextThemeWrapper import androidx.test.core.app.ApplicationProvider import com.google.common.truth.Truth.assertThat +import com.stripe.android.R import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import kotlin.test.Test @@ -9,7 +11,12 @@ import kotlin.test.Test @RunWith(RobolectricTestRunner::class) class BecsDebitBsbEditTextTest { - private val bsbEditText = BecsDebitBsbEditText(ApplicationProvider.getApplicationContext()) + private val bsbEditText = BecsDebitBsbEditText( + ContextThemeWrapper( + ApplicationProvider.getApplicationContext(), + R.style.StripeDefaultTheme + ) + ) @Test fun onCompletedCallback_isCalled() { diff --git a/stripe/src/test/java/com/stripe/android/view/CardNumberEditTextTest.kt b/stripe/src/test/java/com/stripe/android/view/CardNumberEditTextTest.kt index e940defd9b7..9d44671cbc5 100644 --- a/stripe/src/test/java/com/stripe/android/view/CardNumberEditTextTest.kt +++ b/stripe/src/test/java/com/stripe/android/view/CardNumberEditTextTest.kt @@ -1,7 +1,7 @@ package com.stripe.android.view -import android.content.Context import android.view.ViewGroup +import androidx.appcompat.view.ContextThemeWrapper import androidx.test.core.app.ApplicationProvider import com.google.common.truth.Truth.assertThat import com.stripe.android.ApiKeyFixtures @@ -57,7 +57,10 @@ import kotlin.test.assertNull @LooperMode(LooperMode.Mode.PAUSED) internal class CardNumberEditTextTest { private val testDispatcher = TestCoroutineDispatcher() - private val context: Context = ApplicationProvider.getApplicationContext() + private val context = ContextThemeWrapper( + ApplicationProvider.getApplicationContext(), + R.style.StripeDefaultTheme + ) private val activityScenarioFactory = ActivityScenarioFactory(context) private var completionCallbackInvocations = 0 diff --git a/stripe/src/test/java/com/stripe/android/view/CvcEditTextTest.kt b/stripe/src/test/java/com/stripe/android/view/CvcEditTextTest.kt index a01329ac6f1..7be84a33e9e 100644 --- a/stripe/src/test/java/com/stripe/android/view/CvcEditTextTest.kt +++ b/stripe/src/test/java/com/stripe/android/view/CvcEditTextTest.kt @@ -1,7 +1,9 @@ package com.stripe.android.view +import androidx.appcompat.view.ContextThemeWrapper import androidx.test.core.app.ApplicationProvider import com.google.common.truth.Truth.assertThat +import com.stripe.android.R import com.stripe.android.model.CardBrand import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner @@ -11,8 +13,12 @@ import kotlin.test.assertTrue @RunWith(RobolectricTestRunner::class) class CvcEditTextTest { - - private val cvcEditText = CvcEditText(ApplicationProvider.getApplicationContext()) + private val cvcEditText = CvcEditText( + ContextThemeWrapper( + ApplicationProvider.getApplicationContext(), + R.style.StripeDefaultTheme + ) + ) @Test fun cvcValue_withoutText_returnsNull() { diff --git a/stripe/src/test/java/com/stripe/android/view/EmailEditTextTest.kt b/stripe/src/test/java/com/stripe/android/view/EmailEditTextTest.kt index 38bbe0a25c4..53fd070d7b2 100644 --- a/stripe/src/test/java/com/stripe/android/view/EmailEditTextTest.kt +++ b/stripe/src/test/java/com/stripe/android/view/EmailEditTextTest.kt @@ -1,7 +1,9 @@ package com.stripe.android.view +import androidx.appcompat.view.ContextThemeWrapper import androidx.test.core.app.ApplicationProvider import com.google.common.truth.Truth.assertThat +import com.stripe.android.R import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import kotlin.test.Test @@ -9,7 +11,10 @@ import kotlin.test.Test @RunWith(RobolectricTestRunner::class) class EmailEditTextTest { private val emailEditText = EmailEditText( - ApplicationProvider.getApplicationContext() + ContextThemeWrapper( + ApplicationProvider.getApplicationContext(), + R.style.StripeDefaultTheme + ) ) @Test diff --git a/stripe/src/test/java/com/stripe/android/view/ExpiryDateEditTextTest.kt b/stripe/src/test/java/com/stripe/android/view/ExpiryDateEditTextTest.kt index 664306b7af9..9f8cfefb0bd 100644 --- a/stripe/src/test/java/com/stripe/android/view/ExpiryDateEditTextTest.kt +++ b/stripe/src/test/java/com/stripe/android/view/ExpiryDateEditTextTest.kt @@ -1,7 +1,8 @@ package com.stripe.android.view -import android.content.Context +import androidx.appcompat.view.ContextThemeWrapper import androidx.test.core.app.ApplicationProvider +import com.stripe.android.R import com.stripe.android.testharness.ViewTestUtils import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner @@ -19,9 +20,12 @@ import kotlin.test.assertTrue */ @RunWith(RobolectricTestRunner::class) class ExpiryDateEditTextTest { - private val expiryDateEditText: ExpiryDateEditText by lazy { - ExpiryDateEditText(ApplicationProvider.getApplicationContext()) - } + private val expiryDateEditText = ExpiryDateEditText( + ContextThemeWrapper( + ApplicationProvider.getApplicationContext(), + R.style.StripeDefaultTheme + ) + ) @BeforeTest fun setup() { diff --git a/stripe/src/test/java/com/stripe/android/view/PostalCodeEditTextTest.kt b/stripe/src/test/java/com/stripe/android/view/PostalCodeEditTextTest.kt index 3831b0fa176..1e48ac99dc5 100644 --- a/stripe/src/test/java/com/stripe/android/view/PostalCodeEditTextTest.kt +++ b/stripe/src/test/java/com/stripe/android/view/PostalCodeEditTextTest.kt @@ -1,14 +1,15 @@ package com.stripe.android.view import android.app.Activity -import android.content.Context import android.text.InputType +import androidx.appcompat.view.ContextThemeWrapper import androidx.test.core.app.ApplicationProvider import com.google.android.material.textfield.TextInputLayout import com.google.common.truth.Truth.assertThat import com.nhaarman.mockitokotlin2.mock import com.stripe.android.CustomerSession import com.stripe.android.PaymentSessionFixtures +import com.stripe.android.R import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import kotlin.test.BeforeTest @@ -16,7 +17,10 @@ import kotlin.test.Test @RunWith(RobolectricTestRunner::class) class PostalCodeEditTextTest { - private val context = ApplicationProvider.getApplicationContext() + private val context = ContextThemeWrapper( + ApplicationProvider.getApplicationContext(), + R.style.StripeDefaultTheme + ) private val postalCodeEditText = PostalCodeEditText(context) @BeforeTest diff --git a/stripe/src/test/java/com/stripe/android/view/StripeEditTextTest.kt b/stripe/src/test/java/com/stripe/android/view/StripeEditTextTest.kt index 47773b2a62f..5bc85738f9e 100644 --- a/stripe/src/test/java/com/stripe/android/view/StripeEditTextTest.kt +++ b/stripe/src/test/java/com/stripe/android/view/StripeEditTextTest.kt @@ -2,6 +2,7 @@ package com.stripe.android.view import android.content.Context import androidx.annotation.ColorInt +import androidx.appcompat.view.ContextThemeWrapper import androidx.core.content.ContextCompat import androidx.test.core.app.ApplicationProvider import com.google.common.truth.Truth.assertThat @@ -14,7 +15,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestCoroutineDispatcher import kotlinx.coroutines.test.runBlockingTest import org.junit.runner.RunWith -import org.mockito.Mockito.reset import org.mockito.Mockito.verify import org.robolectric.RobolectricTestRunner import kotlin.test.Test @@ -22,8 +22,10 @@ import kotlin.test.Test @RunWith(RobolectricTestRunner::class) @ExperimentalCoroutinesApi internal class StripeEditTextTest { - - private val context: Context = ApplicationProvider.getApplicationContext() + private val context: Context = ContextThemeWrapper( + ApplicationProvider.getApplicationContext(), + R.style.StripeDefaultTheme + ) private val afterTextChangedListener: StripeEditText.AfterTextChangedListener = mock() private val deleteEmptyListener: StripeEditText.DeleteEmptyListener = mock() private val testDispatcher = TestCoroutineDispatcher() @@ -54,7 +56,6 @@ internal class StripeEditTextTest { @Test fun deleteText_whenNonZeroLength_callsAppropriateListeners() { editText.append("1") - reset(afterTextChangedListener) ViewTestUtils.sendDeleteKeyEvent(editText) verifyNoMoreInteractions(deleteEmptyListener)