/* Ċ Ġ* ĠDesign ed Ġand Ġdeveloped Ġby Ġ 2 0 2 0 Ġsky do ves Ġ( Ja ew o ong ĠE um ) Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ @ file : Suppress (" Spell Checking Inspection ") Ċ Ċ package Ġcom . sky do ves . mar vel hero es . repository Ċ Ċ import Ġandroidx . arch . core . executor . testing . Instant Task Executor Rule Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . at Least Once Ċ import Ġcom . n ha ar man . mock it ok otlin 2 . mock Ċ 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 . sky do ves . mar vel hero es . Main Cor outines Rule Ċ import Ġcom . sky do ves . mar vel hero es . model . Post er Ċ import Ġcom . sky do ves . mar vel hero es . network . Api Util . get Call Ċ import Ġcom . sky do ves . mar vel hero es . network . Mar vel Client Ċ import Ġcom . sky do ves . mar vel hero es . network . Mar vel Service Ċ import Ġcom . sky do ves . mar vel hero es . persistence . Post er Dao Ċ import Ġcom . sky do ves . mar vel hero es . utils . Mock TestUtil . mock Post er List Ċ import Ġcom . sky do ves . sand wich . Response DataSource Ċ import Ġcom . sky do ves . sand wich . dis pos ables . Composite Disposable Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ Ċ @ Experimental Cor outines Api Ċ class ĠMain Repository Test Ġ{ ĊĊĠ Ġprivate Ġlateinit Ġvar Ġrepository : ĠMain Repository ĊĠ Ġprivate Ġlateinit Ġvar Ġclient : ĠMar vel Client ĊĠ Ġprivate Ġval Ġservice : ĠMar vel Service Ġ= Ġmock () ĊĠ Ġprivate Ġval Ġposter Dao : ĠPost er Dao Ġ= Ġmock () ĊĠ Ġprivate Ġval ĠdataSource : ĠResponse DataSource < List < Post er >> Ġ= ĠResponse DataSource () ĊĊĠ Ġ@ Experimental Cor outines Api ĊĠ Ġ@ get : Rule ĊĠ Ġvar Ġcor outines Rule Ġ= ĠMain Cor outines Rule () ĊĊĠ Ġ@ get : Rule ĊĠ Ġvar Ġinstant Executor Rule Ġ= ĠInstant Task Executor Rule () ĊĊĠ Ġ@ Experimental Cor outines Api ĊĠ Ġ@ Before ĊĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠ Ġclient Ġ= ĠMar vel Client ( service ) ĊĠĠĠ Ġrepository Ġ= ĠMain Repository ( client , ĠdataSource , Ġposter Dao ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġload Mar vel Post ers Test () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠ Ġval Ġmock Data Ġ= Ġmock Post er List () ĊĠĠĠ Ġwhenever ( poster Dao . getPost er List ()). thenReturn ( emptyList ()) ĊĠĠĠ Ġwhenever ( service . fetch Mar vel Post er List ()). thenReturn ( get Call ( mock Data )) ĊĊĠĠĠ Ġval Ġcomposite Disposable Ġ= ĠComposite Disposable () ĊĠĠĠ Ġval Ġload Data Ġ= Ġrepository . load Mar vel Post ers ( composite Disposable ) Ġ{ Ġ} ĊĠĠĠ Ġverify ( poster Dao , Ġat Least Once ()). getPost er List () ĊĠĠĠ Ġverify ( service , Ġat Least Once ()). fetch Mar vel Post er List () ĊĊĠĠĠ Ġval Ġobserver : ĠObserver < List < Post er >> Ġ= Ġmock () ĊĠĠĠ Ġload Data . observe Fore ver ( observer ) ĊĊĠĠĠ Ġval Ġupdated Data Ġ= Ġmock Post er List () ĊĠĠĠ Ġwhenever ( poster Dao . getPost er List ()). thenReturn ( updated Data ) ĊĊĠĠĠ Ġload Data . post Value ( updated Data ) ĊĠĠĠ Ġverify ( observer ). on Changed ( updated Data ) ĊĠĠĠ Ġload Data . remove Observer ( observer ) ĊĠ Ġ} Ċ } Ċ