package Ġcom . sun rise . app . repo Ċ Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġcom . sun rise . app . Base Test Ċ import Ġcom . sun rise . app . core . Constants Ċ import Ġcom . sun rise . app . db . entity . Forecast Entity Ċ import Ġcom . sun rise . app . domain . datasource . forecast . Forecast Local DataSource Ċ import Ġcom . sun rise . app . domain . datasource . forecast . Forecast Remote DataSource Ċ import Ġcom . sun rise . app . utils . create Sample Forecast Entity Ċ import Ġcom . sun rise . app . utils . create Sample Forecast Response Ċ import Ġcom . sun rise . app . utils . domain . Resource Ċ import Ġcom . sun rise . app . utils . domain . Status Ċ import Ġio . mock k . called Ċ import Ġio . mock k . every Ċ import Ġio . mock k . impl . annotations . Mock K Ċ import Ġio . mock k . mock k Ċ import Ġio . mock k . verify Ċ import Ġio . reactivex . Single Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ Ċ class ĠFore cast Repository Test Ġ: ĠBaseTest () Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġrepository : ĠFore cast Repository ĊĊĠĠĠ Ġ@ Mock K ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmock Forecast Remote DataSource : ĠFore cast Remote DataSource ĊĊĠĠĠ Ġ@ Mock K ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġmock Forecast Local DataSource : ĠFore cast Local DataSource ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġoverride Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . setUp () ĊĊĠĠĠĠĠĠĠ Ġrepository Ġ= ĠFore cast Repository ( mock Forecast Remote DataSource , Ġmock Forecast Local DataSource ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` load Forecast By Coord Ġshould Ġget Ġcurrent Ġweather Ġfrom Ġthe Ġlocal Ġdata Ġsource Ġif Ġfetch Required Ġis Ġfalse `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġforecast LiveData : ĠMutable LiveData < Forecast Entity > Ġ= ĠMutable LiveData () ĊĠĠĠĠĠĠĠ Ġforecast LiveData . post Value ( create Sample Forecast Entity ( 1 , Ġ" J oh ann es burg ")) ĊĠĠĠĠĠĠĠ Ġval Ġmocked Observer : ĠObserver < Resource < Forecast Entity >> Ġ= Ġmock k ( relax Unit Fun Ġ= Ġtrue ) ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġmock Forecast Local DataSource . get Forecast () Ġ} Ġreturns Ġforecast LiveData ĊĊĠĠĠĠĠĠĠ Ġrepository . load Forecast By Coord ( lat , Ġlon , Ġfalse , ĠConstants . Coords . METRIC ). observe Fore ver ( mocked Observer ) ĊĊĠĠĠĠĠĠĠ Ġverify Ġ{ Ġmock Forecast Remote DataSource . get Forecast By Geo C ords ( lat , Ġlon , ĠConstants . Coords . METRIC ) Ġwas Not Ġcalled Ġ} ĊĠĠĠĠĠĠĠ Ġverify Ġ{ Ġmock Forecast Local DataSource . get Forecast () Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` load Forecast By Coord Ġshould Ġreturn Ġvalid Ġdata Ġfrom Ġthe Ġlocal Ġdata Ġsource Ġif Ġfetch Required Ġis Ġfalse `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġforecast LiveData : ĠMutable LiveData < Forecast Entity > Ġ= ĠMutable LiveData () ĊĠĠĠĠĠĠĠ Ġforecast LiveData . post Value ( create Sample Forecast Entity ( 1 , Ġ" J oh ann es burg ")) ĊĠĠĠĠĠĠĠ Ġval Ġmocked Observer : ĠObserver < Resource < Forecast Entity >> Ġ= Ġmock k ( relax Unit Fun Ġ= Ġtrue ) ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġmock Forecast Local DataSource . get Forecast () Ġ} Ġreturns Ġforecast LiveData ĊĊĠĠĠĠĠĠĠ Ġrepository . load Forecast By Coord ( lat , Ġlon , Ġfalse , ĠConstants . Coords . METRIC ). observe Fore ver ( mocked Observer ) ĊĊĠĠĠĠĠĠĠ Ġval Ġforecast Entities Ġ= Ġmutable ListOf < Resource < Forecast Entity >>() ĊĠĠĠĠĠĠĠ Ġverify Ġ{ Ġmocked Observer . on Changed ( capture ( forecast Entities )) Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġforecast Entity Ġ= Ġforecast Entities . first () ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( Status . SUCCESS , Ġforecast Entity . status ) ĊĊĠĠĠĠĠĠĠ ĠassertEquals (" J oh ann es burg ", Ġforecast Entity . data ?. city ?. city Name ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġforecast Entity . data ?. id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` load Current Weather By Geo C ords Ġshould Ġget Ġcurrent Ġweather Ġfrom Ġthe Ġremote Ġdata Ġsource Ġif Ġfetch Required Ġis Ġtrue `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġforecast LiveData : ĠMutable LiveData < Forecast Entity > Ġ= ĠMutable LiveData () ĊĠĠĠĠĠĠĠ Ġforecast LiveData . post Value ( create Sample Forecast Entity ( 1 , Ġ" J oh ann es burg ")) ĊĠĠĠĠĠĠĠ Ġval Ġmocked Observer : ĠObserver < Resource < Forecast Entity >> Ġ= Ġmock k ( relax Unit Fun Ġ= Ġtrue ) ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġmock Forecast Local DataSource . get Forecast () Ġ} Ġreturns Ġforecast LiveData ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġmock Forecast Remote DataSource . get Forecast By Geo C ords ( lat , Ġlon , ĠConstants . Coords . METRIC ) Ġ} Ġreturns ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSingle . just ( create Sample Forecast Response ()) ĊĊĠĠĠĠĠĠĠ Ġrepository . load Forecast By Coord ( lat , Ġlon , Ġtrue , ĠConstants . Coords . METRIC ). observe Fore ver ( mocked Observer ) ĊĊĠĠĠĠĠĠĠ Ġverify Ġ{ Ġmock Forecast Remote DataSource . get Forecast By Geo C ords ( lat , Ġlon , ĠConstants . Coords . METRIC ) Ġ} ĊĠĠĠĠĠĠĠ Ġverify Ġ{ Ġmock Forecast Local DataSource . get Forecast () Ġwas Not Ġcalled Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` load Forecast By Coord Ġshould Ġreturn Ġvalid Ġdata Ġfrom Ġthe Ġremote Ġdata Ġsource Ġif Ġfetch Required Ġis Ġtrue `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġforecast LiveData : ĠMutable LiveData < Forecast Entity > Ġ= ĠMutable LiveData () ĊĠĠĠĠĠĠĠ Ġforecast LiveData . post Value ( create Sample Forecast Entity ( 1 , Ġ" J oh ann es burg ")) ĊĠĠĠĠĠĠĠ Ġval Ġmocked Observer : ĠObserver < Resource < Forecast Entity >> Ġ= Ġmock k ( relax Unit Fun Ġ= Ġtrue ) ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġmock Forecast Local DataSource . get Forecast () Ġ} Ġreturns Ġforecast LiveData ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġmock Forecast Remote DataSource . get Forecast By Geo C ords ( lat , Ġlon , ĠConstants . Coords . METRIC ) Ġ} Ġreturns ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSingle . just ( create Sample Forecast Response ()) ĊĊĠĠĠĠĠĠĠ Ġrepository . load Forecast By Coord ( lat , Ġlon , Ġtrue , ĠConstants . Coords . METRIC ). observe Fore ver ( mocked Observer ) ĊĊĠĠĠĠĠĠĠ Ġval Ġforecast Entities Ġ= Ġmutable ListOf < Resource < Forecast Entity >>() ĊĠĠĠĠĠĠĠ Ġverify Ġ{ Ġmocked Observer . on Changed ( capture ( forecast Entities )) Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġforecast Entity Ġ= Ġforecast Entities . first () ĊĊĠĠĠĠĠĠĠ ĠassertEquals (" J oh ann es burg ", Ġforecast Entity . data ?. city ?. city Name ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġforecast Entity . data ?. id ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval Ġlat Ġ= Ġ 3 0 . 0 ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval Ġlon Ġ= Ġ 3 4 . 0 ĊĠĠĠ Ġ} Ċ Ċ } Ċ