File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
main/java/com/paypal/android/cardpayments
test/java/com/paypal/android/cardpayments Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ class CardClient internal constructor(
3838 var cardVaultListener: CardVaultListener ? = null
3939
4040 private var approveOrderId: String? = null
41- private val lifeCycleObserver = CardLifeCycleObserver (this )
41+ internal val lifeCycleObserver = CardLifeCycleObserver (this )
4242
4343 private val activityReference = WeakReference (activity)
4444
Original file line number Diff line number Diff line change @@ -29,6 +29,8 @@ import org.junit.Before
2929import org.junit.Test
3030import org.junit.runner.RunWith
3131import org.robolectric.RobolectricTestRunner
32+ import strikt.api.expectThat
33+ import strikt.assertions.isNull
3234
3335@ExperimentalCoroutinesApi
3436@RunWith(RobolectricTestRunner ::class )
@@ -359,4 +361,18 @@ class CardClientUnitTest {
359361 sut.cardVaultListener = cardVaultListener
360362 return sut
361363 }
364+
365+ @Test
366+ fun `when client is complete, lifecycle observer is removed` () = runTest {
367+ val sut = createCardClient(testScheduler)
368+
369+ val lifeCycle = mockk<Lifecycle >(relaxed = true )
370+ every { activity.lifecycle } returns lifeCycle
371+
372+ sut.removeObservers()
373+
374+ verify { lifeCycle.removeObserver(sut.lifeCycleObserver) }
375+ expectThat(sut.approveOrderListener).isNull()
376+ expectThat(sut.cardVaultListener).isNull()
377+ }
362378}
You can’t perform that action at this time.
0 commit comments