package Ġcom . kin . eco system . balance . presenter ĊĊ Ċ import Ġcom . kin . eco system . balance . view . IB alance View Ċ import Ġcom . kin . eco system . common . Observer Ċ import Ġcom . kin . eco system . common . model . Balance Ċ import Ġcom . kin . eco system . core . data . blockchain . Blockchain Source Ċ import Ġcom . kin . eco system . core . data . order . Order DataSource Ċ import Ġcom . kin . eco system . core . network . model . Order Ċ import Ġcom . n ha ar man . mock it ok otlin 2 .* Ċ import Ġjunit . framework . Assert . assertNull Ċ import Ġjunit . framework . Assert . assertTrue Ċ import Ġkin . eco system . test . base . Base TestClass Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . junit . runners . JUnit 4 Ċ import Ġorg . mockito . Mockito . verify Ċ import Ġjava . math . BigDecimal Ċ Ċ @ RunWith ( JUnit 4 :: class ) Ċ class ĠBalance Presenter Test Ġ: ĠBase TestClass () Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġbalance View : ĠI Balance View Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġblockchain Source : ĠBlock chain Source Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġorder Repository : ĠOrder DataSource Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġorder : ĠOrder Ġ= Ġmock Ġ{ ĊĠĠĠĠĠĠĠ Ġon Ġ{ ĠorderId Ġ} Ġdo Answer Ġ{ Ġ" 2 " Ġ} ĊĠĠĠĠĠĠĠ Ġon Ġ{ Ġoffer Id Ġ} Ġdo Answer Ġ{ Ġ" 1 " Ġ} ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġprivate Ġval Ġbalance Observer Captor Ġ= Ġargument Captor < Observer < Balance >>() ĊĠĠĠ Ġprivate Ġval Ġs se Captor Ġ= Ġargument Captor < Boolean >() ĊĠĠĠ Ġprivate Ġval Ġorder Observer Captor Ġ= Ġargument Captor < Observer < Order >>() ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġbalance Presenter : ĠBalance Presenter ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġoverride Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . setUp () ĊĠĠĠĠĠĠĠ Ġbalance Presenter Ġ= ĠBalance Presenter ( blockchain Source , Ġorder Repository ) ĊĠĠĠĠĠĠĠ Ġbalance Presenter . on Attach ( balance View ) ĊĊĠĠĠĠĠĠĠ Ġverify ( blockchain Source ). add Balance Observer ( balance Observer Captor . capture (), Ġs se Captor . capture ()) ĊĠĠĠĠĠĠĠ Ġverify ( order Repository ). add Order Observer ( order Observer Captor . capture ()) ĊĠĠĠĠĠĠĠ ĠassertTrue ( sse Captor . first Value ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠĠĠĠĠ Ġbalance Presenter . on Detach () ĊĊĠĠĠĠĠĠĠ Ġverify ( blockchain Source ). remove Balance Observer ( balance Observer Captor . first Value , Ġtrue ) ĊĠĠĠĠĠĠĠ Ġverify ( order Repository ). remove Order Observer ( order Observer Captor . first Value ) ĊĠĠĠĠĠĠĠ ĠassertNull ( balance Presenter . view ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` update Ġbalance , Ġcheck Ġview Ġbeing Ġnotify Ġwith Ġthe Ġcorrect Ġvalue `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġbalance Ġ= ĠBalance () ĊĠĠĠĠĠĠĠ Ġbalance Observer Captor . first Value . on Changed ( balance ) ĊĠĠĠĠĠĠĠ Ġverify ( balance View ). update Balance ( 0 ) ĊĊĠĠĠĠĠĠĠ Ġbalance . amount Ġ= ĠBigDecimal ( 3 0 ) ĊĠĠĠĠĠĠĠ Ġbalance Observer Captor . first Value . on Changed ( balance ) ĊĠĠĠĠĠĠĠ Ġverify ( balance View ). update Balance ( 3 0 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` pending Ġorder Ġstart Ġbalance Ġloading Ġanimation , Ġstop Ġon Ġbalance Ġupdated `() Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( order . status ). thenReturn ( Order . Status . PENDING ) ĊĠĠĠĠĠĠĠ Ġorder Observer Captor . first Value . on Changed ( order ) ĊĠĠĠĠĠĠĠ Ġverify ( balance View ). start Loading Animation () ĊĊĠĠĠĠĠĠĠ Ġval Ġbalance Ġ= ĠBalance ( BigDecimal ( 3 0 )) ĊĠĠĠĠĠĠĠ Ġbalance Observer Captor . first Value . on Changed ( balance ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( order . status ). thenReturn ( Order . Status . COMPLETED ) ĊĠĠĠĠĠĠĠ Ġorder Observer Captor . first Value . on Changed ( order ) ĊĊĠĠĠĠĠĠĠ Ġverify ( balance View ). stop Loading Animation () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` pending Ġorder Ġstart Ġbalance Ġloading Ġanimation , Ġstop Ġon Ġorder Ġfailed `() Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( order . status ). thenReturn ( Order . Status . PENDING ) ĊĠĠĠĠĠĠĠ Ġorder Observer Captor . first Value . on Changed ( order ) ĊĠĠĠĠĠĠĠ Ġverify ( balance View ). start Loading Animation () ĊĊĊĠĠĠĠĠĠĠ Ġwhenever ( order . status ). thenReturn ( Order . Status . FAILED ) ĊĠĠĠĠĠĠĠ Ġorder Observer Captor . first Value . on Changed ( order ) ĊĠĠĠĠĠĠĠ Ġverify ( balance View ). stop Loading Animation () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` two Ġpending Ġorders Ġstart Ġbalance Ġloading Ġanimation , Ġstop Ġon Ġsecond Ġupdate `() Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( order . status ). thenReturn ( Order . Status . PENDING ) ĊĠĠĠĠĠĠĠ Ġorder Observer Captor . first Value . on Changed ( order ) ĊĠĠĠĠĠĠĠ Ġorder Observer Captor . first Value . on Changed ( order ) ĊĠĠĠĠĠĠĠ Ġverify ( balance View ). start Loading Animation () ĊĊĠĠĠĠĠĠĠ Ġval Ġbalance Ġ= ĠBalance ( BigDecimal ( 3 0 )) ĊĊĠĠĠĠĠĠĠ Ġ// ĠFirst Ġbalance Ġupdate Ġ- Ġshould ĠNOT Ġstop Ġanimation ĊĠĠĠĠĠĠĠ Ġbalance Observer Captor . first Value . on Changed ( balance ) ĊĠĠĠĠĠĠĠ Ġwhenever ( order . status ). thenReturn ( Order . Status . COMPLETED ) ĊĠĠĠĠĠĠĠ Ġorder Observer Captor . first Value . on Changed ( order ) ĊĠĠĠĠĠĠĠ Ġverify ( balance View , Ġnever ()). stop Loading Animation () ĊĊĠĠĠĠĠĠĠ Ġ// ĠSecond Ġbalance Ġupdate Ġ- Ġshould Ġstop Ġanimation ĊĠĠĠĠĠĠĠ Ġbalance Observer Captor . first Value . on Changed ( balance ) ĊĠĠĠĠĠĠĠ Ġwhenever ( order . status ). thenReturn ( Order . Status . COMPLETED ) ĊĠĠĠĠĠĠĠ Ġorder Observer Captor . first Value . on Changed ( order ) ĊĊĠĠĠĠĠĠĠ Ġverify ( balance View ). stop Loading Animation () ĊĠĠĠ Ġ} Ċ }