Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mshafrir-stripe committed Sep 15, 2020
1 parent e946b90 commit 8b82427
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
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

@RunWith(RobolectricTestRunner::class)
class BecsDebitAccountNumberEditTextTest {
private val accountNumberEditText = BecsDebitAccountNumberEditText(
ApplicationProvider.getApplicationContext()
ContextThemeWrapper(
ApplicationProvider.getApplicationContext(),
R.style.StripeDefaultTheme
)
)

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
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

@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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions stripe/src/test/java/com/stripe/android/view/CvcEditTextTest.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
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

@RunWith(RobolectricTestRunner::class)
class EmailEditTextTest {
private val emailEditText = EmailEditText(
ApplicationProvider.getApplicationContext()
ContextThemeWrapper(
ApplicationProvider.getApplicationContext(),
R.style.StripeDefaultTheme
)
)

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,9 +20,12 @@ import kotlin.test.assertTrue
*/
@RunWith(RobolectricTestRunner::class)
class ExpiryDateEditTextTest {
private val expiryDateEditText: ExpiryDateEditText by lazy {
ExpiryDateEditText(ApplicationProvider.getApplicationContext<Context>())
}
private val expiryDateEditText = ExpiryDateEditText(
ContextThemeWrapper(
ApplicationProvider.getApplicationContext(),
R.style.StripeDefaultTheme
)
)

@BeforeTest
fun setup() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
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
import kotlin.test.Test

@RunWith(RobolectricTestRunner::class)
class PostalCodeEditTextTest {
private val context = ApplicationProvider.getApplicationContext<Context>()
private val context = ContextThemeWrapper(
ApplicationProvider.getApplicationContext(),
R.style.StripeDefaultTheme
)
private val postalCodeEditText = PostalCodeEditText(context)

@BeforeTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,16 +15,17 @@ 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

@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()
Expand Down Expand Up @@ -54,7 +56,6 @@ internal class StripeEditTextTest {
@Test
fun deleteText_whenNonZeroLength_callsAppropriateListeners() {
editText.append("1")
reset(afterTextChangedListener)

ViewTestUtils.sendDeleteKeyEvent(editText)
verifyNoMoreInteractions(deleteEmptyListener)
Expand Down

0 comments on commit 8b82427

Please sign in to comment.