package Ġcom . la qu y soft . cle ang it app . use case . user Ċ Ċ import Ġcom . n ha ar man . mockito _ kotlin . mock Ċ import Ġcom . n ha ar man . mockito _ kotlin . verify Ċ import Ġcom . n ha ar man . mockito _ kotlin . wh enever Ċ import Ġio . reactivex . Flow able Ċ import Ġcom . la qu y soft . cle ang it app . domain . executor . Post Execution Thread Ċ import Ġcom . la qu y soft . cle ang it app . domain . executor . Thread Executor Ċ import Ġcom . la qu y soft . cle ang it app . domain . inter actor . browse . Get Users Ċ import Ġcom . la qu y soft . cle ang it app . domain . model . User Ċ import Ġcom . la qu y soft . cle ang it app . domain . repository . UserRepository Ċ import Ġcom . la qu y soft . cle ang it app . domain . test . factory . User Factory Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ Ċ class ĠGet Users Test Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġget Users : ĠGet Users ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmock Thread Executor : ĠThread Executor ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmock Post Execution Thread : ĠPost Execution Thread ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmock UserRepository : ĠUser Repository ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġmock Thread Executor Ġ= Ġmock () ĊĠĠĠĠĠĠĠ Ġmock Post Execution Thread Ġ= Ġmock () ĊĠĠĠĠĠĠĠ Ġmock UserRepository Ġ= Ġmock () ĊĠĠĠĠĠĠĠ Ġget Users Ġ= ĠGet Users ( mock UserRepository , Ġmock Thread Executor , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġmock Post Execution Thread ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbuild UseCase Observable Calls Repository () Ġ{ ĊĠĠĠĠĠĠĠ Ġget Users . build UseCase Observable ( null ) ĊĠĠĠĠĠĠĠ Ġverify ( mock UserRepository ). get Users () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbuild UseCase Observable Comp letes () Ġ{ ĊĠĠĠĠĠĠĠ Ġstub UserRepository Get Users ( Flow able . just ( User Factory . make UserList ( 2 ))) ĊĠĠĠĠĠĠĠ Ġval Ġtest Observer Ġ= Ġget Users . build UseCase Observable ( null ). test () ĊĠĠĠĠĠĠĠ Ġtest Observer . assert Complete () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġbuild UseCase Observable Returns Data () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġusers Ġ= ĠUser Factory . make UserList ( 2 ) ĊĠĠĠĠĠĠĠ Ġstub UserRepository Get Users ( Flow able . just ( users )) ĊĠĠĠĠĠĠĠ Ġval Ġtest Observer Ġ= Ġget Users . build UseCase Observable ( null ). test () ĊĠĠĠĠĠĠĠ Ġtest Observer . assert Value ( users ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġstub UserRepository Get Users ( single : ĠFlow able < List < User >>) Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( mock UserRepository . get Users ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. thenReturn ( single ) ĊĠĠĠ Ġ} Ċ Ċ } Ċ