Skip to content

Commit

Permalink
Add unit test to CardClient
Browse files Browse the repository at this point in the history
  • Loading branch information
warmkesselj committed Apr 24, 2024
1 parent 1123f69 commit c9e7425
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CardClient internal constructor(
var cardVaultListener: CardVaultListener? = null

private var approveOrderId: String? = null
private val lifeCycleObserver = CardLifeCycleObserver(this)
internal val lifeCycleObserver = CardLifeCycleObserver(this)

private val activityReference = WeakReference(activity)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import strikt.api.expectThat
import strikt.assertions.isNull

@ExperimentalCoroutinesApi
@RunWith(RobolectricTestRunner::class)
Expand Down Expand Up @@ -359,4 +361,18 @@ class CardClientUnitTest {
sut.cardVaultListener = cardVaultListener
return sut
}

@Test
fun `when client is complete, lifecycle observer is removed`() = runTest {
val sut = createCardClient(testScheduler)

val lifeCycle = mockk<Lifecycle>(relaxed = true)
every { activity.lifecycle } returns lifeCycle

sut.removeObservers()

verify { lifeCycle.removeObserver(sut.lifeCycleObserver) }
expectThat(sut.approveOrderListener).isNull()
expectThat(sut.cardVaultListener).isNull()
}
}

0 comments on commit c9e7425

Please sign in to comment.