package Ġio . github . to by hs . weather weight . data Ċ Ċ import Ġio . github . to by hs . weather weight . api . acc u weather . Acc u Weather Service Ċ import Ġio . github . to by hs . weather weight . api . acc u weather . forecast s . Daily Forecast Ċ import Ġio . github . to by hs . weather weight . api . acc u weather . forecast s . Daily Forecast Response Ċ import Ġio . github . to by hs . weather weight . api . acc u weather . forecast s . Day Period Ċ import Ġio . github . to by hs . weather weight . api . acc u weather . forecast s . Temperature Ċ import Ġio . github . to by hs . weather weight . api . acc u weather . forecast s . Temperature Range Ċ import Ġio . github . to by hs . weather weight . api . acc u weather . locations . Administr ative Area Ċ import Ġio . github . to by hs . weather weight . api . acc u weather . locations . City Ċ import Ġio . github . to by hs . weather weight . api . acc u weather . locations . Country Ċ Ċ import Ġio . reactivex . rx java 3 . core . Single Ċ Ċ import Ġorg . hamcrest . Core Matchers . equalTo Ċ import Ġorg . hamcrest . Matcher Assert . assertThat Ċ Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ Ċ import Ġorg . mockito . Mockito Ċ import Ġorg . mockito . Mockito . mock Ċ Ċ import Ġorg . th reet en . bp . Clock Ċ import Ġorg . th reet en . bp . Z onedDateTime Ċ import Ġorg . th reet en . bp . temporal . Ch rono Unit Ċ Ċ import Ġretrofit 2 . Response Ċ Ċ class ĠAcc u Weather Repository Test Ġ{ ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġacc u Weather Service : ĠAcc u Weather Service ĊĠĠĠ Ġprivate Ġval Ġclock Ġ= ĠClock . system UTC () ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġrepository : ĠAcc u Weather Repository ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġacc u Weather Service Ġ= Ġmock ( Acc u Weather Service :: class . java ) ĊĠĠĠĠĠĠĠ Ġrepository Ġ= ĠAcc u Weather Repository ( acc u Weather Service , Ġclock ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Forecast _ location NotFound () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcities Response Ġ= ĠResponse . success < List < City >>( emptyList ()) ĊĠĠĠĠĠĠĠ Ġval Ġcities Single Ġ= ĠSingle . just ( cities Response ) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( acc u Weather Service . search C ities (" Now here , ĠUSA ", Ġ 0 )). thenReturn ( cities Single ) ĊĊĠĠĠĠĠĠĠ Ġval Ġobserver Ġ= Ġrepository . get Forecast (" Now here , ĠUSA "). test () ĊĠĠĠĠĠĠĠ Ġobserver . assert Error ( Location NotFoundError :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Forecast () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcities : ĠMutable List < City > Ġ= Ġmutable ListOf () ĊĠĠĠĠĠĠĠ Ġcities . add ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠCity . builder () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Key (" 1 2 3 4 5 6 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Localized Name (" San ĠJose ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Administr ative Area ( Administr ative Area . builder (). setId (" CA "). build ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Country ( Country . builder (). setId (" US "). build ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġcities . add ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠCity . builder () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Key (" 4 3 2 1 6 5 ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Localized Name (" San ĠJose ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Administr ative Area ( Administr ative Area . builder (). setId (" SJ "). build ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Country ( Country . builder (). setId (" CR "). build ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġcities Single Ġ= ĠSingle . just ( Response . success < List < City >>( cities )) ĊĠĠĠĠĠĠĠ ĠMockito .` when `( acc u Weather Service . search C ities (" San ĠJose ", Ġ 0 )). thenReturn ( cities Single ) ĊĊĠĠĠĠĠĠĠ Ġval Ġtime Ġ= ĠZ onedDateTime . parse (" 2 0 1 8 - 0 1 - 2 9 T 1 2 : 0 0 : 0 0 Z ") ĊĠĠĠĠĠĠĠ Ġval Ġdaily Forecast s : ĠMutable List < Daily Forecast > Ġ= Ġmutable ListOf () ĊĠĠĠĠĠĠĠ Ġvar Ġtemperature Range Ġ= ĠTemperature Range . builder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. setMinimum ( Temperature . builder (). setValue ( 5 0 . 0 ). build ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. setMaximum ( Temperature . builder (). setValue ( 6 0 . 0 ). build ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠĠĠĠĠ Ġdaily Forecast s . add ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠDaily Forecast . builder () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. setDate ( time ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Temperature ( temperature Range ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Day ( Day Period . builder (). setIcon Phrase (" Sun ny "). build ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Night ( Day Period . builder (). setIcon Phrase (" Sun ny "). build ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġtemperature Range Ġ= ĠTemperature Range . builder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. setMinimum ( Temperature . builder (). setValue ( 5 2 . 0 ). build ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. setMaximum ( Temperature . builder (). setValue ( 6 2 . 0 ). build ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠĠĠĠĠ Ġdaily Forecast s . add ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠDaily Forecast . builder () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. setDate ( time . plus Days ( 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Temperature ( temperature Range ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Day ( Day Period . builder (). setIcon Phrase (" Cloud y "). build ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Night ( Day Period . builder (). setIcon Phrase (" Show ers "). build ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= ĠDaily Forecast Response . builder () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. set Daily Forecast s ( daily Forecast s ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠĠĠĠĠ ĠMockito .` when `( acc u Weather Service . get 5 Day Forecast (" 1 2 3 4 5 6 ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. thenReturn ( Single . just ( Response . success ( response ))) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġrepository . get Forecast (" San ĠJose "). blocking Get () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( result . location , ĠequalTo (" San ĠJose , ĠCA , ĠUS ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġresult . publication Time . until ( Z onedDateTime . now ( clock ), ĠCh rono Unit . MIN UTES ), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠequalTo ( 0 L ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . forecast s . size , ĠequalTo ( 2 )) ĊĊĠĠĠĠĠĠĠ Ġvar Ġdaily Forecast Ġ= Ġresult . forecast s [ 0 ] ĊĠĠĠĠĠĠĠ ĠassertThat ( daily Forecast . date . toString (), ĠequalTo (" 2 0 1 8 - 0 1 - 2 9 ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( daily Forecast . low , ĠequalTo ( 5 0 )) ĊĠĠĠĠĠĠĠ ĠassertThat ( daily Forecast . high , ĠequalTo ( 6 0 )) ĊĠĠĠĠĠĠĠ ĠassertThat ( daily Forecast . text , ĠequalTo (" Sun ny ")) ĊĊĠĠĠĠĠĠĠ Ġdaily Forecast Ġ= Ġresult . forecast s [ 1 ] ĊĠĠĠĠĠĠĠ ĠassertThat ( daily Forecast . date . toString (), ĠequalTo (" 2 0 1 8 - 0 1 - 3 0 ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( daily Forecast . low , ĠequalTo ( 5 2 )) ĊĠĠĠĠĠĠĠ ĠassertThat ( daily Forecast . high , ĠequalTo ( 6 2 )) ĊĠĠĠĠĠĠĠ ĠassertThat ( daily Forecast . text , ĠequalTo (" Cloud y Ġ/ ĠShow ers ")) ĊĠĠĠ Ġ} Ċ } Ċ