package Ġcom . shop app . ui . address . base . contract Ċ Ċ import Ġcom . n ha ar man . mockito _ kotlin .* Ċ import Ġcom . shop app . R Ċ import Ġcom . shop app . domain . inter actor . account . Create Customer Address UseCase Ċ import Ġcom . shop app . domain . inter actor . account . Edit Customer Address UseCase Ċ import Ġcom . shop app . domain . inter actor . account . Get Countries UseCase Ċ import Ġcom . shop app . domain . validator . Field Validator Ċ import Ġcom . shop app . gateway . entity . Address Ċ import Ġcom . shop app . gateway . entity . Country Ċ import Ġcom . shop app . gateway . entity . Error Ċ import Ġcom . shop app . test . Mock Instanti ator Ċ import Ġcom . shop app . test . Rx Immediate Scheduler Rule Ċ import Ġcom . shop app . test . ext . mock Ċ import Ġio . reactivex . Comp letable Ċ import Ġio . reactivex . Single Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Assert . assertTrue Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito Annotations Ċ Ċ class ĠAddress Presenter Test Ġ{ ĊĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġvar Ġtest Scheduler Rule Ġ= ĠRx Immediate Scheduler Rule () ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġview : ĠAddress View ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġfield Validator : ĠField Validator ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcountries UseCase : ĠGet Countries UseCase ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcreate Customer Address UseCase : ĠCreate Customer Address UseCase ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġedit Customer Address UseCase : ĠEdit Customer Address UseCase ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġaddress : ĠAddress ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġcountry List : ĠList < Country > ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġpresenter : ĠAddress Presenter < Address View > ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp Test () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito Annotations . init Mocks ( this ) ĊĠĠĠĠĠĠĠ Ġpresenter Ġ= ĠAddress Presenter ( field Validator , Ġcountries UseCase , Ġcreate Customer Address UseCase , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġedit Customer Address UseCase ) ĊĠĠĠĠĠĠĠ Ġpresenter . attach View ( view ) ĊĊĠĠĠĠĠĠĠ Ġcountries UseCase . mock () ĊĠĠĠĠĠĠĠ Ġcreate Customer Address UseCase . mock () ĊĠĠĠĠĠĠĠ Ġedit Customer Address UseCase . mock () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsubmit Address Should Show Error When Submit Invalid Address () Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven ( field Validator . is Address Valid ( any ())). willReturn ( false ) ĊĠĠĠĠĠĠĠ Ġpresenter . submit Address ( address ) ĊĊĠĠĠĠĠĠĠ Ġval Ġin Order Ġ= Ġin Order ( view ) ĊĠĠĠĠĠĠĠ Ġin Order . verify ( view ). submit Address Error () ĊĠĠĠĠĠĠĠ Ġin Order . verify ( view ). showMessage ( R . string . invalid _ address ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsubmit Address Should Call Address Changed When On Single Success () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġ" result " ĊĠĠĠĠĠĠĠ Ġgiven ( create Customer Address UseCase . build UseCase Single ( any ())). willReturn ( Single . just ( result )) ĊĠĠĠĠĠĠĠ Ġgiven ( field Validator . is Address Valid ( any ())). willReturn ( true ) ĊĠĠĠĠĠĠĠ Ġpresenter . submit Address ( address ) ĊĊĠĠĠĠĠĠĠ Ġval Ġin Order Ġ= Ġin Order ( view , Ġcreate Customer Address UseCase ) ĊĠĠĠĠĠĠĠ Ġin Order . verify ( create Customer Address UseCase ). execute ( any (), Ġany (), Ġeq ( address )) ĊĠĠĠĠĠĠĠ Ġin Order . verify ( view ). address Changed ( address ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsubmit Address Should Call Address Changed When On Single Content Error () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġerror Ġ= ĠError . Content () ĊĠĠĠĠĠĠĠ Ġgiven ( create Customer Address UseCase . build UseCase Single ( any ())). willReturn ( Single . error ( error )) ĊĠĠĠĠĠĠĠ Ġgiven ( field Validator . is Address Valid ( any ())). willReturn ( true ) ĊĠĠĠĠĠĠĠ Ġpresenter . submit Address ( address ) ĊĊĠĠĠĠĠĠĠ Ġargument Captor < Error >(). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġin Order Ġ= Ġin Order ( view , Ġcreate Customer Address UseCase ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġin Order . verify ( create Customer Address UseCase ). execute ( any (), Ġany (), Ġeq ( address )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġin Order . verify ( view ). show Error ( capture ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġin Order . verify ( view ). address Changed ( address ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertTrue ( first Value Ġis ĠError . Content ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsubmit Address Should Call Address Changed When On Single Non Critical Error () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġ" message " ĊĠĠĠĠĠĠĠ Ġval Ġerror Ġ= ĠError . Non Critical ( message ) ĊĠĠĠĠĠĠĠ Ġgiven ( create Customer Address UseCase . build UseCase Single ( any ())). willReturn ( Single . error ( error )) ĊĠĠĠĠĠĠĠ Ġgiven ( field Validator . is Address Valid ( any ())). willReturn ( true ) ĊĠĠĠĠĠĠĠ Ġpresenter . submit Address ( address ) ĊĊĠĠĠĠĠĠĠ Ġval Ġin Order Ġ= Ġin Order ( view , Ġcreate Customer Address UseCase ) ĊĠĠĠĠĠĠĠ Ġin Order . verify ( create Customer Address UseCase ). execute ( any (), Ġany (), Ġeq ( address )) ĊĠĠĠĠĠĠĠ Ġin Order . verify ( view ). showMessage ( message ) ĊĠĠĠĠĠĠĠ Ġin Order . verify ( view ). address Changed ( address ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġedit Address Should Show Error When Edit Invalid Address () Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven ( field Validator . is Address Valid ( any ())). willReturn ( false ) ĊĠĠĠĠĠĠĠ Ġpresenter . edit Address ( Mock Instanti ator . DEFAULT _ ID , Ġaddress ) ĊĊĠĠĠĠĠĠĠ Ġval Ġin Order Ġ= Ġin Order ( view ) ĊĠĠĠĠĠĠĠ Ġin Order . verify ( view ). submit Address Error () ĊĠĠĠĠĠĠĠ Ġin Order . verify ( view ). showMessage ( R . string . invalid _ address ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġedit Address Should Call Address Changed When On Comp letable Success () Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven ( edit Customer Address UseCase . build UseCase Comp letable ( any ())). willReturn ( Comp letable . complete ()) ĊĠĠĠĠĠĠĠ Ġgiven ( field Validator . is Address Valid ( any ())). willReturn ( true ) ĊĠĠĠĠĠĠĠ Ġpresenter . edit Address ( Mock Instanti ator . DEFAULT _ ID , Ġaddress ) ĊĊĠĠĠĠĠĠĠ Ġargument Captor < Edit Customer Address UseCase . Params >(). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġin Order Ġ= Ġin Order ( view , Ġedit Customer Address UseCase ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġin Order . verify ( edit Customer Address UseCase ). execute ( any (), Ġany (), Ġcapture ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġin Order . verify ( view ). address Changed ( address ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( Mock Instanti ator . DEFAULT _ ID , Ġfirst Value . address Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( address , Ġfirst Value . address ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġedit Address Should Call Address Changed When On Comp letable Content Error () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġerror Ġ= ĠError . Content () ĊĠĠĠĠĠĠĠ Ġgiven ( edit Customer Address UseCase . build UseCase Comp letable ( any ())). willReturn ( Comp letable . error ( error )) ĊĠĠĠĠĠĠĠ Ġgiven ( field Validator . is Address Valid ( any ())). willReturn ( true ) ĊĠĠĠĠĠĠĠ Ġpresenter . edit Address ( Mock Instanti ator . DEFAULT _ ID , Ġaddress ) ĊĊĊĠĠĠĠĠĠĠ Ġval Ġin Order Ġ= Ġin Order ( view , Ġedit Customer Address UseCase ) ĊĠĠĠĠĠĠĠ Ġargument Captor < Edit Customer Address UseCase . Params >(). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġin Order . verify ( edit Customer Address UseCase ). execute ( any (), Ġany (), Ġcapture ()) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( Mock Instanti ator . DEFAULT _ ID , Ġfirst Value . address Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( address , Ġfirst Value . address ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġargument Captor < Error >(). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġin Order . verify ( view ). show Error ( capture ()) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertTrue ( first Value Ġis ĠError . Content ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġin Order . verify ( view ). address Changed ( address ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġedit Address Should Call Address Changed When On Comp letable Non Critical Error () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġ" message " ĊĠĠĠĠĠĠĠ Ġval Ġerror Ġ= ĠError . Non Critical ( message ) ĊĠĠĠĠĠĠĠ Ġgiven ( edit Customer Address UseCase . build UseCase Comp letable ( any ())). willReturn ( Comp letable . error ( error )) ĊĠĠĠĠĠĠĠ Ġgiven ( field Validator . is Address Valid ( any ())). willReturn ( true ) ĊĠĠĠĠĠĠĠ Ġpresenter . edit Address ( Mock Instanti ator . DEFAULT _ ID , Ġaddress ) ĊĊĠĠĠĠĠĠĠ Ġargument Captor < Edit Customer Address UseCase . Params >(). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġin Order Ġ= Ġin Order ( view , Ġedit Customer Address UseCase ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġin Order . verify ( edit Customer Address UseCase ). execute ( any (), Ġany (), Ġcapture ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġin Order . verify ( view ). showMessage ( message ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġin Order . verify ( view ). address Changed ( address ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( Mock Instanti ator . DEFAULT _ ID , Ġfirst Value . address Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( address , Ġfirst Value . address ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Countries List Should Call Countries Loaded () Ġ{ ĊĠĠĠĠĠĠĠ Ġgiven ( countries UseCase . build UseCase Single ( any ())). willReturn ( Single . just ( country List )) ĊĠĠĠĠĠĠĠ Ġpresenter . getCount ries List () ĊĊĠĠĠĠĠĠĠ Ġval Ġin Order Ġ= Ġin Order ( view , Ġcountries UseCase ) ĊĠĠĠĠĠĠĠ Ġin Order . verify ( countries UseCase ). execute ( any (), Ġany (), Ġany ()) ĊĠĠĠĠĠĠĠ Ġin Order . verify ( view ). countries Loaded ( country List ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Countries List Call Address Changed When On Single Content Error () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġerror Ġ= ĠError . Content () ĊĠĠĠĠĠĠĠ Ġgiven ( countries UseCase . build UseCase Single ( any ())). willReturn ( Single . error ( error )) ĊĠĠĠĠĠĠĠ Ġpresenter . getCount ries List () ĊĊĠĠĠĠĠĠĠ Ġargument Captor < Error >(). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġin Order Ġ= Ġin Order ( view , Ġcountries UseCase ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġin Order . verify ( countries UseCase ). execute ( any (), Ġany (), Ġany ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġin Order . verify ( view ). show Error ( capture ()) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertTrue ( first Value Ġis ĠError . Content ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Countries List Call Address Changed When On Single Non Critical Error () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmessage Ġ= Ġ" message " ĊĠĠĠĠĠĠĠ Ġval Ġerror Ġ= ĠError . Non Critical ( message ) ĊĠĠĠĠĠĠĠ Ġgiven ( countries UseCase . build UseCase Single ( any ())). willReturn ( Single . error ( error )) ĊĠĠĠĠĠĠĠ Ġpresenter . getCount ries List () ĊĊĠĠĠĠĠĠĠ Ġval Ġin Order Ġ= Ġin Order ( view , Ġcountries UseCase ) ĊĠĠĠĠĠĠĠ Ġin Order . verify ( countries UseCase ). execute ( any (), Ġany (), Ġany ()) ĊĠĠĠĠĠĠĠ Ġin Order . verify ( view ). showMessage ( message ) ĊĠĠĠ Ġ} Ċ }