package Ġcom . jud op ay . jud okit . android . ui . edit card Ċ Ċ import Ġandroid . app . Application Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġcom . jud op ay . jud okit . android . db . entity . Token ized Card Entity Ċ import Ġcom . jud op ay . jud okit . android . db . repository . Token ized Card Repository Ċ import Ġcom . jud op ay . jud okit . android . model . Card Network Ċ import Ġcom . jud op ay . jud okit . android . ui . edit card . adapter . Color Picker Item Ċ import Ġcom . jud op ay . jud okit . android . ui . payment methods . model . Payment Card ViewModel Ċ import Ġio . mock k . co Every Ċ import Ġio . mock k . co Verify Ċ import Ġio . mock k . every Ċ import Ġio . mock k . mock k Ċ import Ġio . mock k . mock k Static Ċ import Ġio . mock k . spy k Ċ import Ġio . mock k . verify Ċ import Ġjunit . framework . TestCase . assertEquals Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . test . Test Coroutine Dispatcher Ċ import Ġkotlinx . coroutines . test . reset Main Ċ import Ġkotlinx . coroutines . test . set Main Ċ import Ġorg . junit . jupiter . api . After Each Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . DisplayName Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . extension . Extend With Ċ Ċ private Ġconst Ġval ĠC ARD _ ID Ġ= Ġ 1 Ċ private Ġconst Ġval ĠNEW _ TITLE Ġ= Ġ" NEW _ TITLE " Ċ Ċ @ Experimental Cor outines Api Ċ @ Extend With ( com . jud op ay . jud okit . android . Instant Executor Extension :: class ) Ċ @ DisplayName (" Testing Ġedit Ġcard Ġview Ġmodel Ġlogic ") Ċ internal Ġclass ĠEdit Card ViewModel Test Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġtest Dispatcher Ġ= ĠTest Coroutine Dispatcher () ĊĊĠĠĠ Ġprivate Ġval Ġapplication : ĠApplication Ġ= Ġmock k ( relax ed Ġ= Ġtrue ) ĊĠĠĠ Ġprivate Ġval Ġcard Repository : ĠToken ized Card Repository Ġ= Ġmock k ( relax ed Ġ= Ġtrue ) ĊĠĠĠ Ġprivate Ġval Ġedit Card Model Mock Ġ= Ġspy k < Observer < Edit Card Model >>() ĊĠĠĠ Ġprivate Ġval Ġtoken ized Card Entity : ĠToken ized Card Entity Ġ= Ġmock k ( relax ed Ġ= Ġtrue ) Ġ{ ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġnetwork Ġ} Ġreturns ĠCard Network . VIS A ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġpattern Ġ} Ġreturns ĠCard Pattern . BLACK ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġinternal Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ ĠDispatch ers . set Main ( test Dispatcher ) ĊĊĠĠĠĠĠĠĠ Ġmock k Static (" com . jud op ay . jud okit . android . ui . edit card . Map pers Kt ") ĊĊĠĠĠĠĠĠĠ Ġco Every Ġ{ Ġcard Repository . find With Id ( CARD _ ID ) Ġ} Ġreturns Ġtoken ized Card Entity ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After Each ĊĠĠĠ Ġinternal Ġfun ĠtearDown () Ġ{ ĊĠĠĠĠĠĠĠ ĠDispatch ers . reset Main () ĊĠĠĠĠĠĠĠ Ġtest Dispatcher . cleanup Test Cor outines () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ DisplayName (" Given Ġedit Ġcard Ġview Ġmodel Ġis Ġinitial ised , Ġthen Ġcall Ġrepository . find With Id ( card Id )") ĊĠĠĠ Ġfun Ġfind Card With Given Id On ViewModel Initial ised () Ġ{ ĊĠĠĠĠĠĠĠ ĠEdit Card ViewModel ( CARD _ ID , Ġcard Repository , Ġapplication ) ĊĊĠĠĠĠĠĠĠ Ġco Verify Ġ{ Ġcard Repository . find With Id ( CARD _ ID ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ DisplayName (" Given Ġedit Ġcard Ġview Ġmodel Ġis Ġinitial ised , Ġthen Ġshould Ġupdate Ġmodel Ġwith Ġnew ĠEdit Card Model ") ĊĠĠĠ Ġfun Ġupdate Model On Edit Card ViewModel Initial ised () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġslots Ġ= Ġmutable ListOf < Edit Card Model >() ĊĊĠĠĠĠĠĠĠ Ġval Ġsut Ġ= ĠEdit Card ViewModel ( CARD _ ID , Ġcard Repository , Ġapplication ) ĊĊĠĠĠĠĠĠĠ Ġsut . model . observe Fore ver ( edit Card Model Mock ) ĊĊĠĠĠĠĠĠĠ Ġverify Ġ{ Ġedit Card Model Mock . on Changed ( capture ( slots )) Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġedit Card Model Ġ= Ġslots [ 0 ] ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( get Edit Card Model (), Ġedit Card Model ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ DisplayName (" Given Ġsend Ġmethod Ġis Ġcalled Ġwith ĠChange Pattern Ġaction , Ġthen Ġupdate Ġmodel Ġwith Ġnew Ġpattern ") ĊĠĠĠ Ġfun Ġupdate Model With New Pattern OnChange Pattern Action () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġslots Ġ= Ġmutable ListOf < Edit Card Model >() ĊĊĠĠĠĠĠĠĠ Ġval Ġsut Ġ= ĠEdit Card ViewModel ( CARD _ ID , Ġcard Repository , Ġapplication ) ĊĊĠĠĠĠĠĠĠ Ġsut . send ( Edit Card Action . Change Pattern ( Card Pattern . BLACK )) ĊĊĠĠĠĠĠĠĠ Ġsut . model . observe Fore ver ( edit Card Model Mock ) ĊĊĠĠĠĠĠĠĠ Ġverify Ġ{ Ġedit Card Model Mock . on Changed ( capture ( slots )) Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġedit Card Model Ġ= Ġslots [ 0 ] ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( get Edit Card Model (), Ġedit Card Model ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ DisplayName (" Given Ġsend Ġmethod Ġis Ġcalled Ġwith ĠSave Ġaction , Ġthen Ġcall Ġcard Repository . insert ( card Entity )") ĊĠĠĠ Ġfun Ġinsert Card On Save Action () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsut Ġ= ĠEdit Card ViewModel ( CARD _ ID , Ġcard Repository , Ġapplication ) ĊĊĠĠĠĠĠĠĠ Ġsut . send ( Edit Card Action . Save ) ĊĊĠĠĠĠĠĠĠ Ġsut . model . observe Fore ver ( edit Card Model Mock ) ĊĊĠĠĠĠĠĠĠ Ġco Verify Ġ{ Ġcard Repository . insert ( token ized Card Entity ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ DisplayName (" Given Ġsend Ġmethod Ġis Ġcalled Ġwith ĠToggle Default Card State Ġaction , Ġthen Ġupdate Ġis Default Ġmodel Ġfield ") ĊĠĠĠ Ġfun Ġupdate Is Default Model Field On Toggle Default Card State Action () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġslots Ġ= Ġmutable ListOf < Edit Card Model >() ĊĊĠĠĠĠĠĠĠ Ġval Ġsut Ġ= ĠEdit Card ViewModel ( CARD _ ID , Ġcard Repository , Ġapplication ) ĊĊĠĠĠĠĠĠĠ Ġsut . send ( Edit Card Action . Toggle Default Card State ) ĊĊĠĠĠĠĠĠĠ Ġsut . model . observe Fore ver ( edit Card Model Mock ) ĊĊĠĠĠĠĠĠĠ Ġverify Ġ{ Ġedit Card Model Mock . on Changed ( capture ( slots )) Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġedit Card Model Ġ= Ġslots [ 0 ] ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( get Edit Card Model ( on Changed Ġ= Ġtrue , Ġis Default Ġ= Ġtrue ), Ġedit Card Model ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ DisplayName (" Given Ġsend Ġmethod Ġis Ġcalled Ġwith ĠChange Title Ġaction , Ġthen Ġupdate Ġtitle Ġmodel Ġfield ") ĊĠĠĠ Ġfun Ġupdate Title Model Field OnChange Title Action () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġslots Ġ= Ġmutable ListOf < Edit Card Model >() ĊĊĠĠĠĠĠĠĠ Ġval Ġsut Ġ= ĠEdit Card ViewModel ( CARD _ ID , Ġcard Repository , Ġapplication ) ĊĊĠĠĠĠĠĠĠ Ġsut . send ( Edit Card Action . Change Title ( NEW _ TITLE )) ĊĊĠĠĠĠĠĠĠ Ġsut . model . observe Fore ver ( edit Card Model Mock ) ĊĊĠĠĠĠĠĠĠ Ġverify Ġ{ Ġedit Card Model Mock . on Changed ( capture ( slots )) Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġedit Card Model Ġ= Ġslots [ 0 ] ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( get Edit Card Model ( on Changed Ġ= Ġtrue , Ġtitle Ġ= ĠNEW _ TITLE ), Ġedit Card Model ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġpatterns Ġ= ĠCard Pattern . values (). map Ġ{ ĠColor Picker Item ( it ) Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Edit Card Model ( ĊĠĠĠĠĠĠĠ ĠonChanged : ĠBoolean Ġ= Ġfalse , ĊĠĠĠĠĠĠĠ Ġis Default : ĠBoolean Ġ= Ġfalse , ĊĠĠĠĠĠĠĠ Ġtitle : ĠString Ġ= Ġ"" ĊĠĠĠ Ġ): ĠEdit Card Model Ġ{ ĊĠĠĠĠĠĠĠ Ġpatterns . forEach Ġ{ Ġit . isSelected Ġ= Ġit . pattern Ġ== ĠCard Pattern . BLACK Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn ĠEdit Card Model ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcolor Options Ġ= Ġpatterns , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis Save Button Enabled Ġ= ĠonChanged , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcard Ġ= ĠPayment Card ViewModel ( name Ġ= Ġtitle ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtitle Ġ= Ġtitle , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġis Default Ġ= Ġis Default ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} Ċ } Ċ