package Ġco . nim ble hq . rx java . ui . screens . second Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġco . nim ble hq . rx java . databinding . Fragment Second Binding Ċ import Ġco . nim ble hq . rx java . di . modules . Rx Permissions Module Ċ import Ġco . nim ble hq . rx java . domain . data . Data Ċ import Ġco . nim ble hq . rx java . test . Test Navigator Module . mock Main Navigator Ċ import Ġco . nim ble hq . rx java . test . get Private Property Ċ import Ġco . nim ble hq . rx java . test . replace Ċ import Ġco . nim ble hq . rx java . ui . screens . Base Fragment Test Ċ import Ġcom . t br uy elle . rx permissions 2 . Rx Permissions Ċ import Ġdagger . h ilt . android . testing .* Ċ import Ġio . mock k . every Ċ import Ġio . mock k . mock k Ċ import Ġio . reactivex . Observable Ċ import Ġorg . am sh ove . k lu ent . shouldBe EqualTo Ċ import Ġorg . am sh ove . k lu ent . should Not BeNull Ċ import Ġorg . junit .* Ċ Ċ @ H ilt Android Test Ċ @ Un install Modules ( Rx Permissions Module :: class ) Ċ class ĠSecond Fragment UnitTest Ġ: ĠBase Fragment Test < Second Fragment , ĠFragment Second Binding >() Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġmock ViewModel Ġ= Ġmock k < Second ViewModel >( relax ed Ġ= Ġtrue ) ĊĠĠĠ Ġprivate Ġval Ġbundle Ġ= ĠSecond Bundle ( ĊĠĠĠĠĠĠĠ Ġdata Ġ= ĠData ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtitle Ġ= Ġ" title ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġauthor Ġ= Ġ" author ", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthumbnail Ġ= Ġ"", ĊĠĠĠĠĠĠĠĠĠĠĠ Ġurl Ġ= Ġ"" ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġ@ get : Rule ( order Ġ= Ġ 0 ) ĊĠĠĠ Ġvar Ġh ilt Rule Ġ= ĠH ilt Android Rule ( this ) ĊĊĠĠĠ Ġ@ Bind Value ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġval Ġmock Rx Permissions Ġ= Ġmock k < Rx Permissions >() ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġh ilt Rule . inject () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` When Ġinitializing ĠSecond Fragment , Ġits Ġview Ġdisplays Ġthe Ġcorresponding Ġdata Ġfrom Ġbundle `() Ġ{ ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġmock ViewModel . data Ġ} Ġreturns ĠObservable . just ( bundle . data ) ĊĠĠĠĠĠĠĠ Ġlaunch Fragment () ĊĠĠĠĠĠĠĠ Ġfragment . binding . bt Open Post . text . toString () ĠshouldBe EqualTo Ġ" Open ĠPost " ĊĠĠĠĠĠĠĠ Ġfragment . binding . tv Second Title . text . toString () ĠshouldBe EqualTo Ġbundle . data . title ĊĠĠĠĠĠĠĠ Ġfragment . binding . tv Second Author . text . toString () ĠshouldBe EqualTo Ġbundle . data . author ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġlaunch Fragment () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġargs Ġ= ĠBundle (). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġput Parcelable ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" bundle ", Ġbundle ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġlaunch Fragment In H ilt Container < Second Fragment >( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġon Inst antiate Ġ= Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreplace ( get Private Property (" viewModel "), Ġmock ViewModel ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnavigator Ġ= Ġmock Main Navigator ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġrx Permissions Ġ= Ġmock Rx Permissions ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ}, ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfragment Args Ġ= Ġargs ĊĠĠĠĠĠĠĠ Ġ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfragment Ġ= Ġthis ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfragment . navigator . should Not BeNull () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfragment . rx Permissions . should Not BeNull () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ