package Ġcom . zh eng . home Ċ Ċ import Ġcom . zh eng . home . common . TestData Factory Ċ import Ġcom . zh eng . home . data . DataManager Ċ import Ġcom . zh eng . home . data . model . Pokemon Ċ import Ġcom . zh eng . home . features . detail . Detail M vp View Ċ import Ġcom . zh eng . home . features . detail . Detail Presenter Ċ import Ġcom . zh eng . home . util . Rx Schedulers Override Rule Ċ import Ġio . reactivex . Single Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Argument Matchers . any Boolean Ċ import Ġorg . mockito . Argument Matchers . any String Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito .* Ċ import Ġorg . mockito . Mockito Annotations Ċ import Ġorg . mockito . junit . Mockito JUnit Runner Ċ Ċ @ RunWith ( Mockito JUnit Runner :: class ) Ċ class ĠDetail Presenter Test Ġ{ ĊĊĠĠĠ Ġ@ Mock Ġlateinit Ġvar Ġm Mock Detail M vp View : ĠDetail M vp View ĊĠĠĠ Ġ@ Mock Ġlateinit Ġvar Ġm Mock DataManager : ĠData Manager ĊĠĠĠ Ġprivate Ġvar Ġm Detail Presenter : ĠDetail Presenter ? Ġ= Ġnull ĊĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġ@ Rule Ġval Ġm Override Schedulers Rule Ġ= ĠRx Schedulers Override Rule () ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito Annotations . init Mocks ( this ) ĊĠĠĠĠĠĠĠ Ġm Detail Presenter Ġ= ĠDetail Presenter ( m Mock DataManager ) ĊĠĠĠĠĠĠĠ Ġm Detail Presenter ?. attach View ( m Mock Detail M vp View ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun ĠtearDown () Ġ{ ĊĠĠĠĠĠĠĠ Ġm Detail Presenter ?. detach View () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( Exception :: class ) ĊĠĠĠ Ġfun Ġget Pokemon Detail Returns Pokemon () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġpokemon Ġ= ĠTest Data Factory . make Pokemon (" id ") ĊĠĠĠĠĠĠĠ Ġ` when `( m Mock DataManager . get Pokemon ( any String ())) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. thenReturn ( Single . just ( pokemon )) ĊĊĠĠĠĠĠĠĠ Ġm Detail Presenter ?. get Pokemon ( any String ()) ĊĊĠĠĠĠĠĠĠ Ġverify < Detail M vp View >( m Mock Detail M vp View , Ġtimes ( 2 )). show Progress ( any Boolean ()) ĊĠĠĠĠĠĠĠ Ġverify < Detail M vp View >( m Mock Detail M vp View ). show Pokemon ( pokemon ) ĊĠĠĠĠĠĠĠ Ġverify < Detail M vp View >( m Mock Detail M vp View , Ġnever ()). show Error ( RuntimeException ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( Exception :: class ) ĊĠĠĠ Ġfun Ġget Pokemon Detail Returns Error () Ġ{ ĊĠĠĠĠĠĠĠ Ġ` when `( m Mock DataManager . get Pokemon (" id ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. thenReturn ( Single . error < Pokemon >( RuntimeException ())) ĊĊĠĠĠĠĠĠĠ Ġm Detail Presenter ?. get Pokemon (" id ") ĊĊĠĠĠĠĠĠĠ Ġverify < Detail M vp View >( m Mock Detail M vp View , Ġtimes ( 2 )). show Progress ( any Boolean ()) Ċ // ĠĠĠĠĠĠĠ Ġverify < Detail M vp View >( m Mock Detail M vp View ). show Error ( any ( Throwable :: class . java )) Ċ // ĠĠĠĠĠĠĠ Ġverify < Detail M vp View >( m Mock Detail M vp View , Ġnever ()). show Pokemon ( any ( Pokemon :: class . java )) ĊĠĠĠ Ġ} Ċ Ċ }