package Ġcom . architect coders . open weather . detail Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġcom . architect coders . open weather . test shared . mocked Weather Ċ import Ġcom . architect coders . open weather . ui . detail . Detail ViewModel Ċ import Ġcom . architect coders . use sc ases . Find By City Ċ import Ġcom . architect coders . use sc ases . Find By Timestamp Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . verify Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġkotlinx . coroutines . Dispatch ers Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . junit . Mockito JUnit Runner Ċ Ċ @ RunWith ( Mockito JUnit Runner :: class ) Ċ class ĠDetail ViewModel Test Ġ{ ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġrule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġlateinit Ġvar ĠfindBy City : ĠFind By City ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġlateinit Ġvar ĠfindBy Timestamp : ĠFind By Timestamp ĊĊĠĠĠ Ġ@ Mock ĊĠĠĠ Ġlateinit Ġvar Ġobserver : ĠObserver < Detail ViewModel . Ui Model > ĊĊĠĠĠ Ġlateinit Ġvar Ġdetail ViewModel : ĠDetail ViewModel ĊĊĠĠĠ Ġprivate Ġval Ġtimestamp Ġ= Ġ" 1 2 3 4 5 6 " ĊĠĠĠ Ġprivate Ġval Ġcity Ġ= Ġ" Mad rid " ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġdetail ViewModel Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠDetail ViewModel ( timestamp , ĠfindBy City , ĠfindBy Timestamp , ĠDispatch ers . Un conf ined ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` ob serving ĠLive Data Ġfinds Ġthe Ġweather Ġby Ġtimestamp `() Ġ{ ĊĠĠĠĠĠĠĠ Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhenever ( findBy Timestamp . invoke ( timestamp )). thenReturn ( mocked Weather ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġdetail ViewModel . model . observe Fore ver ( observer ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( observer ). on Changed ( Detail ViewModel . Ui Model . Content ( mocked Weather )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` ob serving ĠLive Data Ġfinds Ġthe Ġweather Ġby Ġcity `() Ġ{ ĊĠĠĠĠĠĠĠ Ġrun Blocking Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġweather List Ġ= ĠlistOf ( mocked Weather . copy ( id Ġ= Ġ 1 )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhenever ( findBy Timestamp . invoke ( timestamp )). thenReturn ( mocked Weather ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhenever ( findBy City . invoke ( city )). thenReturn ( weather List ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdetail ViewModel . model . observe Fore ver ( observer ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġdetail ViewModel . find Weather By City ( city ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( observer ). on Changed ( Detail ViewModel . Ui Model . Show Weather By City ( weather List )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }