package Ġcom . ap top ay ments . sdk . features . load fund s . payments ources Ċ Ċ import Ġandroid . content . SharedPreferences Ċ import Ġcom . ap top ay ments . mobile . data . payments ources . Card Ċ import Ġcom . ap top ay ments . mobile . data . payments ources . New Card Ċ import Ġcom . ap top ay ments . mobile . data . payments ources . Payment Source Ċ import Ġcom . ap top ay ments . mobile . exception . Failure Ċ import Ġcom . ap top ay ments . mobile . functional . Either Ċ import Ġcom . ap top ay ments . mobile . functional . right Ċ import Ġcom . ap top ay ments . mobile . platform . A pto Platform Protocol Ċ import Ġcom . ap top ay ments . sdk . Coroutine Dispatcher Test Ċ import Ġcom . ap top ay ments . sdk . Instant Executor Extension Ċ import Ġcom . ap top ay ments . sdk . core . data . Test DataProvider Ċ import Ġcom . ap top ay ments . sdk . utils . shouldBe Right And EqualTo Ċ import Ġorg . mockito . kotlin .* Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . test . Test Coroutine Dispatcher Ċ import Ġkotlinx . coroutines . test . run Blocking Test Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ import Ġkotlin . test . assertEquals Ċ import Ġkotlin . test . assertNull Ċ Ċ private Ġconst Ġval ĠAC CEPT ED _ ON BOARD ING Ġ= Ġ" ADD _ CARD _ ACCEPT ED _ ON BOARD ING " Ċ Ċ @ Suppress (" UN CHECK ED _ CAST ") Ċ @ Experimental Cor outines Api Ċ @ Extend With ( Instant Executor Extension :: class ) Ċ class ĠPayment Sources Repository Test Ġ: ĠCor outine Dispatcher Test Ġ{ ĊĊĠĠĠ Ġoverride Ġlateinit Ġvar Ġdispatcher : ĠTest Coroutine Dispatcher ĊĊĠĠĠ Ġprivate Ġval Ġapt o Platform : ĠA pto Platform Protocol Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġeditor : ĠSharedPreferences . Editor Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġshared Preferences : ĠSharedPreferences Ġ= Ġmock () ĊĊĠĠĠ Ġprivate Ġval Ġsut Ġ= ĠPayment Sources Repository ( ap to Platform , Ġshared Preferences ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġaccepted Ġon boarding Ġthen Ġsaved Ġto Ġshared Pref `() Ġ{ ĊĠĠĠĠĠĠĠ Ġconfigure Shared Pref () ĊĊĠĠĠĠĠĠĠ Ġsut . accepted On boarding () ĊĊĠĠĠĠĠĠĠ Ġverify ( editor ). put Boolean ( ACCEPT ED _ ON BOARD ING , Ġtrue ) ĊĠĠĠĠĠĠĠ Ġverify ( editor ). apply () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġhas Accepted On boarding Ġthen Ġresult Ġis Ġgot Ġfrom Ġshared Pref `() Ġ{ ĊĠĠĠĠĠĠĠ Ġconfigure Shared Pref () ĊĊĠĠĠĠĠĠĠ Ġsut . has Accepted On boarding () ĊĊĠĠĠĠĠĠĠ Ġverify ( shared Preferences ). getBoolean ( ACCEPT ED _ ON BOARD ING , Ġfalse ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġrepo Ġwithout Ġinteraction Ġthen Ġselected Payment Source Ġis Ġnull `() Ġ= Ġdispatcher . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ ĠassertNull ( sut . selected Payment Source . value ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġselect Payment Source Loc ally Ġthen Ġvalue Ġis Ġupdated `() Ġ= Ġdispatcher . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= ĠTest DataProvider . provide Payment Sources Card () ĊĊĠĠĠĠĠĠĠ Ġsut . select Payment Source Loc ally ( card ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( card , Ġsut . selected Payment Source . value ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġselect Payment Source Loc ally Ġthen Ġno Ġapi - call Ġis Ġmade `() Ġ= Ġdispatcher . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= ĠTest DataProvider . provide Payment Sources Card () ĊĊĠĠĠĠĠĠĠ Ġsut . select Payment Source Loc ally ( card ) ĊĊĠĠĠĠĠĠĠ Ġverify Zero Interactions ( ap to Platform ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġrefresh Selected Payment Source Ġthen Ġcorrect Ġpayment Ġsource Ġreturned Ġin Ġlive Data `() Ġ= Ġdispatcher . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= ĠTest DataProvider . provide Payment Sources Card () ĊĠĠĠĠĠĠĠ Ġconfigure Get Payment Sources ( card ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġsut . refresh Selected Payment Source () ĊĊĠĠĠĠĠĠĠ Ġresult . shouldBe Right And EqualTo ( card ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( card , Ġsut . selected Payment Source . value ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġget Payment Source List Ġthen Ġcorrect Ġreturned `() Ġ= Ġdispatcher . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= ĠTest DataProvider . provide Payment Sources Card () ĊĠĠĠĠĠĠĠ Ġconfigure Get Payment Sources ( card ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġsut . get Payment Source List () ĊĊĠĠĠĠĠĠĠ Ġresult . shouldBe Right And EqualTo ( listOf ( card )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` when Ġadd Payment Source Ġthen Ġselected Ġpayment Ġsource Ġreturned `() Ġ= Ġdispatcher . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnew Card Ġ= ĠTest DataProvider . provide New Card () ĊĠĠĠĠĠĠĠ Ġval Ġcard Ġ= ĠTest DataProvider . provide Payment Sources Card () ĊĠĠĠĠĠĠĠ Ġconfigure Add Payment Source ( new Card , Ġcard ) ĊĠĠĠĠĠĠĠ Ġconfigure Get Payment Sources ( card ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġsut . add Payment Source ( new Card ) ĊĊĠĠĠĠĠĠĠ Ġresult . shouldBe Right And EqualTo ( card ) ĊĠĠĠĠĠĠĠ Ġverify ( ap to Platform ). add Payment Source ( eq ( new Card ), Ġany ()) ĊĠĠĠĠĠĠĠ Ġverify ( ap to Platform ). get Payment Sources ( any (), Ġany OrNull (), Ġany OrNull (), Ġany OrNull ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ( card , Ġsut . selected Payment Source . value ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġconfigure Add Payment Source ( ĊĠĠĠĠĠĠĠ Ġnew Card : ĠNew Card , ĊĠĠĠĠĠĠĠ Ġcard : ĠCard ĊĠĠĠ Ġ) Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( ap to Platform . add Payment Source ( eq ( new Card ), Ġany ())). then Answer Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ( it . arguments [ 1 ] Ġas Ġ( Either < Failure , ĠPayment Source >) Ġ-> ĠUnit ). invoke ( card . right ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġconfigure Get Payment Sources ( card : ĠCard ) Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( ap to Platform . get Payment Sources ( any (), Ġany OrNull (), Ġany OrNull (), Ġany OrNull ())). then Answer Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ( it . arguments [ 0 ] Ġas Ġ( Either < Failure , ĠList < Payment Source >>) Ġ-> ĠUnit ). invoke ( listOf ( card ). right ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġconfigure Shared Pref () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( shared Preferences . edit ()). thenReturn ( editor ) ĊĠĠĠĠĠĠĠ Ġwhenever ( editor . put Boolean ( any (), Ġany ())). thenReturn ( editor ) ĊĠĠĠ Ġ} Ċ } Ċ