package Ġcom . ou day . pokemon . details Ċ Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . times Ċ 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 Ġcom . ou day . pokemon . core . Worker Ċ import Ġcom . ou day . pokemon . details . data . model . response . Pokemon Details Response Ċ import Ġcom . ou day . pokemon . details . ui . Pokemon Details ViewModel Ċ import Ġcom . ou day . pokemon . details . use case . Pokemon Details UseCase Ċ import Ġcom . ou day . pokemon . utils . Base UnitTest Ċ import Ġcom . ou day . pokemon . utils . capture Values Ċ import Ġcom . ou day . pokemon . utils . getValue For Test Ċ import Ġkotlinx . coroutines . flow . flow Ċ import Ġkotlinx . coroutines . test . run Blocking Test Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Test Ċ Ċ private Ġconst Ġval ĠPO KE MON _ ID Ġ= Ġ 5 Ċ Ċ class ĠPokemon Details ViewModel Should Ġ: ĠBase UnitTest () Ġ{ ĊĊĠĠĠ Ġprivate Ġvar Ġuse Case : ĠPokemon Details UseCase Ġ= Ġmock () ĊĠĠĠ Ġprivate Ġval Ġpokemon Ġ= Ġmock < Pokemon Details Response >() ĊĠĠĠ Ġprivate Ġval Ġexpected Ġ= ĠResult . success ( pokemon ) ĊĠĠĠ Ġprivate Ġval Ġbackend ErrorException Ġ= ĠRuntimeException (" Backend Ġerror ") ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġfetch All P ok em ons From ViewModel () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġmock Successful ViewModel (). fetch Pokemon Details ( PO KE MON _ ID ) ĊĠĠĠĠĠĠĠ Ġverify ( use Case , Ġtimes ( 1 )). fetch Pokemon Details ( PO KE MON _ ID ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġemit Error When Receive Error () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠviewModel Ġ= Ġmock Error Case () ĊĠĠĠĠĠĠĠ ĠviewModel . fetch Pokemon Details ( PO KE MON _ ID ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbackend ErrorException , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . pokemon Details Worker . getValue For Test ()?. throwable ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġemits P ok em ons From ViewModel () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠviewModel Ġ= Ġmock Successful ViewModel () ĊĠĠĠĠĠĠĠ ĠviewModel . fetch Pokemon Details ( PO KE MON _ ID ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġexpected . get OrNull (), ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . pokemon Details Worker . getValue For Test ()?. data ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġemit Loading State Before Emit ting Data () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠviewModel Ġ= Ġmock Successful ViewModel () ĊĠĠĠĠĠĠĠ ĠviewModel . pokemon Details Worker . capture Values Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . fetch Pokemon Details ( PO KE MON _ ID ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Worker . loading < Pokemon Details Response ?> (), Ġvalues [ 0 ]) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġemit Loading State Before Emit ting Error () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠviewModel Ġ= Ġmock Error Case () ĊĠĠĠĠĠĠĠ ĠviewModel . pokemon Details Worker . capture Values Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . fetch Pokemon Details ( PO KE MON _ ID ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssert . assertEquals ( Worker . loading < Pokemon Details Response ?> (), Ġvalues [ 0 ]) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġsuspend Ġfun Ġmock Error Case (): ĠPokemon Details ViewModel Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( use Case . fetch Pokemon Details ( PO KE MON _ ID )). thenReturn ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġflow Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġemit ( Result . failure < Pokemon Details Response >( backend ErrorException )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġreturn ĠPokemon Details ViewModel ( use Case ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġsuspend Ġfun Ġmock Successful ViewModel (): ĠPokemon Details ViewModel Ġ{ ĊĠĠĠĠĠĠĠ Ġwhenever ( use Case . fetch Pokemon Details ( PO KE MON _ ID )). thenReturn ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġflow Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġemit ( Result . success ( pokemon )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠĠĠĠĠ Ġreturn ĠPokemon Details ViewModel ( use Case ) ĊĠĠĠ Ġ} Ċ Ċ }