package Ġcom . g ary mc g ow an . mov i ep edia Ċ Ċ import Ġcom . g ary mc g ow an . mov i ep edia . model . Movie Ċ import Ġcom . g ary mc g ow an . mov i ep edia . model . Movie Repository Ċ import Ġcom . g ary mc g ow an . mov i ep edia . persistence . Stored Movie Dao Ċ import Ġcom . g ary mc g ow an . mov i ep edia . view . search . Movie List Contract Ċ import Ġcom . g ary mc g ow an . mov i ep edia . view . search . Movie List Presenter Ċ import Ġio . reactivex . Flow able Ċ import Ġio . reactivex . plugins . Rx Java Plugins Ċ import Ġio . reactivex . schedul ers . Schedulers Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito Ċ import Ġorg . mockito . Mockito .* Ċ import Ġorg . mockito . Mockito Annotations Ċ import Ġjava . util .* Ċ Ċ class ĠMovie List Presenter Test Ġ{ Ċ Ċ // ĠĠĠ Ġ@ Rule Ġvar Ġmock ito Rule Ġ= ĠMockito JUnit . rule () ĊĊĠĠĠ Ġ@ Mock Ġlateinit Ġvar Ġview : ĠMovie List Contract . View Ġ// TODO Ġtake Ġview ĊĠĠĠ Ġ@ Mock Ġlateinit Ġvar Ġmovie Repository : ĠMovie Repository ĊĠĠĠ Ġ@ Mock Ġlateinit Ġvar Ġstored Movie Dao : ĠStored Movie Dao ĊĠĠĠ Ġlateinit Ġvar Ġpresenter : ĠMovie List Presenter ĊĊĠĠĠ Ġprivate Ġval ĠTHREE _ MO VI ES Ġ= ĠArrays . asList ( Movie (), ĠMovie (), ĠMovie ()) ĊĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito Annotations . init Mocks ( this ) ĊĠĠĠĠĠĠĠ Ġpresenter Ġ= ĠMovie List Presenter ( movie Repository , Ġstored Movie Dao , ĠS chedulers . tr amp oline ()) ĊĠĠĠĠĠĠĠ ĠRx Java Plugins . set Io Scheduler Handler Ġ{ Ġscheduler Ġ-> ĠS chedulers . tr amp oline () Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ After ĊĠĠĠ Ġfun Ġclean Up () Ġ{ ĊĠĠĠĠĠĠĠ ĠRx Java Plugins . reset () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Pass Movies To View () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġ` when `( movie Repository . get Movie Search (" 1 2 3 ")). thenReturn ( Flow able . just ( TH REE _ MO VI ES )) ĊĊĠĠĠĠĠĠĠ Ġpresenter . set Search Term Observable ( Flow able . just (" 1 2 3 ")) ĊĊĠĠĠĠĠĠĠ Ġverify ( view ). display Movies ( TH REE _ MO VI ES ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Pass Movies To View Null () Ġ{ ĊĠĠĠĠĠĠĠ Ġ` when `( movie Repository . get Movie Search (" 1 2 3 ")). thenReturn ( null ) ĊĊĠĠĠĠĠĠĠ Ġpresenter . set Search Term Observable ( Flow able . just (" 1 2 3 ")) ĊĊĠĠĠĠĠĠĠ Ġverify ( view ). display Error ( Mockito . any String ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Pass Movies To View Empty () Ġ{ ĊĠĠĠĠĠĠĠ Ġ` when `( movie Repository . get Movie Search (" 1 2 3 ")). thenReturn ( Flow able . just < List < Movie >>( emptyList ())) ĊĊĠĠĠĠĠĠĠ Ġpresenter . set Search Term Observable ( Flow able . just (" 1 2 3 ")) ĊĊĠĠĠĠĠĠĠ Ġverify ( view ). display Movies ( emptyList ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Handle Exception () Ġ{ ĊĠĠĠĠĠĠĠ Ġ` when `( movie Repository . get Movie Search (" 1 2 3 ")). then Throw ( RuntimeException (" Something Ġwhen Ġwrong ")) ĊĊĠĠĠĠĠĠĠ Ġpresenter . set Search Term Observable ( Flow able . just (" 1 2 3 ")) ĊĊĠĠĠĠĠĠĠ Ġverify ( view ). display Error ( Mockito . any String ()) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmultiple Requests () Ġ{ ĊĠĠĠĠĠĠĠ Ġ` when `( movie Repository . get Movie Search ( Mockito . any String ())). thenReturn ( Flow able . just ( TH REE _ MO VI ES )) ĊĊĠĠĠĠĠĠĠ Ġpresenter . set Search Term Observable ( Flow able . just (" t ", Ġ" ta ", Ġ" tak ", Ġ" take ", Ġ" taken ")) ĊĊĠĠĠĠĠĠĠ Ġverify ( view , Ġtimes ( 5 )). display Movies ( TH REE _ MO VI ES ) ĊĠĠĠ Ġ} Ċ }