package Ġcom . cor rot . kw iat onomous app . presentation . devices Ċ Ċ import Ġcom . cor rot . kw iat onomous app . Main Coroutine Rule Ċ import Ġcom . cor rot . kw iat onomous app . domain . model . User Device Ċ import Ġcom . cor rot . kw iat onomous app . domain . repository . User Device Repository Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġio . mock k . Mock K Annotations Ċ import Ġio . mock k . every Ċ import Ġio . mock k . mock k Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . flow . flow Of Ċ import Ġkotlinx . coroutines . test . run Blocking Test Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test ĊĊ Ċ class ĠDevices ViewModel Test Ġ{ ĊĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġcoroutine Rule Ġ= ĠMain Coroutine Rule () ĊĊĠĠĠ Ġprivate Ġvar Ġuser Device Repository : ĠUser Device Repository Ġ= Ġmock k () ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠĠĠĠĠ ĠMock K Annotations . init ( this ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest _ some _ devices _ found () Ġ= Ġcoroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠG IV EN ĊĠĠĠĠĠĠĠ Ġval Ġuser Devices List Ġ= ĠlistOf < User Device >( mock k (), Ġmock k (), Ġmock k ()) ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġuser Device Repository . getUser Devices () Ġ}. returns ( flow Of ( user Devices List )) ĊĠĠĠĠĠĠĠ Ġval Ġdevices ViewModel Ġ= ĠDevices ViewModel ( user Device Repository , Ġcoroutine Rule . dispatcher ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠTHEN ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= Ġdevices ViewModel . state . value ĊĠĠĠĠĠĠĠ ĠassertThat ( state . isLoading ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( state . error ). isNull () ĊĠĠĠĠĠĠĠ ĠassertThat ( state . user Devices ). has Size ( 3 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Experimental Cor outines Api ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest _ no _ devices _ found () Ġ= Ġcoroutine Rule . run Blocking Test Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠG IV EN ĊĠĠĠĠĠĠĠ Ġevery Ġ{ Ġuser Device Repository . getUser Devices () Ġ}. returns ( flow Of ( emptyList ())) ĊĠĠĠĠĠĠĠ Ġval Ġdevices ViewModel Ġ= ĠDevices ViewModel ( user Device Repository , Ġcoroutine Rule . dispatcher ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠTHEN ĊĠĠĠĠĠĠĠ Ġval Ġstate Ġ= Ġdevices ViewModel . state . value ĊĠĠĠĠĠĠĠ ĠassertThat ( state . isLoading ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( state . error ). isNull () ĊĠĠĠĠĠĠĠ ĠassertThat ( state . user Devices ). isEmpty () ĊĠĠĠ Ġ} Ċ }