package Ġno . bir g . album selector . view model Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . never Ċ 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 . Experimental Cor outines Api Ċ import Ġno . bir g . album selector . TestContext Provider Ċ import Ġno . bir g . album selector . Test Coroutine Rule Ċ import Ġno . bir g . album selector . database .* Ċ import Ġno . bir g . album selector . get Or Await Value Ċ import Ġno . bir g . album selector . screens . Library Album s Ċ import Ġno . bir g . album selector . screens . album . Album ViewModel Ċ import Ġno . bir g . album selector . spotify . Streaming Client Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġkotlin . test . assertEquals Ċ Ċ class ĠAlbum ViewModel Test Ġ{ ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġinstant Executor Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġval Ġtest Coroutine Rule Ġ= ĠTest Coroutine Rule () ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠA ID : ĠString Ġ= Ġ" test _ aid " ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠTITLE Ġ= Ġ" test _ title " ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠAR TI ST Ġ= Ġ" test _ artist " ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠD URATION Ġ= Ġ 6 0 0 0 0 Ġ// ĠOne Ġminute ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠIMAGE _ URL Ġ= Ġ" test . url " ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠAL BU M : ĠAlbum Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAlbum ( A ID , ĠTITLE , ĠAR TI ST , ĠD URATION , ĠIMAGE _ URL ) ĊĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠC ID Ġ= Ġ" test _ category " ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠC ATEG ORY Ġ= ĠCategory ( CID ) ĊĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠC ATEG ORY _ AL BU M _ CROSS _ REF Ġ= ĠCategory Album Cross Ref ( CID , ĠA ID ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġmock Album Dao : ĠAlbum Dao Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġmock Category Dao : ĠCategory Dao Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġmock Streaming Client : ĠStreaming Client Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval ĠviewModel : ĠAlbum ViewModel ĊĊĠĠĠ Ġprivate Ġval Ġlibrary Album s Ġ= ĠMutable LiveData < List < Album With Categories >>() ĊĠĠĠ Ġprivate Ġval Ġcategories Ġ= ĠMutable LiveData < List < Category With Album s >>() ĊĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Album Dao . getBy ID ( A ID )). thenReturn ( Mutable LiveData ( AL BU M )) ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Album Dao . getAll With Categories ()). thenReturn ( library Album s ) ĊĠĠĠĠĠĠĠ Ġwhenever ( mock Category Dao . getAll With Album s ()). thenReturn ( categories ) ĊĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠAlbum ViewModel ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠA ID , Ġmock Album Dao , Ġmock Category Dao , Ġmock Streaming Client , ĠTest Context Provider () ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġfun Ġdelete Album _ When Called _ Album Dao Delete Called () Ġ{ ĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . delete Album () ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( mock Album Dao ). delete ( AL BU M ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġselect Random Album _ When Called _ Next Album Selected () Ġ{ ĊĠĠĠĠĠĠĠ ĠLibrary Album s . display ed Album s . value Ġ= ĠlistOf ( AL BU M ) ĊĊĠĠĠĠĠĠĠ ĠviewModel . select Random Album () ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( AL BU M , ĠviewModel . next Album . get Or Await Value ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġfun Ġadd Category _ Category DoesNotExist _ Category Dao Insert Called () Ġ{ ĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhenever ( mock Category Dao . check Record ( CID )). thenReturn ( false ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . add Category ( CID ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( mock Category Dao ). insert ( CATEGORY ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġfun Ġadd Category _ Category AlreadyExists _ Category Dao Insert Not Called () Ġ{ ĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhenever ( mock Category Dao . check Record ( CID )). thenReturn ( true ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . add Category ( CID ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( mock Category Dao , Ġnever ()). insert ( CATEGORY ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġfun Ġdelete Category _ When Called _ Category Dao Delete Called () Ġ{ ĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . delete Category ( CATEGORY ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( mock Category Dao ). delete ( CATEGORY ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġfun Ġset Category _ When Called _ Category Dao Insert Cross Ref Called () Ġ{ ĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . set Category ( CATEGORY ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( mock Category Dao ). insert Album Cross Ref ( CATEGORY _ AL BU M _ CROSS _ REF ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġfun Ġunset Category _ When Called _ Category Dao Delete Cross Ref Called () Ġ{ ĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . unset Category ( CATEGORY ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( mock Category Dao ). delete Album Cross Ref ( CATEGORY _ AL BU M _ CROSS _ REF ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġfun Ġplay Album _ When Called _ Spot ify Client Play Called () Ġ{ ĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . play Album () ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( mock Streaming Client ). play Album ( A ID ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġfun Ġrefresh Album _ Album In Library _ Album Dao Called With Details () Ġ{ ĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhenever ( mock Album Dao . check Record ( A ID )). thenReturn ( true ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhenever ( mock Streaming Client . fetch Album Details ( A ID , Ġtrue )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. thenReturn ( AL BU M ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . refresh Album ( A ID ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( mock Album Dao ). update ( AL BU M ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġfun Ġrefresh Album _ Album In Library _ Spot ify Client Called () Ġ{ ĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhenever ( mock Album Dao . check Record ( A ID )). thenReturn ( true ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . refresh Album ( A ID ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( mock Streaming Client ). fetch Album Details ( A ID , Ġtrue ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġfun Ġrefresh Album _ Album NotIn Library _ Album Dao Not Called () Ġ{ ĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhenever ( mock Album Dao . check Record ( A ID )). thenReturn ( false ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . refresh Album ( A ID ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( mock Album Dao , Ġnever ()). update ( AL BU M ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġfun Ġrefresh Album _ Album NotIn Library _ Spot ify Client Not Called () Ġ{ ĊĠĠĠĠĠĠĠ Ġtest Coroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhenever ( mock Album Dao . check Record ( A ID )). thenReturn ( false ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . refresh Album ( A ID ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġverify ( mock Streaming Client , Ġnever ()). fetch Album Details ( A ID ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ