package Ġit . luc cap 1 1 . android . o zon o . repository Ċ Ċ import Ġit . luc cap 1 1 . android . o zon o . Cor outines Test Rule Ċ import Ġit . luc cap 1 1 . android . o zon o . TestUtil Ċ import Ġit . luc cap 1 1 . android . o zon o . model . data . City Ċ import Ġit . luc cap 1 1 . android . o zon o . model . data . Weather Data Ċ import Ġit . luc cap 1 1 . android . o zon o . network . O WM Remote DataSource Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . test . run Blocking Test Ċ import Ġorg . hamcrest . core . Is .` is ` Ċ import Ġorg . hamcrest . Matcher Assert . assertThat Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Assert . assertNot Equals Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . junit . runners . JUnit 4 Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito .* Ċ Ċ @ Experimental Cor outines Api Ċ @ RunWith ( JUnit 4 :: class ) Ċ class ĠWeather Data Repository Test Ġ{ ĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġvar Ġcor outines Test Rule Ġ= ĠCor outines Test Rule () ĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġprivate Ġval Ġremote Repository Ġ= Ġmock ( O WM Remote DataSource :: class . java ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfetch Weather Data By City Name _ null () Ġ= Ġcor outines Test Rule . test Dispatcher . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġ Ġmethod UnderTest Ġ= ĠWeather Data Repository ( remote Repository ) ĊĠĠĠĠĠĠĠ Ġ` when `( remote Repository . fetch O Weather Map Data ( any String ())). thenReturn ( null ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresults Ġ= Ġmethod UnderTest . fetch Weather Data By City Name (" L is bon a ") ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( null , Ġresults ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfetch Weather Data By City Name _ full () Ġ= Ġcor outines Test Rule . test Dispatcher . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġ Ġmethod UnderTest Ġ= ĠWeather Data Repository ( remote Repository ) ĊĠĠĠĠĠĠĠ Ġval Ġnow Ġ= ĠSystem . currentTimeMillis () ĊĠĠĠĠĠĠĠ Ġval Ġweather Data Ġ= ĠWeather Data ( listOf ( TestUtil (). mock Weather Data ( now )), ĠCity (" L is bon a ")) ĊĠĠĠĠĠĠĠ Ġ` when `( remote Repository . fetch O Weather Map Data ( any String ())). thenReturn ( weather Data ) ĊĊĠĠĠĠĠĠĠ Ġval Ġresults Ġ= Ġmethod UnderTest . fetch Weather Data By City Name (" L is bon a ") ĊĠĠĠĠĠĠĠ Ġverify ( remote Repository ). fetch O Weather Map Data (" L is bon a ") ĊĊĠĠĠĠĠĠĠ Ġassert Not Equals ( results , Ġnull ) ĊĠĠĠĠĠĠĠ ĠassertThat ( results ! ![ 0 ]. time In Secs , Ġ` is `( now )) ĊĠĠĠĠĠĠĠ ĠassertThat ( results [ 0 ]. weather [ 0 ]. icon , Ġ` is ` (" icon ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( results [ 0 ]. main . temp , Ġ` is `( 2 3 . 4 f )) ĊĠĠĠ Ġ} Ċ }