package Ġcom . hey ze us v . pl ut us wallet . ui . account Ċ Ċ import Ġcom . hey ze us v . pl ut us wallet . Instant Executor Extension Ċ import Ġcom . hey ze us v . pl ut us wallet . Test Coroutine Extension Ċ import Ġcom . hey ze us v . pl ut us wallet . data . Dummy Data Util Ċ import Ġcom . hey ze us v . pl ut us wallet . data . Fake Repository Ċ import Ġcom . hey ze us v . pl ut us wallet . data . model . Account Ċ import Ġcom . hey ze us v . pl ut us wallet . util . Event Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . test . run Blocking Test Ċ import Ġorg . junit . Assert . assertEquals Ċ 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 Ċ Ċ @ Experimental Cor outines Api Ċ @ Extend With ( Instant Executor Extension :: class , ĠTest Coroutine Extension :: class ) Ċ internal Ġclass ĠAccount ViewModel Test Ġ{ ĊĊĠĠĠ Ġ// Ġtest ĠFake ĊĠĠĠ Ġprivate Ġval Ġrepo Ġ= ĠFake Repository () ĊĊĠĠĠ Ġ// ĠWhat Ġis Ġbeing Ġtested ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġacc VM : ĠAccount ViewModel ĊĊĠĠĠ Ġ// Ġdummy Ġdata ĊĠĠĠ Ġprivate Ġval Ġdd Ġ= ĠDummy Data Util () ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun ĠsetUp ViewModel () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġ// Ġreset Ġfake Ġrepo Ġwith Ġdummy Ġdata Ġand Ġpass Ġit Ġto ĠViewModel ĊĠĠĠĠĠĠĠ Ġrepo . reset Lists () ĊĠĠĠĠĠĠĠ Ġacc VM Ġ= ĠAccount ViewModel ( repo ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ DisplayName (" Should Ġcreate Ġedit ĠEvent Ġcontaining ĠAccount Ġwhen Ġedit Ġbutton Ġis Ġpressed ") ĊĠĠĠ Ġfun Ġedit Account OC () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġacc Ġ= ĠAccount ( 0 , Ġ" Test ") ĊĊĠĠĠĠĠĠĠ Ġacc VM . edit Account OC ( acc ) ĊĠĠĠĠĠĠĠ Ġval Ġvalue : ĠEvent < Account > Ġ= Ġacc VM . edit Account Event . value !! ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( value . getContent IfNot Handled (), Ġacc ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ DisplayName (" Should Ġcreate Ġdelete ĠEvent Ġcontaining ĠAccount Ġwhen Ġdelete Ġbutton Ġis Ġpressed ") ĊĠĠĠ Ġfun Ġdelete Account OC () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġacc Ġ= ĠAccount ( 0 , Ġ" Test ") ĊĊĠĠĠĠĠĠĠ Ġacc VM . delete Account OC ( acc ) ĊĠĠĠĠĠĠĠ Ġval Ġvalue : ĠEvent < Account > Ġ= Ġacc VM . delete Account Event . value !! ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( value . getContent IfNot Handled (), Ġacc ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ DisplayName (" Should Ġinitialize Ġlist Ġcontaining Ġall ĠAccount Ġnames Ġand ĠAccounts Ġbeing Ġused ") ĊĠĠĠ Ġfun Ġinit Names Used Lists () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġexpected Names : ĠMutable List < String > Ġ= Ġmutable ListOf (" Cash ", Ġ" Credit ĠCard ", Ġ" Debit ĠCard ", Ġ" Unused ") ĊĠĠĠĠĠĠĠ Ġval Ġexpected Used : ĠMutable List < String > Ġ= Ġmutable ListOf (" Cash ", Ġ" Credit ĠCard ", Ġ" Debit ĠCard ") ĊĊĠĠĠĠĠĠĠ Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġacc VM . init Names Used Lists () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( expected Names , Ġacc VM . account Names ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected Used , Ġacc VM . accounts Used ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ DisplayName (" Should Ġdelete ĠAccount Ġfrom Ġlists Ġand Ġdatabase ") ĊĠĠĠ Ġfun Ġdelete Account Pos Fun () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġexpected Names : ĠMutable List < String > Ġ= Ġmutable ListOf (" Cash ", Ġ" Debit ĠCard ", Ġ" Unused ") ĊĠĠĠĠĠĠĠ Ġval Ġexpected Used : ĠMutable List < String > Ġ= Ġmutable ListOf (" Cash ", Ġ" Debit ĠCard ") ĊĠĠĠĠĠĠĠ Ġacc VM . account Names Ġ= Ġmutable ListOf (" Cash ", Ġ" Credit ĠCard ", Ġ" Debit ĠCard ", Ġ" Unused ") ĊĠĠĠĠĠĠĠ Ġacc VM . accounts Used Ġ= Ġmutable ListOf (" Cash ", Ġ" Credit ĠCard ", Ġ" Debit ĠCard ") ĊĊĠĠĠĠĠĠĠ Ġacc VM . delete Account Pos Fun ( dd . acc 1 ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( expected Names , Ġacc VM . account Names ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected Used , Ġacc VM . accounts Used ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( mutable ListOf ( dd . acc 2 , Ġdd . acc 3 , Ġdd . acc 4 ), Ġrepo . acc List ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ DisplayName (" Should Ġedit ĠAccount Ġwith Ġa Ġnew Ġname ") ĊĠĠĠ Ġfun Ġedit AccountName () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġexpected Names : ĠMutable List < String > Ġ= Ġmutable ListOf (" Cash ", Ġ" Test ", Ġ" Debit ĠCard ", Ġ" Unused ") ĊĠĠĠĠĠĠĠ Ġval Ġexpected Used : ĠMutable List < String > Ġ= Ġmutable ListOf (" Cash ", Ġ" Test ", Ġ" Debit ĠCard ") ĊĠĠĠĠĠĠĠ Ġacc VM . account Names Ġ= Ġmutable ListOf (" Cash ", Ġ" Credit ĠCard ", Ġ" Debit ĠCard ", Ġ" Unused ") ĊĠĠĠĠĠĠĠ Ġacc VM . accounts Used Ġ= Ġmutable ListOf (" Cash ", Ġ" Credit ĠCard ", Ġ" Debit ĠCard ") ĊĊĠĠĠĠĠĠĠ Ġacc VM . edit AccountName ( dd . acc 1 , Ġ" Test ") ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( expected Names , Ġacc VM . account Names ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( expected Used , Ġacc VM . accounts Used ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Account ( 1 , Ġ" Test "), Ġrepo . acc List [ 0 ]) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ DisplayName (" Should Ġedit ĠAccount Ġwith Ġan Ġexisting Ġname Ġwhich Ġcreates Ġan Ġexists ĠEvent ") ĊĠĠĠ Ġfun Ġedit AccountName Exists () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġacc VM . account Names Ġ= Ġmutable ListOf (" Cash ", Ġ" Credit ĠCard ", Ġ" Debit ĠCard ", Ġ" Unused ") ĊĊĠĠĠĠĠĠĠ Ġacc VM . edit AccountName ( dd . acc 1 , Ġ" Cash ") ĊĠĠĠĠĠĠĠ Ġval Ġvalue : ĠEvent < String > Ġ= Ġacc VM . exists Account Event . value !! ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( value . getContent IfNot Handled (), Ġ" Cash ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ DisplayName (" Should Ġinsert Ġa Ġnew Ġunique ĠAccount ") ĊĠĠĠ Ġfun Ġinsert New Account () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġnew Account Ġ= ĠAccount ( 1 0 0 , Ġ" Test ") ĊĊĠĠĠĠĠĠĠ Ġacc VM . insert New Account ( new Account , Ġ" Test ") ĊĊĠĠĠĠĠĠĠ Ġassert ( repo . acc List . contains ( new Account )) ĊĠĠĠĠĠĠĠ ĠassertEquals ( mutable ListOf (" Test "), Ġacc VM . account Names ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ DisplayName (" Should Ġinsert ĠAccount Ġwith Ġan Ġexisting Ġname Ġwhich Ġcreates Ġan Ġexist ĠEvent ") ĊĠĠĠ Ġfun Ġinsert New Account Exists () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġnew Account Ġ= ĠAccount ( 1 0 0 , Ġ" Cash ") ĊĠĠĠĠĠĠĠ Ġacc VM . account Names Ġ= Ġmutable ListOf (" Cash ", Ġ" Credit ĠCard ", Ġ" Debit ĠCard ", Ġ" Unused ") ĊĊĠĠĠĠĠĠĠ Ġacc VM . insert New Account ( new Account , Ġ" Cash ") ĊĠĠĠĠĠĠĠ Ġval Ġvalue : ĠEvent < String > Ġ= Ġacc VM . exists Account Event . value !! ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( value . getContent IfNot Handled (), Ġ" Cash ") ĊĠĠĠ Ġ} Ċ }