package Ġcom . we alth front . mage ll an . sample . advanced . api Ċ Ċ import Ġcom . we alth front . mage ll an . sample . advanced . R Ċ import Ġcom . we alth front . mage ll an . sample . advanced . c ere al collection . C ere al Details Ċ import Ġcom . we alth front . mage ll an . sample . advanced . c ere al collection . C ere al Status Ċ import Ġcom . we alth front . mage ll an . sample . advanced . c ere al collection . C ere al Status . ACTIVE Ċ import Ġio . reactivex . Observable Ċ import Ġio . reactivex . schedul ers . Schedulers Ċ import Ġokhttp 3 . Ok HttpClient Ċ import Ġretrofit 2 . Ret rofit Ċ import Ġretrofit 2 . adapter . rx java 2 . Rx Java 2 Call Adapter Factory Ċ import Ġretrofit 2 . mock . Behavior Delegate Ċ import Ġretrofit 2 . mock . Mock Ret rofit Ċ import Ġretrofit 2 . mock . Network Behavior Ċ import Ġjava . util . concurrent . TimeUnit Ċ Ċ class ĠApi Client Ġconstructor ( private Ġval Ġretrofit : ĠBehavior Delegate < Api Contract >) Ġ: ĠApi Contract Ġ{ ĊĊĠ Ġval ĠALL _ C ERE ALS Ġ= ĠlistOf ( ĊĠĠĠ ĠC ere al Details ( ĊĠĠĠĠĠ ĠR . string . monster _ c ere als _ title , ĠR . string . monster _ c ere als _ description , ĊĠĠĠĠĠ ĠC ere al Status . LIMIT ED ĊĠĠĠ Ġ), ĊĠĠĠ ĠC ere al Details ( ĊĠĠĠĠĠ ĠR . string . d unk _ a _ b alls _ title , ĊĠĠĠĠĠ ĠR . string . d unk _ a _ b alls _ description , ĊĠĠĠĠĠ ĠC ere al Status . DIS CONT IN U ED ĊĠĠĠ Ġ), ĊĠĠĠ ĠC ere al Details ( ĊĠĠĠĠĠ ĠR . string . corn fl akes _ title , ĊĠĠĠĠĠ ĠR . string . corn fl akes _ description , ĊĠĠĠĠĠ ĠACT IVE ĊĠĠĠ Ġ), ĊĠĠĠ ĠC ere al Details ( ĊĠĠĠĠĠ ĠR . string . oreo _ os _ title , ĊĠĠĠĠĠ ĠR . string . oreo _ os _ description , ĊĠĠĠĠĠ ĠACT IVE ĊĠĠĠ Ġ) ĊĠ Ġ) ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĊĠĠĠ Ġ@ Jvm Static ĊĠĠĠ Ġfun Ġbuild Client (): ĠApi Client Ġ{ ĊĠĠĠĠĠ Ġval Ġretrofit Ġ= Ġget Ret rofit () ĊĠĠĠĠĠ Ġval Ġdelegate Ġ= Ġget Mock Ret rofit ( ret rofit ). create ( Api Contract :: class . java ) ĊĠĠĠĠĠ Ġreturn ĠApi Client ( delegate ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Ret rofit (): ĠRet rofit Ġ{ ĊĠĠĠĠĠ Ġval Ġok HttpClient Ġ= ĠOk HttpClient (). newBuilder (). build () ĊĠĠĠĠĠ Ġreturn ĠRet rofit . Builder () ĊĠĠĠĠĠĠĠ Ġ. baseUrl (" http :// example . com ") ĊĠĠĠĠĠĠĠ Ġ. add Call Adapter Factory ( Rx Java 2 Call Adapter Factory . create With Scheduler ( Schedulers . io ())) ĊĠĠĠĠĠĠĠ Ġ. client ( ok HttpClient ) ĊĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Mock Ret rofit ( ret rofit : ĠRet rofit ): ĠMock Ret rofit Ġ{ ĊĠĠĠĠĠ Ġval Ġnetwork Behavior Ġ= ĠNetwork Behavior . create () ĊĠĠĠĠĠ Ġnetwork Behavior . set Delay ( 2 5 0 0 , ĠTimeUnit . MILLISECONDS ) ĊĠĠĠĠĠ Ġnetwork Behavior . set Variance Percent ( 2 0 ) ĊĠĠĠĠĠ Ġnetwork Behavior . setError Percent ( 0 ) ĊĠĠĠĠĠ Ġnetwork Behavior . set Failure Percent ( 0 ) ĊĠĠĠĠĠ Ġreturn ĠMock Ret rofit . Builder ( ret rofit ) ĊĠĠĠĠĠĠĠ Ġ. network Behavior ( network Behavior ) ĊĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġget Collection (): ĠObservable < List < C ere al Details >> Ġ{ ĊĠĠĠ Ġreturn Ġretrofit . return ing Response ( ALL _ C ERE ALS ). get Collection () ĊĠ Ġ} Ċ } Ċ