package Ġcom . gu il her me hol z . where isl unch . domain Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . SharedPreferences Ċ import Ġandroid . location . Location Ċ import Ġcom . gu il her me hol z . where isl unch . domain . datasource . Rest aurants DataSource Ċ import Ġcom . gu il her me hol z . where isl unch . domain . model . Restaurant Ċ import Ġcom . gu il her me hol z . where isl unch . domain . model . Restaurant Detail Ċ import Ġcom . gu il her me hol z . where isl unch . utils . Date Manager Ċ 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 Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito Annotations Ċ import Ġorg . ro bo lectric . f akes . Ro bo SharedPreferences Ċ import Ġrx . Observable Ċ Ċ class ĠRest aurants Repository Test Ġ{ ĊĊĠĠĠ Ġ@ Mock Ġlateinit Ġvar ĠdataSource : ĠRest aurants DataSource ĊĠĠĠ Ġ@ Mock Ġlateinit Ġvar Ġdate Manager : ĠDate Manager ĊĠĠĠ Ġlateinit Ġvar Ġpreferences : ĠSharedPreferences ĊĠĠĠ Ġlateinit Ġvar Ġrepository : ĠRest aurants Repository ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ ĠMockito Annotations . init Mocks ( this ) ĊĠĠĠĠĠĠĠ Ġpreferences Ġ= ĠRo bo SharedPreferences ( mutable Map Of (), Ġ" content ", ĠContext . MODE _ PRIVATE ) ĊĠĠĠĠĠĠĠ Ġrepository Ġ= ĠRest aurants Repository ( dataSource , Ġdate Manager , Ġpreferences ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Route Get Rest aurants () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlocation Ġ= ĠLocation ("") ĊĠĠĠĠĠĠĠ Ġval Ġexpected Result Ġ= ĠObservable . just < List < Restaurant >>( listOf ()) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( dataSource . get Rest aurants ( location , Ġ"")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. thenReturn ( expected Result ) ĊĠĠĠĠĠĠĠ Ġwhenever ( date Manager . getCurrent Date ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. thenReturn ("") ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġrepository . get Rest aurants ( location ) ĊĠĠĠĠĠĠĠ Ġverify ( dataSource ). get Rest aurants ( location , Ġ"") ĊĠĠĠĠĠĠĠ Ġassert ( result Ġ== Ġexpected Result ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Route Get Restaurant () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġexpected Result Ġ= ĠObservable . just < Restaurant Detail >( mock ()) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( dataSource . get Restaurant ("", Ġ" ")). thenReturn ( expected Result ) ĊĠĠĠĠĠĠĠ Ġwhenever ( date Manager . getCurrent Date ()). thenReturn ("") ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġrepository . get Restaurant ("") ĊĠĠĠĠĠĠĠ Ġverify ( dataSource ). get Restaurant ("", Ġ"") ĊĠĠĠĠĠĠĠ Ġassert ( result Ġ== Ġexpected Result ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Route Get Winner () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġexpected Result Ġ= ĠObservable . just < Restaurant Detail >( mock ()) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( dataSource . get Winner (" ")). thenReturn ( expected Result ) ĊĠĠĠĠĠĠĠ Ġwhenever ( date Manager . getCurrent Date ()). thenReturn ("") ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġrepository . get Winner () ĊĠĠĠĠĠĠĠ Ġverify ( dataSource ). get Winner ("") ĊĠĠĠĠĠĠĠ Ġassert ( result Ġ== Ġexpected Result ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Route Vote () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdetail Ġ= ĠRest aurant Detail ("", Ġ"", Ġ"", Ġ"", Ġ 0 f , Ġ"", Ġ 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġexpected Result Ġ= ĠObservable . just < Restaurant Detail >( mock ()) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( dataSource . vote ("", Ġ" ")). thenReturn ( expected Result ) ĊĠĠĠĠĠĠĠ Ġwhenever ( date Manager . getCurrent Date ()). thenReturn ("") ĊĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġrepository . vote ( detail ) ĊĠĠĠĠĠĠĠ Ġverify ( dataSource ). vote ("", Ġ"") ĊĠĠĠĠĠĠĠ Ġassert ( result Ġ== Ġexpected Result ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Return Closed After Mid Day () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( date Manager . is After Mid Day ()). thenReturn ( true ) ĊĠĠĠĠĠĠĠ Ġassert ( repository . is V oting Closed ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġshould Return Open Before Mid Day () Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( date Manager . is After Mid Day ()). thenReturn ( false ) ĊĠĠĠĠĠĠĠ Ġassert (! repository . is V oting Closed ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcan Vote Should Return False After Vote () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdetail Ġ= ĠRest aurant Detail (" id ", Ġ"", Ġ"", Ġ"", Ġ 0 f , Ġ"", Ġ 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġexpected Result Ġ= ĠObservable . just < Restaurant Detail >( mock ()) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( dataSource . vote (" id ", Ġ" 0 0 _ 0 0 _ 0 0 0 0 ")). thenReturn ( expected Result ) ĊĠĠĠĠĠĠĠ Ġwhenever ( date Manager . getCurrent Date ()). thenReturn (" 0 0 _ 0 0 _ 0 0 0 0 ") ĊĠĠĠĠĠĠĠ Ġwhenever ( date Manager . is After Mid Day ()). thenReturn ( false ) ĊĊĠĠĠĠĠĠĠ Ġrepository . vote ( detail ) ĊĊĠĠĠĠĠĠĠ Ġassert (! repository . can Vote (" id ")) ĊĠĠĠ Ġ} Ċ }