package Ġcom . f red por ci unc ula . dag gers imple way . posts Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġcom . f red por ci unc ula . dag gers imple way . model . new Post Ċ import Ġcom . f red por ci unc ula . dag gers imple way . service . Posts Service Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġio . reactivex . Single Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . BDD Mockito . given Ċ import Ġorg . mockito . Inject Mocks Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . junit . Mockito JUnit Runner Ċ Ċ @ RunWith ( Mockito JUnit Runner :: class ) Ċ class ĠBest Post ViewModel Test Ġ{ ĊĊĠĠĠ Ġ@ get : Rule Ġval Ġinstant Task Executor Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġposts Service : ĠPosts Service ĊĊĠĠĠ Ġ@ Mock Ġprivate Ġlateinit Ġvar Ġbest Post Finder : ĠBest Post Finder ĊĊĠĠĠ Ġ@ Inject Mocks Ġprivate Ġlateinit Ġvar ĠviewModel : ĠBest Post ViewModel ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` should Ġemit Ġwhatever Ġpost Ġis Ġreturned Ġby Ġthe Ġbest Ġpost Ġfinder `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġposts Ġ= ĠlistOf ( new Post ( id Ġ= Ġ 1 0 ), Ġnew Post ( id Ġ= Ġ 2 0 )) ĊĠĠĠĠĠĠĠ Ġgiven ( posts Service . posts ()). willReturn ( Single . just ( posts )) ĊĠĠĠĠĠĠĠ Ġgiven ( best Post Finder . find Best Post ( posts )). willReturn ( posts . first ()) ĊĊĠĠĠĠĠĠĠ Ġwith ( viewModel ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġload Posts () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbest Post (). observe Fore ver Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( it ). isEqualTo ( posts . first ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ