package Ġcom . dam ian ch od ore k . ren sh ired ux . controller Ċ Ċ import Ġcom . dam ian ch od ore k . ren shi . store . Store Ċ import Ġcom . dam ian ch od ore k . ren sh ired ux . Contract . Interactor . Make Api Call Interactor Ċ import Ġcom . dam ian ch od ore k . ren sh ired ux . Contract . Plugin . Make Api Call Btn Fragment Plugin Ċ import Ġcom . dam ian ch od ore k . ren sh ired ux . action . Finish ing Api Call Action Ċ import Ġcom . dam ian ch od ore k . ren sh ired ux . action . M aking Api Call Action Ċ import Ġcom . dam ian ch od ore k . ren sh ired ux . store . MainActivity Store Ċ import Ġcom . dam ian ch od ore k . ren sh ired ux . utils . Rx Test Rule Ċ import Ġcom . n ha ar man . mockito _ kotlin .* Ċ import Ġio . reactivex . Comp letable Ċ import Ġio . reactivex . subjects . Comp letable Subject Ċ import Ġio . reactivex . subjects . Publish Subject Ċ import Ġorg . hamcrest . Core Matchers . equalTo Ċ import Ġorg . hamcrest . Matcher Assert . assertThat Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ Ċ /** Ċ Ġ* Ġ@ author ĠD am ian ĠCh od ore k Ċ Ġ*/ Ċ class ĠMake Api Call Controller Impl Test Ġ{ ĊĊĠĠĠ Ġ@ Suppress (" unused ") ĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġrx Rule Ġ= ĠRx Test Rule () ĊĊĠĠĠ Ġprivate Ġval Ġclicks Ġ= ĠPublish Subject . create < Unit >() ĊĠĠĠ Ġprivate Ġval Ġplugin Mock Ġ= Ġmock < Make Api Call Btn Fragment Plugin >(). apply Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( make Api Call Click s ). thenReturn ( click s ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġprivate Ġval Ġstore Mock Ġ= Ġmock < Store <* >> (). apply Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( dispatch ( any ())). thenReturn ( Comp letable . complete ()) ĊĠĠĠ Ġ} ĊĠĠĠ Ġprivate Ġval Ġapi Call Subject Ġ= ĠComp letable Subject . create () ĊĠĠĠ Ġprivate Ġval Ġinter actor Mock Ġ= Ġmock < Make Api Call Interactor >(). apply Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( make Fake Api Call ()). thenReturn ( api Call Subject ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġprivate Ġval Ġlog Mock Ġ= Ġmock <( Throwable ) Ġ-> ĠUnit >() ĊĠĠĠ Ġprivate Ġval Ġcontroller Ġ= ĠMake Api Call Controller Impl ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinter actor Mock , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlog Mock ĊĠĠĠ Ġ). apply Ġ{ ĊĠĠĠĠĠĠĠ Ġset Store Ref ( store Mock ) ĊĠĠĠĠĠĠĠ Ġset Plugin Ref ( plugin Mock ) ĊĠĠĠĠĠĠĠ Ġon Attach Plugin () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġinit _ does Nothing With Plugin () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġplugin Mock Ġ= Ġmock < Make Api Call Btn Fragment Plugin >() ĊĊĠĠĠĠĠĠĠ ĠMake Api Call Controller Impl (). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġset Store Ref ( mock ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġset Plugin Ref ( plugin Mock ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġverify Zero Interactions ( plugin Mock ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġinit _ does Nothing With Store () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġstore Mock Ġ= Ġmock < MainActivity Store >() ĊĊĠĠĠĠĠĠĠ ĠMake Api Call Controller Impl (). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġset Store Ref ( store Mock ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġset Plugin Ref ( mock ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġverify Zero Interactions ( store Mock ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġon Attach Plugin _ ob serves Click s () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( click s . has Observer s (), ĠequalTo ( true )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġon Attach Plugin _ dis poses Click s Stream _ on Detach () Ġ{ ĊĠĠĠĠĠĠĠ Ġcontroller . on Detach Plugin () ĊĠĠĠĠĠĠĠ ĠassertThat ( click s . has Observer s (), ĠequalTo ( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmake Api Call Click s _ dis patches M aking Api Call Action () Ġ{ ĊĠĠĠĠĠĠĠ Ġemit Click () ĊĠĠĠĠĠĠĠ Ġverify ( store Mock ). dispatch ( any < M aking Api Call Action >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġemit Click () Ġ= Ġclicks . onNext ( Unit ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmake Api Call Click s _ dis patches M aking Api Call Action _ when Clicked Many Times () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġclicks Count Ġ= Ġemit Click s () ĊĠĠĠĠĠĠĠ Ġverify ( store Mock , Ġtimes ( click s Count )). dispatch ( any < M aking Api Call Action >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġemit Click s (): ĠInt Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġclicks Count Ġ= Ġ 5 ĊĊĠĠĠĠĠĠĠ Ġrepeat ( click s Count ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġemit Click () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġclicks Count ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmake Api Call Click s _ m akes Api Call () Ġ{ ĊĠĠĠĠĠĠĠ Ġemit Click () ĊĠĠĠĠĠĠĠ ĠassertThat ( api Call Subject . has Observer s (), ĠequalTo ( true )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġon Attach Plugin _ does Not Dispose Api Stream On Detach _ when Clicked () Ġ{ ĊĠĠĠĠĠĠĠ Ġemit Click () ĊĊĠĠĠĠĠĠĠ Ġcontroller . on Detach Plugin () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( api Call Subject . has Observer s (), ĠequalTo ( true )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġon Attach Plugin _ dis poses Api Stream On Destroy _ when Clicked () Ġ{ ĊĠĠĠĠĠĠĠ Ġemit Click () ĊĊĠĠĠĠĠĠĠ Ġcontroller . on Destroy () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( api Call Subject . has Observer s (), ĠequalTo ( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmake Api Call Click s _ m akes Api Call _ when Clicked Many Times () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġclicks Count Ġ= Ġemit Click s () ĊĠĠĠĠĠĠĠ Ġverify ( inter actor Mock , Ġtimes ( click s Count )). make Fake Api Call () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmake Api Call Click s _ dis patches Finish ing Api Call Action () Ġ{ ĊĠĠĠĠĠĠĠ Ġemit Click () ĊĠĠĠĠĠĠĠ Ġverify ( store Mock ). dispatch ( any < Finish ing Api Call Action >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmake Api Call Click s _ dis patches Finish ing Api Call Action _ when Clicked Many Times () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġclicks Count Ġ= Ġemit Click s () ĊĠĠĠĠĠĠĠ Ġverify ( store Mock , Ġtimes ( click s Count )). dispatch ( any < Finish ing Api Call Action >()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmake Api Call Click s _ logs Error _ when Error Occurs During Api Call () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġruntime Exception Ġ= ĠRuntimeException () ĊĠĠĠĠĠĠĠ Ġwhenever ( inter actor Mock . make Fake Api Call ()). thenReturn ( Comp letable . error ( runtime Exception )) ĊĊĠĠĠĠĠĠĠ Ġemit Click () ĊĊĠĠĠĠĠĠĠ Ġverify ( log Mock ). invoke ( runtime Exception ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmake Api Call Click s _ logs Error _ when Error Occurs During Click () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġruntime Exception Ġ= ĠRuntimeException () ĊĊĠĠĠĠĠĠĠ Ġclicks . onError ( runtime Exception ) ĊĊĠĠĠĠĠĠĠ Ġverify ( log Mock ). invoke ( runtime Exception ) ĊĠĠĠ Ġ} Ċ }