package Ġcom . must afa . movie guide app . fragment . tv Ċ Ċ import Ġandroid . view . View Ċ import Ġandroid . widget . Horizontal ScrollView Ċ import Ġandroid . widget . ListView Ċ import Ġandroid . widget . ScrollView Ċ import Ġandroidx . core . widget . Nested ScrollView Ċ import Ġandroidx . fragment . app . testing . launch Fragment In Container Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . navigation . Navigation Ċ import Ġandroidx . navigation . testing . Test Nav Host Controller Ċ import Ġandroidx . test . core . app . Application Provider Ċ import Ġandroidx . test . espress o . Esp ress o . on View Ċ import Ġandroidx . test . espress o . View Action Ċ import Ġandroidx . test . espress o . action . View Actions Ċ import Ġandroidx . test . espress o . assertion . View Assertions . matches Ċ import Ġandroidx . test . espress o . matcher . View Matchers .* Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġandroidx . test . internal . runner . junit 4 . statement . Ui Thread Statement . run On Ui Thread Ċ import Ġcom . must afa . movie guide app . R Ċ import Ġcom . must afa . movie guide app . models . Keyword Ċ import Ġcom . must afa . movie guide app . models . Resource Ċ import Ġcom . must afa . movie guide app . models . Review Ċ import Ġcom . must afa . movie guide app . models . Video Ċ import Ġcom . must afa . movie guide app . models . entity . Tv Ċ import Ġcom . must afa . movie guide app . util .* Ċ import Ġcom . must afa . movie guide app . utils . Mock TestUtil Ċ import Ġcom . must afa . movie guide app . view . ui . tv . tv detail . Tv Detail Fragment Ċ import Ġcom . must afa . movie guide app . view . ui . tv . tv detail . Tv Detail Fragment Args Ċ import Ġcom . must afa . movie guide app . view . ui . tv . tv detail . Tv Detail ViewModel Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . wh enever Ċ import Ġcom . sch ib st ed . sp ain . bar ista . interaction . Bar ista Scroll Interactions . scrollTo Ċ import Ġorg . hamcrest . Matcher Ċ import Ġorg . hamcrest . Matchers Ċ import Ġorg . hamcrest . Matchers . any Of Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . mockito . Mockito . mock Ċ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠT v Detail Fragment Test Ġ{ ĊĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġval Ġexecutor Rule Ġ= ĠTask Executor With Id ling Resource Rule () ĊĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġval Ġcounting App Executors Ġ= ĠCount ing App Executors Rule () ĊĊĠĠĠ Ġ@ Rule ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġval Ġdata Binding Id ling Resource Rule Ġ= ĠData Binding Id ling Resource Rule () ĊĊĠĠĠ Ġprivate Ġval Ġnav Controller Ġ= ĠTest Nav Host Controller ( Application Provider . getApplicationContext ()) ĊĠĠĠ Ġprivate Ġval Ġkeywords LiveData Ġ= ĠMutable LiveData < Resource < List < Keyword >> >() ĊĠĠĠ Ġprivate Ġval Ġvideos LiveData Ġ= ĠMutable LiveData < Resource < List < Video >> >() ĊĠĠĠ Ġprivate Ġval Ġreviews LiveData Ġ= ĠMutable LiveData < Resource < List < Review >> >() ĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠT v Detail ViewModel ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġinit () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Ġ= Ġmock ( Tv Detail ViewModel :: class . java ) ĊĊĠĠĠĠĠĠĠ Ġwhenever ( viewModel . keyword List LiveData ). thenReturn ( keywords LiveData ) ĊĠĠĠĠĠĠĠ Ġwhenever ( viewModel . review List LiveData ). thenReturn ( reviews LiveData ) ĊĠĠĠĠĠĠĠ Ġwhenever ( viewModel . video List LiveData ). thenReturn ( videos LiveData ) ĊĊĠĠĠĠĠĠĠ Ġ// There Ġare ĠTwo Ġways Ġto Ġcreate Ġa Ġbundle ĊĠĠĠĠĠĠĠ Ġ/* IMPORTANT ĠNOTE */ ĊĠĠĠĠĠĠĠ Ġ/* The Ġkey Ġmust Ġbe Ġthe Ġsame Ġas Ġandroid : name Ġin Ġthe Ġargument ĠTag Ġin Ġyour Ġnav Graph .*/ ĊĠĠĠĠĠĠĠ Ġ// 1 - Ġval Ġbundle Ġ= Ġbundle Of (" tv " Ġto ĠT v ( 1 )) ĊĊĠĠĠĠĠĠĠ Ġ// Ġ 2 - ĊĠĠĠĠĠĠĠ Ġval Ġbundle Ġ= ĠT v Detail Fragment Args ( Tv ( 1 )). to Bundle () ĊĊĠĠĠĠĠĠĠ Ġval Ġscenario Ġ= Ġlaunch Fragment In Container ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbundle , Ġtheme Res Id Ġ= ĠR . style . App Theme ĊĠĠĠĠĠĠĠ Ġ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠT v Detail Fragment (). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel Factory Ġ= ĠViewModel Util . create For ( viewModel ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġdata Binding Id ling Resource Rule . monitor Fragment ( scenario ) ĊĠĠĠĠĠĠĠ Ġ// ĠSet Ġthe Ġnavigation Ġgraph Ġto Ġthe ĠNav Host Controller ĊĠĠĠĠĠĠĠ Ġrun On Ui Thread Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnav Controller . set Graph ( R . navigation . tv ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġscenario . on Fragment Ġ{ Ġfragment Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ ĠNavigation . setView Nav Controller ( fragment . require View (), Ġnav Controller ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfragment . disable ProgressBar Animations () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Tv Detail () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠGiven ĊĠĠĠĠĠĠĠ Ġval Ġkeywords Ġ= ĠMock TestUtil . mock Keyword List () ĊĠĠĠĠĠĠĠ Ġval Ġreviews Ġ= ĠMock TestUtil . mock Review List () ĊĠĠĠĠĠĠĠ Ġval Ġvideos Ġ= ĠMock TestUtil . mock Video List () ĊĊĠĠĠĠĠĠĠ Ġ// ĠAction ĊĠĠĠĠĠĠĠ Ġkeywords LiveData . post Value ( Resource . success ( keywords , Ġfalse )) ĊĠĠĠĠĠĠĠ Ġreviews LiveData . post Value ( Resource . success ( reviews , Ġfalse )) ĊĠĠĠĠĠĠĠ Ġvideos LiveData . post Value ( Resource . success ( videos , Ġfalse )) ĊĊĠĠĠĠĠĠĠ Ġ// ĠAssert Ġ... ĠCheck ĊĊĠĠĠĠĠĠĠ Ġ// Trail ers .. ĠV ideos ĊĠĠĠĠĠĠĠ Ġon View ( list Matcher Videos (). at Position ( 0 )). check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( list Matcher Videos (). at Position ( 0 )). check ( matches ( has Desc endant ( with Text (" video 0 ")) )) ĊĊĊĠĠĠĠĠĠĠ Ġ// Reviews ĊĠĠĠĠĠĠĠ Ġ// ĠWe Ġneed Ġto Ġscroll Ġon Ġthe ĠN ast ed ScrollView Ġto Ġsee Ġthe Ġthe Ġfake ĠRe views . ĊĠĠĠĠĠĠĠ Ġscroll To (" Must afa ") Ġ// Ġ/* ĠMust afa Ġis Ġauthor Ġof Ġa Ġfake Ġreview Ġsee ĠMock TestUtil . mock Review List () */ ĊĊĠĠĠĠĠĠĠ Ġon View ( list Matcher Reviews (). at Position ( 0 )). check ( matches ( is Displayed ())) ĊĠĠĠĠĠĠĠ Ġon View ( list Matcher Reviews (). at Position ( 0 )). check ( matches ( has Desc endant ( with Text (" Must afa ")) )) ĊĊĠĠĠĠĠĠĠ Ġ// Keywords ĊĠĠĠĠĠĠĠ Ġon View ( with Id ( R . id . detail _ body _ tags )). check ( matches ( is Displayed ())) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġlist Matcher Videos (): ĠRecyclerView Matcher Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠRecyclerView Matcher ( R . id . detail _ body _ re cyclerView _ trail ers ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġlist Matcher Reviews (): ĠRecyclerView Matcher Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠRecyclerView Matcher ( R . id . detail _ body _ re cyclerView _ reviews ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* Ġ Ġhttps :// medium . com /@ dev asi erra / espress o - nested scroll view - scroll ing - via - kotlin - deleg ation - 5 e 7 f 0 aa 6 4 c 0 9 ĊĠĠĠĠ Ġ* Ġ ĠDid n 't Ġwork Ġfor Ġme ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ Suppress (" unused ") ĊĠĠĠ Ġclass ĠNested ScrollView Extension ( scroll to Action : ĠView Action Ġ= ĠView Actions . scrollTo ()) Ġ: ĊĠĠĠĠĠĠĠ ĠView Action Ġby Ġscroll to Action Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġget Constraints (): ĠMatcher < View > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠMatch ers . all Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwith Effective Visibility ( Visibility . VISIBLE ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġis Desc endant Of A ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġany Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġis AssignableFrom ( Nested ScrollView :: class . java ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġis AssignableFrom ( ScrollView :: class . java ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġis AssignableFrom ( Horizontal ScrollView :: class . java ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġis AssignableFrom ( ListView :: class . java ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }